void * threadmain(void *args) { int i, idx; testfunc_t func; threaddata_t *td = (threaddata_t *) args; TEST_SRAND(((int)TIME()) * td->tid); thread_barrier(); if (!threadstress) MSG("tid=%3d> starting.", td->tid); for (i = 0; i < iters; i++) { idx = TEST_RAND(0,functions_num-1); func = test_functions[idx]; assert(func != NULL); func(td); if (td->ltid == 0 && !threadstress) TEST_PROGRESS_BAR(i, iters); } thread_barrier(); if (!threadstress) MSG("tid=%3d> done.", td->tid); return NULL; }
/* All nodes must get the same random sequence */ static void randomize(thread_data_t *td) { local_barrier(); if (td->local_id == 0) { int i; static int srand_phase = 1; TEST_SRAND(srand_phase++); for (i=0; i<iters; ++i) { R[i] = TEST_RAND(0,1000000000); } } local_barrier(); }
int main(int argc, char **argv) { static int *A, *B, *C, *D, *E, *F, *G; gasnet_node_t myproc, i; int j; /* call startup */ GASNET_Safe(gasnet_init(&argc, &argv)); if (argc > 1) { iters = atoi(argv[1]); } if (iters < 1) { iters = 1000; } #if GASNET_PAR if (argc > 2) { threads = atoi(argv[2]); } threads = test_thread_limit(threads); if (threads < 1) { printf("ERROR: Threads must be between 1 and %d\n", TEST_MAXTHREADS); exit(EXIT_FAILURE); } #endif /* get SPMD info */ myproc = gasnet_mynode(); numprocs = gasnet_nodes(); images = numprocs * threads; datasize = iters * (3 + 4 * images); GASNET_Safe(gasnet_attach(NULL, 0, TEST_SEGSZ_REQUEST, TEST_MINHEAPOFFSET)); test_init("testcoll",0,"(iters) (threadcnt)"); TEST_SET_WAITMODE(threads); if (argc > 3) test_usage(); MSG0("Running coll test(s) with %d iterations.", iters); R = test_malloc(iters*sizeof(int)); TEST_SRAND(1); /* Number if ints to store */ /* Carve some variables out of the (aligned) segment: */ Aw = test_malloc(iters * sizeof(int *)); Bw = test_malloc(iters * sizeof(int *)); Cw = test_malloc(iters * sizeof(int *)); Dw = test_malloc(iters * sizeof(int *)); Ew = test_malloc(iters * sizeof(int *)); Fw = test_malloc(iters * sizeof(int *)); Gw = test_malloc(iters * sizeof(int *)); A = (int *)TEST_MYSEG(); /* int [1*iters] */ B = A + 1*iters; /* int [1*iters] */ C = B + 1*iters; /* int [N*iters] */ D = C + images*iters; /* int [N*iters] */ E = D + images*iters; /* int [1*iters] */ F = E + 1*iters; /* int [N*iters] */ G = F + images*iters; /* int [N*iters] */ for (j = 0; j < iters; ++j) { Aw[j] = A + j; Bw[j] = B + j; Cw[j] = C + j*images; Dw[j] = D + j*images; Ew[j] = E + j; Fw[j] = F + j*images; Gw[j] = G + j*images; } /* The unaligned equivalents */ Av = test_malloc_2D(iters, images * sizeof(int *)); Bv = test_malloc_2D(iters, images * sizeof(int *)); Cv = test_malloc_2D(iters, images * sizeof(int *)); Dv = test_malloc_2D(iters, images * sizeof(int *)); Ev = test_malloc_2D(iters, images * sizeof(int *)); Fv = test_malloc_2D(iters, images * sizeof(int *)); Gv = test_malloc_2D(iters, images * sizeof(int *)); for (i = 0; i < images; ++i) { /* Using (TEST_SEG(n) + n) yields unaligned even when the segments are aligned. This is to help catch any case where addresses might have been misused that might go undetected if the addresses were aligned */ A = (int *)TEST_SEG(i/threads) + (i/threads) + datasize*(i%threads); B = A + 1*iters; C = B + 1*iters; D = C + images*iters; E = D + images*iters; F = E + 1*iters; G = F + images*iters; for (j = 0; j < iters; ++j) { Av[j][i] = A + j; Bv[j][i] = B + j; Cv[j][i] = C + j*images; Dv[j][i] = D + j*images; Ev[j][i] = E + j; Fv[j][i] = F + j*images; Gv[j][i] = G + j*images; } } BARRIER(); #if GASNET_PAR MSG("Forking %d gasnet threads", threads); { int i; thread_data_t* tt_thread_data = test_malloc(threads*sizeof(thread_data_t)); for (i = 0; i < threads; i++) { tt_thread_data[i].myproc = myproc; tt_thread_data[i].local_id = i; tt_thread_data[i].mythread = i + threads * myproc; tt_thread_data[i].peerthread = i + threads * (((myproc ^ 1) == numprocs) ? myproc : (myproc ^ 1)); } test_createandjoin_pthreads(threads, &thread_main, tt_thread_data, sizeof(tt_thread_data[0])); test_free(tt_thread_data); } #else { thread_data_t td; td.myproc = myproc; td.local_id = 0; td.mythread = myproc; td.peerthread = ((myproc ^ 1) == numprocs) ? myproc : (myproc ^ 1); thread_main(&td); } #endif BARRIER(); test_free(Aw); test_free(Bw); test_free(Cw); test_free(Dw); test_free_2D(Av); test_free_2D(Bv); test_free_2D(Cv); test_free_2D(Dv); test_free(R); MSG("done."); gasnet_exit(0); return 0; }
int main(int argc, char **argv) { int outer_iterations = 0; int inner_iterations = 0; int seedoffset = 0; int numprocs, myproc, peerproc; int sender_p; char *shadow_region_1, *shadow_region_2; int i,j; char *local_base, *target_base; /* call startup */ GASNET_Safe(gasnet_init(&argc, &argv)); /* get SPMD info */ myproc = gasnet_mynode(); numprocs = gasnet_nodes(); if (argc > 1) segsize = atoi(argv[1]); if (!segsize) segsize = 1024*1000; if (argc > 2) outer_iterations = atoi(argv[2]); if (!outer_iterations) outer_iterations = 10; if (argc > 3) inner_iterations = atoi(argv[3]); if (!inner_iterations) inner_iterations = 10; if (argc > 4) seedoffset = atoi(argv[4]); GASNET_Safe(gasnet_attach(NULL, 0, TEST_SEGSZ, TEST_MINHEAPOFFSET)); test_init("testslice",0, "(segsize) (iterations) (# of sizes per iteration) (seed)"); /* parse arguments */ if (argc > 5) test_usage(); if(numprocs & 1) { MSG0("WARNING: This test requires an even number of nodes. Test skipped.\n"); gasnet_exit(0); /* exit 0 to prevent false negatives in test harnesses for smp-conduit */ } sender_p = !(myproc & 1); peerproc = myproc ^ 1; if (seedoffset == 0) { seedoffset = (((unsigned int)TIME()) & 0xFFFF); TEST_BCAST(&seedoffset, 0, &seedoffset, sizeof(&seedoffset)); } TEST_SRAND(myproc+seedoffset); MSG0("Running with segment size = %d outer iterations=%d inner iterations=%d seed=%d", segsize,outer_iterations, inner_iterations, seedoffset); BARRIER(); /* Allocate two shadow regions the same size as the segment */ shadow_region_1 = (char *) test_malloc(segsize); shadow_region_2 = (char *) test_malloc(segsize); /* Fill up the shadow region with random data */ for(i=0; i < segsize; i++) { shadow_region_1[i] = (char) TEST_RAND(0,255); } memset(shadow_region_2,0,segsize); /* Big loop performing the following */ for(i=0; i < outer_iterations; i++) { if(sender_p) { /* Pick a starting point anywhere in the segment */ int starting_point = TEST_RAND(0,(segsize-1)); local_base = TEST_SEG(myproc); target_base = TEST_SEG(peerproc); for(j=0; j < inner_iterations; j++) { /* Pick a length */ int len = TEST_RAND(1,segsize-starting_point); int remote_starting_point = TEST_RAND(0,segsize-len); int local_starting_point_1 = TEST_RAND(0,segsize-len); int local_starting_point_2 = TEST_RAND(0,segsize-len); /* Perform operations */ /* Out of segment put from shadow_region 1 to remote */ gasnet_put(peerproc,target_base+remote_starting_point,shadow_region_1 + starting_point,len); /* In segment get from remote to local segment */ gasnet_get(local_base+local_starting_point_1,peerproc,target_base+remote_starting_point,len); /* Verify */ assert_eq(shadow_region_1 + starting_point, local_base + local_starting_point_1, len,starting_point,i,j,"Out of segment put + in segment get"); /* Out of segment get from remote to shadow_region_2 (starting from 0) */ gasnet_get(shadow_region_2+local_starting_point_2,peerproc,target_base+remote_starting_point,len); /* Verify */ assert_eq(shadow_region_2+local_starting_point_2, shadow_region_1 + starting_point, len,starting_point,i,j,"Out of segment get"); } TEST_PROGRESS_BAR(i,outer_iterations); } BARRIER(); } if(sender_p && !failures) { MSG("testslice PASSED"); } gasnet_exit(0); return 0; }
int main(int argc, char **argv) { int outer_iterations = 0; int inner_iterations = 0; int seedoffset = 0; int numprocs, myproc; #if PLATFORM_COMPILER_CLANG // The addition of a gratuitous 'volatile' here has been observed to // work-around Bug 3630 in which Clang 4 and newer misoptimize this test. volatile int peerproc; #else int peerproc; #endif int sender_p; char *shadow_region_1, *shadow_region_2; int i,j; char *local_base, *target_base; /* call startup */ GASNET_Safe(gex_Client_Init(&myclient, &myep, &myteam, "testslice", &argc, &argv, 0)); /* get SPMD info */ myproc = gex_TM_QueryRank(myteam); numprocs = gex_TM_QuerySize(myteam); if (argc > 1) segsize = atoi(argv[1]); if (!segsize) segsize = 1024*1000; if (argc > 2) outer_iterations = atoi(argv[2]); if (!outer_iterations) outer_iterations = 10; if (argc > 3) inner_iterations = atoi(argv[3]); if (!inner_iterations) inner_iterations = 10; if (argc > 4) seedoffset = atoi(argv[4]); GASNET_Safe(gex_Segment_Attach(&mysegment, myteam, TEST_SEGSZ)); test_init("testslice",0, "(segsize) (iterations) (# of sizes per iteration) (seed)"); /* parse arguments */ if (argc > 5) test_usage(); if(numprocs & 1) { MSG0("WARNING: This test requires an even number of nodes. Test skipped.\n"); gasnet_exit(0); /* exit 0 to prevent false negatives in test harnesses for smp-conduit */ } sender_p = !(myproc & 1); peerproc = myproc ^ 1; if (seedoffset == 0) { seedoffset = (((unsigned int)TIME()) & 0xFFFF); TEST_BCAST(&seedoffset, 0, &seedoffset, sizeof(&seedoffset)); } TEST_SRAND(myproc+seedoffset); MSG0("Running with segment size = %d outer iterations=%d inner iterations=%d seed=%d", segsize,outer_iterations, inner_iterations, seedoffset); BARRIER(); /* Allocate two shadow regions the same size as the segment */ shadow_region_1 = (char *) test_malloc(segsize); shadow_region_2 = (char *) test_malloc(segsize); /* Fill up the shadow region with random data */ for(i=0;i < segsize;i++) { shadow_region_1[i] = (char) TEST_RAND(0,255); } memset(shadow_region_2,0,segsize); /* Big loop performing the following */ for(i=0;i < outer_iterations;i++) { if(sender_p) { /* Pick a starting point anywhere in the segment */ int starting_point = TEST_RAND(0,(segsize-1)); local_base = TEST_SEG(myproc); target_base = TEST_SEG(peerproc); for(j=0;j < inner_iterations;j++) { /* Pick a length */ int len = TEST_RAND(1,segsize-starting_point); int remote_starting_point = TEST_RAND(0,segsize-len); int local_starting_point_1 = TEST_RAND(0,segsize-len); int local_starting_point_2 = TEST_RAND(0,segsize-len); /* Perform operations */ /* Out of segment put from shadow_region 1 to remote */ gex_RMA_PutBlocking(myteam, peerproc,target_base+remote_starting_point,shadow_region_1 + starting_point,len, 0); /* In segment get from remote to local segment */ gex_RMA_GetBlocking(myteam, local_base+local_starting_point_1,peerproc,target_base+remote_starting_point,len, 0); /* Verify */ assert_eq(shadow_region_1 + starting_point, local_base + local_starting_point_1, len,starting_point,i,j,"Out of segment put + in segment get"); /* Out of segment get from remote to shadow_region_2 (starting from 0) */ gex_RMA_GetBlocking(myteam, shadow_region_2+local_starting_point_2,peerproc,target_base+remote_starting_point,len, 0); /* Verify */ assert_eq(shadow_region_2+local_starting_point_2, shadow_region_1 + starting_point, len,starting_point,i,j,"Out of segment get"); } TEST_PROGRESS_BAR(i,outer_iterations); } BARRIER(); } if(sender_p && !failures) { MSG("testslice PASSED"); } gasnet_exit(0); return 0; }