/* SPE-Teil des Cell-Programms zur Berechnung von Pi nach dem Schrotflinten-Algorithmus */ /************************** * Peter Vaeterlein, 2008 * **************************/ #include #include #include #include #include "pi_libspe.h" float compute_pi( long int seed, uint64_t rounds ) { uint64_t i; uint64_t in = 0; float x, y; unsigned long int h; srand48( seed ); for ( i = 0; i < rounds; i++ ) { x = (float) lrand48()/RAND_MAX; y = (float) lrand48()/RAND_MAX; if (( x * x + y * y ) < 1.0 ) { in++; } } return ( float ) 4.0 * in / rounds; } int main () { uint32_t ea_block_h, ea_block_l; uint32_t tag_id; spe_par_t spe_par __attribute__ ((aligned(16))); ea_block_h = spu_read_in_mbox(); ea_block_l = spu_read_in_mbox(); tag_id = mfc_tag_reserve(); spu_mfcdma64( &spe_par, ea_block_h, ea_block_l, sizeof( spe_par_t ), tag_id, MFC_GET_CMD ); mfc_write_tag_mask( 1 << tag_id ); mfc_read_tag_status_all(); spe_par.value = compute_pi( spe_par.seed, spe_par.rounds ); spu_mfcdma64( &spe_par, ea_block_h, ea_block_l, sizeof( spe_par_t ), tag_id, MFC_PUT_CMD ); mfc_write_tag_mask( 1 << tag_id ); mfc_read_tag_status_all(); mfc_tag_release( tag_id ); return 0; }