int main(int argc, char **argv) { server_args_t server_args; pthread_t server_thread; seed_random(); burp_track = track_new(BURP_WAV); if (! burp_track) { perror(BURP_WAV); exit(1); } p = piface_new(); pthread_mutex_init(&event_lock, NULL); server_args.port = 5555; server_args.command = remote_event; server_args.state = NULL; pthread_create(&server_thread, NULL, server_thread_main, &server_args); while(true) { wait_for_trigger(); take_action(); wait_for_trigger_release(); if (n_consecutive_spits) { wait_for_recharge(); } } return 0; }
void Processor::z_restart() { flush_buffer(); os_restart_game(RESTART_BEGIN); seed_random(0); if (!first_restart) { story_fp->seek(0); if (story_fp->read(zmp, h_dynamic_size) != h_dynamic_size) error("Story file read error"); } else { first_restart = false; } restart_header(); restart_screen(); _sp = _fp = _stack + STACK_SIZE; _frameCount = 0; if (h_version != V6 && h_version != V9) { long pc = (long)h_start_pc; SET_PC(pc); } else { call(h_start_pc, 0, nullptr, 0); } os_restart_game(RESTART_END); }
main() { /* Reads in chrom, and runs on NUM_ENVIRONMENTS_FOR_PERFORMANCE randomly generated environments for NUM_MOVES moves on each. Returns average performance over these NUM_ENVIRONMENTS_FOR_PERFORMANCE environments */ int i, row, column; int performance_points = 0; float environment_x1, environment_y1, environment_x2, environment_y2; long ran_seed = 0, ran_seed_flag; float performance; /* Seed random number generator */ ran_seed = ran_seed_flag ? ran_seed_flag : 0; ran_seed = seed_random(ran_seed_flag); chrom = (int *) malloc(CHROM_LENGTH * sizeof(int)); read_chrom(); calc_performance(chrom); }
int main() { double v[BODY_VECTOR_SIZE]; body b; double vp[BODY_VECTOR_SIZE]; double vc[CENTRAL_BODY_VECTOR_SIZE]; central_body bc; double vcp[CENTRAL_BODY_VECTOR_SIZE]; int i; gsl_rng *rng = NULL; const double eps = 1e-12; rng=gsl_rng_alloc(gsl_rng_ranlxd2); seed_random(rng); for (i = 0; i < BODY_VECTOR_SIZE; i++) { v[i] = gsl_rng_uniform(rng); } for (i = 0; i < CENTRAL_BODY_VECTOR_SIZE; i++) { vc[i] = gsl_rng_uniform(rng); } vector_to_body(v, &b); body_to_vector(&b, vp); vector_to_central_body(vc, &bc); central_body_to_vector(&bc, vcp); if (!check_vector_close(eps, eps, BODY_VECTOR_SIZE, v, vp)) return 1; if (!check_vector_close(eps, eps, CENTRAL_BODY_VECTOR_SIZE, vc, vcp)) return 2; gsl_rng_free(rng); return 0; }
float random_between(float min_value, float max_value) { static bool seeded = seed_random(); float perc = (rand() % 10000) / 10000.0f; return min_value + perc * (max_value - min_value); }
void z_restart (void) { static bool first_restart = TRUE; flush_buffer (); os_restart_game (RESTART_BEGIN); seed_random (0); if (!first_restart) { fseek (story_fp, blorb_ofs, SEEK_SET); if (fread (zmp, 1, h_dynamic_size, story_fp) != h_dynamic_size) os_fatal ("Story file read error"); } else first_restart = FALSE; restart_header (); restart_screen (); sp = fp = stack + STACK_SIZE; frame_count = 0; if (h_version != V6) { long pc = (long) h_start_pc; SET_PC (pc); } else call (h_start_pc, 0, NULL, 0); os_restart_game (RESTART_END); }/* z_restart */
/* * Initialize runtime environment and initializes MPI. */ int init (struct life_t * life, int * c, char *** v) { int argc = *c; char ** argv = *v; life->rank = 0; life->size = 1; life->ncols = DEFAULT_SIZE; life->nrows = DEFAULT_SIZE; life->tcols = DEFAULT_SIZE; life->ubound = DEFAULT_SIZE - 1; life->lbound = 0; life->generations = DEFAULT_GENS; life->randseed = DEFAULT_SEED; life->print = false; life->infile = NULL; life->outfile = NULL; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &life->rank); MPI_Comm_size(MPI_COMM_WORLD, &life->size); parse_args(life, argc, argv); seed_random(life->randseed); init_grids(life); }
int main(int argc, char **argv) { stop_t *stop; track_t *track; fogger_args_t fogger_args = { .default_duty = 0.01, .delta_duty = 0.001, }; seed_random(); if (wb_init() < 0) { perror("wb_init"); exit(1); } if ((track = track_new("coffin-dog.wav")) == NULL) { perror("coffin-dog.wav"); exit(1); } //track_set_volume(track, 50); stop = stop_new(); fogger_run_in_background(FOGGER_PIN, &fogger_args); wb_set(LIGHT_PIN, 1); wb_set(LID_PIN, 0); while (true) { bool is_lit = true; stop_reset(stop); track_play_asynchronously(track, stop); ms_sleep(ACTION_START); while (! stop_is_stopped(stop)) { int open_time = random_number_in_range(LID_OPEN_LOW, LID_OPEN_HIGH); int closed_time = random_number_in_range(LID_CLOSED_LOW, LID_CLOSED_HIGH); printf("\t\tlid %d %d\n", open_time, closed_time); fflush(stdout); wb_set(LID_PIN, 1); blink_lights_for(&is_lit, open_time); wb_set(LID_PIN, 0); blink_lights_for(&is_lit, closed_time); } wb_set(LIGHT_PIN, 1); wb_set(LID_PIN, 0); ms_sleep(random_number_in_range(INTERDELAY_LOW, INTERDELAY_HIGH)); } return 0; }
/* Fills @n bytes pointer to by @p with random numbers. */ void randomize_byte_array(u8 *p, size_t n) { if (!seeded) seed_random(); while (n--) *p++ = rand(); }
void Test_split_number(CuTest* tc) { seed_random(); int * test = split_number(1234, 50, 20); free(test); CuAssertIntEquals(tc, 0, 0); }
static unsigned int get_random(void) { static int initialized; if (!initialized) { seed_random(); initialized = 1; } return RAND() & 0xffffffff; }
static void populate_graph(void *graph, unsigned long long node_count) { unsigned long i; void **ptr; unsigned long gunk; seed_random(); /* Each cell of the array points to another place in the array. */ for (i = 0, ptr = graph; i < node_count; i++, ptr++) { gunk = (node_count - 1) * (rand() / (RAND_MAX + 1.0)); *ptr = (void *)(graph + (gunk * sizeof(void *))); } }
void test_seq(int n) { BiTree_s tree = { 0 }; Rec_s rec; unint i; if (FALSE) seed_random(); for (i = 0; i < n; i++) { rec.key = seq_lump(); rec.val = rnd_lump(); bi_insert(&tree, rec); } bi_print(&tree); }
int main() { gsl_integration_workspace *ws1, *ws2; const size_t ws_size = 100000; gsl_rng *rng; int status = 0; body b1, b2; const double m1 = 1.01e-3; const double m2 = 1.998e-3; const double a1 = 1.02; const double a2 = 10.3; const double eps = 1e-3; double rhs[BODY_VECTOR_SIZE]; double numerical_rhs[BODY_VECTOR_SIZE]; rng = gsl_rng_alloc(gsl_rng_ranlxd2); assert(rng != 0); seed_random(rng); ws1 = gsl_integration_workspace_alloc(ws_size); ws2 = gsl_integration_workspace_alloc(ws_size); assert(ws1 != 0); assert(ws2 != 0); init_random_body(rng, &b1, m1, a1, 1.0/0.0, 0.0, 0.0, 0.0); init_random_body(rng, &b2, m2, a2, 1.0/0.0, 0.0, 0.0, 0.0); raw_average_rhs(eps, &b1, &b2, ws1, ws_size, ws2, ws_size, EPS, EPS, numerical_rhs); average_rhs(eps, &b1, &b2, EPS, rhs); if (!check_vector_close(10.0*EPS, 10.0*EPS, BODY_VECTOR_SIZE, rhs, numerical_rhs)) { fprintf(stderr, "average-rhs-test: numerical average doesn't agree with analytical average\n"); fprintf(stderr, "Analytic: %15g %15g %15g %15g %15g %15g %15g %15g %15g %15g %15g\n", rhs[0], rhs[1], rhs[2], rhs[3], rhs[4], rhs[5], rhs[6], rhs[7], rhs[8], rhs[9], rhs[10]); fprintf(stderr, "Numerical: %15g %15g %15g %15g %15g %15g %15g %15g %15g %15g %15g\n", numerical_rhs[0], numerical_rhs[1], numerical_rhs[2], numerical_rhs[3], numerical_rhs[4], numerical_rhs[5], numerical_rhs[6], numerical_rhs[7], numerical_rhs[8], numerical_rhs[9], numerical_rhs[10]); status = 1; } gsl_rng_free(rng); gsl_integration_workspace_free(ws1); gsl_integration_workspace_free(ws2); return status; }
/* Fills @n characters pointed to by @p with random alphanumeric characters. */ void randomize_char_array_with_alnum(tchar *p, size_t n) { if (!seeded) seed_random(); while (n--) { int r = rand() % 62; if (r < 26) *p++ = r + 'a'; else if (r < 52) *p++ = r - 26 + 'A'; else *p++ = r - 52 + '0'; } }
void test_bi_find(int n) { BiTree_s tree = { 0 }; Rec_s rec; unint i; if (FALSE) seed_random(); for (i = 0; i < n; i++) { rec.key = fixed_lump(7); rec.val = rnd_lump(); r_add(rec); bi_insert(&tree, rec); } r_for_each(find_find, &tree); bi_audit(&tree); }
/* * Read parameters and fork off children that abuse first mmap and then * io_setup in the hopes of causing an oops. */ int main(int argc, char *argv[]) { int i, x, forks, mmap_calls, iosetup_calls; if (argc < 4) { printf("Usage: %s forks mmap_calls iosetup_calls\n", argv[0]); return 1; } forks = atoi(argv[1]); mmap_calls = atoi(argv[2]); iosetup_calls = atoi(argv[3]); printf("%.5d: forks = %d mmaps = %d iosetups = %d\n", getpid(), forks, mmap_calls, iosetup_calls); for (i = 0; i < forks; i++) { x = fork(); if (x == 0) { /* new proc, so start pounding */ printf("%.5d: initializing.\n", getpid()); seed_random(); install_signal_handlers(); printf("%.5d: creating mmaps.\n", getpid()); mmap_pound(mmap_calls); examine_vmsize(); printf("%.5d: calling iosetup..\n", getpid()); iosetup_pound(iosetup_calls); printf("%.5d: done pounding.\n", getpid()); return 0; } else { printf("%.5d: forked pid %.5d.\n", getpid(), x); } } printf("%.5d: waiting for children.\n", getpid()); for (i = 0; i < forks; i++) { wait(NULL); } printf("%.5d: exiting.\n", getpid()); return 0; }
void test_rnd(int n) { BiTree_s tree = { 0 }; Rec_s rec; unint i; if (FALSE) seed_random(); for (i = 0; i < n; i++) { rec.key = fixed_lump(7); rec.val = rnd_lump(); bi_insert(&tree, rec); } // bi_print(&tree); // pr_all_records(&tree); // pr_tree(&tree); bi_audit(&tree); }
int main (int argc, char *argv[]) { int *sray, *rray; int *sdisp, *scounts, *rdisp, *rcounts; int ssize, rsize, i, k, j; float z; init_it (&argc, &argv); scounts = (int *) shmem_malloc (sizeof (int) * numnodes); rcounts = (int *) shmem_malloc (sizeof (int) * numnodes); sdisp = (int *) shmem_malloc (sizeof (int) * numnodes); rdisp = (int *) shmem_malloc (sizeof (int) * numnodes); /* ! seed the random number generator with a ! different number on each processor */ seed_random (myid); /* find data to send */ for (i = 0; i < numnodes; i++) { random_number (&z); scounts[i] = (int) (10.0 * z) + 1; } printf ("-------myid= %d scounts=", myid); for (i = 0; i < numnodes; i++) { printf ("%d ", scounts[i]); } printf ("\n"); /* send the data */ // mpi_err = MPI_Alltoall(scounts,1,MPI_INT, rcounts,1,MPI_INT, // MPI_COMM_WORLD); shmem_barrier_all (); int other, j1; for (j1 = 0; j1 < numnodes; j1++) { shmem_int_put (&rcounts[myid], &scounts[j1], 1, j1); } shmem_barrier_all (); printf ("myid= %d rcounts=", myid); for (i = 0; i < numnodes; i++) { printf ("%d ", rcounts[i]); } printf ("\n"); shmem_finalize (); return 0; }
int main(int argc, char* argv[]) { Grid* grid = new Grid(20, 50); seed_random(grid); std::cout << "seed" << std::endl; grid->draw(std::cout); //grid->tick(); int i = 0; while (true) { std::cout << "\033[2J\033[1;1H"; std::cout << "generation " << i++ << std::endl; grid->tick(); grid->draw(std::cout); usleep(10000); } return 0; }
int main(int argc, char *argv[]) { int debug = 0; if (!seed_random()) { return 1; } if (argc > 1 && strcmp(argv[1], "-d") == 0) { debug = 1; } /* FILE *fp = fopen("/dev/tty", "w"); fprintf(fp, "randasys process group is %d\n", getpgrp()); fclose(fp); */ install_signal_handlers(); while(1) { callnum = find_syscall(); args[0] = get_randnum(0, ULONG_MAX); args[1] = get_randnum(0, ULONG_MAX); args[2] = get_randnum(0, ULONG_MAX); args[3] = get_randnum(0, ULONG_MAX); args[4] = get_randnum(0, ULONG_MAX); args[5] = get_randnum(0, ULONG_MAX); if (debug) { printf("syscall(%d, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X); \r", callnum, args[0], args[1], args[2], args[3], args[4], args[5]); fflush(stdout); } syscall(callnum, args[0], args[1], args[2], args[3], args[4], args[5]); } return 0; }
int main(int argc,char *argv[]){ int *sray,*rray; int *sdisp,*scounts,*rdisp,*rcounts; int ssize,rsize,i,k,j; float z; init_it(&argc,&argv); scounts=(int*)malloc(sizeof(int)*numnodes); rcounts=(int*)malloc(sizeof(int)*numnodes); sdisp=(int*)malloc(sizeof(int)*numnodes); rdisp=(int*)malloc(sizeof(int)*numnodes); /* ! seed the random number generator with a ! different number on each processor */ seed_random(myid); /* find data to send */ for(i=0;i<numnodes;i++){ random_number(&z); scounts[i]=(int)(10.0*z)+1; } printf("myid= %d scounts=",myid); for(i=0;i<numnodes;i++) printf("%d ",scounts[i]); printf("\n"); /* send the data */ mpi_err = MPI_Alltoall( scounts,1,MPI_INT, rcounts,1,MPI_INT, MPI_COMM_WORLD); printf("myid= %d rcounts=",myid); for(i=0;i<numnodes;i++) printf("%d ",rcounts[i]); printf("\n"); #ifdef _CIVL free(scounts); free(rcounts); free(sdisp); free(rdisp); #endif mpi_err = MPI_Finalize(); }
int main(int argc, char *argv[]) { int i; int debug = 0, zero_mode = 0; if (!seed_random()) { return 1; } for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-d")) debug = 1; else if (!strcmp(argv[i], "-z")) zero_mode = 1; } memset(args, 0, sizeof(unsigned long) * 6); install_signal_handlers(); while (1) { callnum = find_syscall(); if (!zero_mode) get_big_randnum(&args[0], sizeof(unsigned long) * 6); if (debug) { printf("syscall(%lu, 0x%lX, 0x%lX, 0x%lX, 0x%lX, " "0x%lX, 0x%lX); \n", callnum, args[0], args[1], args[2], args[3], args[4], args[5]); fflush(stdout); } syscall(callnum, args[0], args[1], args[2], args[3], args[4], args[5]); } return 0; }
int main(int argc, char *argv[]) { unsigned long xmax, ymax; unsigned long x, y; if (argc < 3) { fprintf(stderr, "Usage: %s xmax ymax\n", argv[0]); return 2; } xmax = atoi(argv[1]); ymax = atoi(argv[2]); if (!seed_random()) { return 1; } x = 1 + (unsigned long)((float)xmax * (rand() / (RAND_MAX + 1.0f))); y = 1 + (unsigned long)((float)ymax * (rand() / (RAND_MAX + 1.0f))); printf("+%lu+%lu\n", x, y); return 0; }
void simple_rng::seed_random(const unsigned call_count) { seed_random(random_seed_, call_count); }
int main() { const double RScale = 0.1; const double AScale = 1.0; const double IScale = 1e-2; const double MScale = 1.0; const double tVScale = 1.0; const double kScale = 0.1; const double eps = 1e-12; gsl_rng *rng; double SpinSun[3]; double tVSun, kSun, ISun, MSun, RSun; double zerov[3] = {0.0, 0.0, 0.0}; body b; central_body bc; double n; double a2; double adot; double ndot; double mu; double body_rhs[BODY_VECTOR_SIZE]; double sun_rhs[3]; double Ldot[3], hdot[3], bLdot[3], sLdot[3]; int i; rng = gsl_rng_alloc(gsl_rng_ranlxd2); assert(rng); seed_random(rng); init_body_from_elements(&b, MScale*gsl_rng_uniform(rng), AScale*gsl_rng_uniform(rng), gsl_rng_uniform(rng), 180.0*gsl_rng_uniform(rng), 360.0*gsl_rng_uniform(rng), 360.0*gsl_rng_uniform(rng), zerov, tVScale*gsl_rng_uniform(rng), kScale*gsl_rng_uniform(rng), IScale*gsl_rng_uniform(rng), RScale*gsl_rng_uniform(rng)); random_vector(rng, b.spin, 1.0); random_vector(rng, SpinSun, 1.0); tVSun = tVScale*gsl_rng_uniform(rng); kSun = kScale*gsl_rng_uniform(rng); ISun = IScale*gsl_rng_uniform(rng); RSun = RScale*gsl_rng_uniform(rng); init_central_body(&bc, tVSun, kSun, ISun, RSun, SpinSun); tidal_rhs(&b, &bc, body_rhs, sun_rhs); n = mean_motion(&b); a2 = b.a*b.a; adot = body_rhs[BODY_a_INDEX]; ndot = -3.0/2.0*adot/b.a*n; mu = b.m/(1.0+b.m); for (i = 0; i < 3; i++) { hdot[i] = mu*n*a2*(body_rhs[BODY_L_INDEX+i] + 0.5*(adot/b.a)*b.L[i]); bLdot[i] = b.I*body_rhs[BODY_SPIN_INDEX+i]; sLdot[i] = ISun*sun_rhs[i]; Ldot[i] = hdot[i] + bLdot[i] + sLdot[i]; } if (!check_close(eps, eps, norm(Ldot), 0.0)) { fprintf(stderr, "Ldot = {%g, %g, %g} not close to zero!\n", Ldot[0], Ldot[1], Ldot[2]); fprintf(stderr, "mu*hdot = {%g, %g, %g}\n", hdot[0], hdot[1], hdot[2]); fprintf(stderr, "Body LDot = {%g, %g, %g}\n", bLdot[0], bLdot[1], bLdot[2]); fprintf(stderr, "Sun LDot = {%g, %g, %g}\n", sLdot[0], sLdot[1], sLdot[2]); gsl_rng_free(rng); exit(1); } if (!check_close(eps, eps, dot(b.L, body_rhs + BODY_L_INDEX) + dot(b.A, body_rhs + BODY_A_INDEX), 0.0)) { fprintf(stderr, "A^2 + L^2 = 1.0 magnitude constraint violated!\n"); exit(1); } if (!check_close(eps, eps, dot(b.L, body_rhs + BODY_A_INDEX) + dot(b.A, body_rhs + BODY_L_INDEX), 0.0)) { fprintf(stderr, "A*L = 0 constraint violated!\n"); exit(1); } gsl_rng_free(rng); return 0; }
int main (int argc, char *argv[]) { int *sray, *rray; int *sdisp, *scounts, *rdisp, *rcounts; int ssize, rsize, i, k, j; float z; init_it (&argc, &argv); scounts = (int *) shmem_malloc (sizeof (int) * numnodes); rcounts = (int *) shmem_malloc (sizeof (int) * numnodes); sdisp = (int *) shmem_malloc (sizeof (int) * numnodes); rdisp = (int *) shmem_malloc (sizeof (int) * numnodes); /* ! seed the random number generator with a ! different number on each processor */ seed_random (myid); /* find out how much data to send */ for (i = 0; i < numnodes; i++) { random_number (&z); scounts[i] = (int) (5.0 * z) + 1; } printf ("myid= %d scounts=%d %d %d %d\n", myid, scounts[0], scounts[1], scounts[2], scounts[3]); /* tell the other processors how much data is coming */ // mpi_err = MPI_Alltoall(scounts,1,MPI_INT, rcounts,1,MPI_INT, // MPI_COMM_WORLD); shmem_barrier_all (); int other, j1; for (j1 = 0; j1 < numnodes; j1++) { shmem_int_put (&rcounts[myid], &scounts[j1], 1, j1); } shmem_barrier_all (); printf ("-----myid= %d rcounts=", myid); for (i = 0; i < numnodes; i++) { printf ("%d ", rcounts[i]); } printf ("\n"); /* write(*,*)"myid= ",myid," rcounts= ",rcounts */ /* calculate displacements and the size of the arrays */ sdisp[0] = 0; for (i = 1; i < numnodes; i++) { sdisp[i] = scounts[i - 1] + sdisp[i - 1]; } rdisp[0] = 0; for (i = 1; i < numnodes; i++) { rdisp[i] = rcounts[i - 1] + rdisp[i - 1]; } ssize = 0; rsize = 0; for (i = 0; i < numnodes; i++) { ssize = ssize + scounts[i]; rsize = rsize + rcounts[i]; } /* allocate send and rec arrays */ sray = (int *) shmem_malloc (sizeof (int) * 20); rray = (int *) shmem_malloc (sizeof (int) * 20); for (i = 0; i < ssize; i++) { sray[i] = myid; } /* send/rec different amounts of data to/from each processor */ // mpi_err = MPI_Alltoallv(sray,scounts,sdisp,MPI_INT, // rray,rcounts,rdisp,MPI_INT, MPI_COMM_WORLD); shmem_barrier_all (); for (j1 = 0; j1 < numnodes; j1++) { int k1 = sdisp[j1]; static int k2; shmem_int_get (&k2, &rdisp[myid], 1, j1); shmem_int_put (rray + k2, sray + k1, scounts[j1], j1); } shmem_barrier_all (); printf ("myid= %d rray=", myid); for (i = 0; i < rsize; i++) { printf ("%d ", rray[i]); } printf ("\n"); // mpi_err = MPI_Finalize(); shmem_finalize (); return 0; }
static PyObject* PyMangleMask_genrand_range(struct PyMangleMask* self, PyObject* args) { int status=1; PY_LONG_LONG nrand=0; double ramin=0,ramax=0,decmin=0,decmax=0; double cthmin=0,cthmax=0,phimin=0,phimax=0; struct Point pt; PyObject* ra_obj=NULL; PyObject* dec_obj=NULL; PyObject* tuple=NULL; double* ra_ptr=NULL; double* dec_ptr=NULL; double weight=0; npy_intp poly_id=0; npy_intp ngood=0; double theta=0, phi=0; if (!PyArg_ParseTuple(args, (char*)"Ldddd", &nrand, &ramin, &ramax, &decmin, &decmax)) { return NULL; } if (nrand <= 0) { PyErr_Format(PyExc_ValueError, "nrand should be > 0, got (%ld)",(npy_intp)nrand); status=0; goto _genrand_range_cleanup; } if (!radec_range_to_costhetaphi(ramin,ramax,decmin,decmax, &cthmin,&cthmax,&phimin,&phimax)) { status=0; goto _genrand_range_cleanup; } if (!(ra_obj=make_double_array(nrand, "ra", &ra_ptr))) { status=0; goto _genrand_range_cleanup; } if (!(dec_obj=make_double_array(nrand, "dec", &dec_ptr))) { status=0; goto _genrand_range_cleanup; } seed_random(); while (ngood < nrand) { genrand_theta_phi(cthmin,cthmax,phimin,phimax,&theta, &phi); point_set_from_thetaphi(&pt, theta, phi); //status=mangle_polyid_and_weight(self->mask, &pt, &poly_id, &weight); status=MANGLE_POLYID_AND_WEIGHT(self->mask, &pt, &poly_id, &weight); if (status != 1) { goto _genrand_range_cleanup; } if (poly_id >= 0) { // rely on short circuiting if (weight < 1.0 || drand48() < weight) { ngood++; radec_from_point(&pt, ra_ptr, dec_ptr); ra_ptr++; dec_ptr++; } } } _genrand_range_cleanup: if (status != 1) { Py_XDECREF(ra_obj); Py_XDECREF(dec_obj); Py_XDECREF(tuple); return NULL; } tuple=PyTuple_New(2); PyTuple_SetItem(tuple, 0, ra_obj); PyTuple_SetItem(tuple, 1, dec_obj); return tuple; }
int main (int argc, char *argv[]) { int *sray, *rray; int *sdisp, *scounts, *rdisp, *rcounts, *rcounts_full; int ssize, rsize, i, k, j; float z; init_it (&argc, &argv); scounts = (int *) shmem_malloc (sizeof (int) * numnodes); rcounts = (int *) shmem_malloc (sizeof (int) * numnodes); rcounts_full = (int *) shmem_malloc (sizeof (int) * numnodes * numnodes); sdisp = (int *) shmem_malloc (sizeof (int) * numnodes); rdisp = (int *) shmem_malloc (sizeof (int) * numnodes); /* ! seed the random number generator with a ! different number on each processor */ seed_random (myid); /* find out how much data to send */ for (i = 0; i < numnodes; i++) { random_number (&z); scounts[i] = (int) (5.0 * z) + 1; } printf ("myid= %d scounts=%d %d %d %d\n", myid, scounts[0], scounts[1], scounts[2], scounts[3]); printf ("\n"); /* tell the other processors how much data is coming */ // mpi_err = MPI_Alltoall(scounts,1,MPI_INT, rcounts,1,MPI_INT, // MPI_COMM_WORLD); static long psync[_SHMEM_COLLECT_SYNC_SIZE]; for (i = 0; i < _SHMEM_COLLECT_SYNC_SIZE; i++) psync[i] = _SHMEM_SYNC_VALUE; shmem_barrier_all (); int other, j1; shmem_fcollect32 (rcounts_full, scounts, 4, 0, 0, numnodes, psync); for (i = 0; i < numnodes; i++) { rcounts[i] = rcounts_full[i * numnodes + myid]; } printf ("-----myid= %d rcounts=", myid); for (i = 0; i < numnodes; i++) printf ("%d ", rcounts[i]); printf ("\n"); /* write(*,*)"myid= ",myid," rcounts= ",rcounts */ /* calculate displacements and the size of the arrays */ sdisp[0] = 0; for (i = 1; i < numnodes; i++) { sdisp[i] = scounts[i - 1] + sdisp[i - 1]; } rdisp[0] = 0; for (i = 1; i < numnodes; i++) { rdisp[i] = rcounts[i - 1] + rdisp[i - 1]; } ssize = 0; rsize = 0; for (i = 0; i < numnodes; i++) { ssize = ssize + scounts[i]; rsize = rsize + rcounts[i]; } /* allocate send and rec arrays */ sray = (int *) shmem_malloc (sizeof (int) * 20); rray = (int *) shmem_malloc (sizeof (int) * 20); for (i = 0; i < ssize; i++) { sray[i] = myid; } /* send/rec different amounts of data to/from each processor */ // mpi_err = MPI_Alltoallv(sray,scounts,sdisp,MPI_INT, // rray,rcounts,rdisp,MPI_INT, MPI_COMM_WORLD); shmem_barrier_all (); for (j1 = 0; j1 < numnodes; j1++) { int k1 = sdisp[j1]; static int k2; shmem_int_get (&k2, &rdisp[myid], 1, j1); shmem_int_put (rray + k2, sray + k1, scounts[j1], j1); } shmem_barrier_all (); // not possible, coz even though the rcounts[myid] will be different on // each PE, the elements collected // by PE0 from other PE's will be constant. // shmem_collect32(rray_full,sray,rcounts[myid],0,0,numnodes,psync); printf ("myid= %d rray=", myid); for (i = 0; i < rsize; i++) printf ("%d ", rray[i]); printf ("\n"); // mpi_err = MPI_Finalize(); shmem_finalize (); return 0; }
bool random_bool() { static bool seeded = seed_random(); return rand() % 2 == 0; }