int main (void) { int i; start_pes (0); npes = shmem_n_pes (); me = shmem_my_pe (); for (i = 0; i < DST_SIZE; i++) { dst[i] = -1; } for (i = 0; i < _SHMEM_BCAST_SYNC_SIZE; i += 1) { pSync[i] = _SHMEM_SYNC_VALUE; } shmem_barrier_all (); shmem_collect64 (dst, src, me + 1, 0, 0, 4, pSync); show_dst ("AFTER"); return 0; }
int main (int argc, char **argv) { int i; int nextpe; int me, npes; long src[N]; long *dest; shmemx_request_handle_t handle; start_pes (0); me = shmem_my_pe (); npes = shmem_n_pes (); for (i = 0; i < N; i += 1) { src[i] = (long) me; } dest = (long *) shmalloc (N * sizeof (*dest)); nextpe = (me + 1) % npes; shmemx_long_put_nb (dest, src, N, nextpe, &handle); shmemx_wait_req (handle); shmem_barrier_all (); shfree (dest); return 0; }
/* Performance test for shmem_broadcast32 */ #include <stdio.h> #include <stdlib.h> #include <time.h> #include <sys/time.h> #include <shmem.h> long pSyncA[_SHMEM_BCAST_SYNC_SIZE]; long pSyncB[_SHMEM_BCAST_SYNC_SIZE]; #define N_ELEMENTS 25600/*Data size chosen to be able to capture time required*/ int main(void) { int i,j,k; int *target; int *source; int me, npes; struct timeval start, end; long time_taken,start_time,end_time; start_pes(0); me = _my_pe(); npes = _num_pes(); source = (int *) shmalloc( N_ELEMENTS * sizeof(*source) ); time_taken = 0; for (i = 0; i < N_ELEMENTS; i += 1) { source[i] = i + 1; } target = (int *) shmalloc( N_ELEMENTS * sizeof(*target) ); for (i = 0; i < N_ELEMENTS; i += 1) { target[i] = -90; } for (i = 0; i < _SHMEM_BCAST_SYNC_SIZE; i += 1) { pSyncA[i] = _SHMEM_SYNC_VALUE; pSyncB[i] = _SHMEM_SYNC_VALUE; } shmem_barrier_all(); for(i=0;i<10000;i++){ gettimeofday(&start, NULL); start_time = (start.tv_sec * 1000000.0) + start.tv_usec; /* alternate between 2 pSync arrays to synchronize * consequent collectives of even and odd iterations */ if(i % 2) shmem_broadcast32(target, source, N_ELEMENTS, 0, 0, 0, npes, pSyncA); else shmem_broadcast32(target, source, N_ELEMENTS, 0, 0, 0, npes, pSyncB); gettimeofday(&end, NULL); end_time = (end.tv_sec * 1000000.0) + end.tv_usec; if(me==0){ time_taken = time_taken + (end_time - start_time); } } if(me == 0) printf("Time required for a broadcast of 100 Kbytes of data, with %d PEs is %ld microseconds\n",npes,time_taken/10000); shmem_barrier_all(); shfree(target); shfree(source); return 0; }
void Setup(ArgStruct *p) { int npes; start_pes(2); if((npes=shmem_n_pes())!=2) { printf("Error Message: Run with npes set to 2\n"); exit(1); } p->prot.flag=(int *) shmalloc(sizeof(int)); pTime = (double *) shmalloc(sizeof(double)); pNrepeat = (int *) shmalloc(sizeof(int)); p->tr = p->rcv = 0; if((p->prot.ipe=_my_pe()) == 0) { p->tr=1; p->prot.nbor=1; *p->prot.flag=1; } else { p->rcv=1; p->prot.nbor=0; *p->prot.flag=0; } }
int main() { start_pes(0); me = shmem_my_pe(); npes = shmem_n_pes(); shmem_barrier_all(); if(me%2==0){ a = 42; shmem_barrier_all(); } else{ a = 0; //shmem_barrier_all(); } shmem_barrier_all(); if (me == 0) { printf("value in a is %d (should be 42)\n", a); } return 0; }
int main(){ int me, npes; start_pes(0); me = shmem_my_pe(); npes = shmem_n_pes(); for (i = 0; i < _SHMEM_REDUCE_SYNC_SIZE; i += 1) { pSync[i] = _SHMEM_SYNC_VALUE; } x = 42; y = 0; if(me==0){ shmem_barrier_all(); temp = x+y; } else { shmem_barrier_all(); if(me==1){ old = shmem_int_finc (&y, 0); shmem_int_sum_to_all(&y,&x,1,1,0,npes-1,pWrk,pSync); x= x+10; shmem_int_get(&y,&y,1,0); } else{ shmem_int_sum_to_all(&y,&x, 1,1,0,npes-1,pWrk,pSync); x=y*0.23; } } shmem_barrier_all(); if (me == 0) { printf("value in temp is %d (should be 42)\n", temp); } return 0; }
int main (void) { double *f; int me; start_pes (0); me = shmem_my_pe (); f = (double *) shmalloc (sizeof (*f)); *f = PI; shmem_barrier_all (); if (me == 0) { shmem_double_p (f, E, 1); } shmem_barrier_all (); if (me == 1) { printf ("PE %d: %f, %s\n", me, *f, (fabs (*f - E) < epsilon) ? "OK" : "FAIL"); } shfree (f); return 0; }
int main (int argc, char **argv) { int npes; int me; int *ip; start_pes (0); npes = shmem_n_pes (); me = shmem_my_pe (); /* fire off allocation */ ip = shmalloc_nb (sizeof (*ip)); printf ("PE %d / %d does some other work in the middle of shmalloc_nb\n", me, npes); /* now wait for all PEs to be ready */ shmem_barrier_all (); if (me == 0) { /* PE 0 writes number of PEs to top PE */ shmem_int_p (ip, npes, npes - 1); } shmem_barrier_all (); printf ("PE %d / %d says \"ip\" = %d\n", me, npes, *ip); shfree_nb (ip); printf ("PE %d / %d does some other work in the middle of shfree_nb\n", me, npes); return 0; }
int main(void) { short source[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; static short target[10]; int me; start_pes(0); me = _my_pe(); if (me == 0) { /* put 10 words into target on PE 1 */ shmem_short_iput(target, source, 1, 2, 5, 1); } shmem_barrier_all(); /* sync sender and receiver */ if (me == 1) { printf("target on PE %d is %hd %hd %hd %hd %hd\n", me, target[0], target[1], target[2], target[3], target[4] ); } shmem_barrier_all(); /* sync before exiting */ return 0; }
int main (int argc, char **argv) { int me; int slp; start_pes (0); me = shmem_my_pe (); slp = 1; shmem_barrier_all (); if (me == 1) { sleep (3); } shmem_set_lock (&L); printf ("%d: sleeping %d second%s...\n", me, slp, slp == 1 ? "" : "s"); sleep (slp); printf ("%d: sleeping...done\n", me); shmem_clear_lock (&L); shmem_barrier_all (); return 0; }
int main (void) { int i; long *target; static long source[8] = { 1, 2, 3, 4, 5, 6, 7, 8 }; int nlong = 8; int me; start_pes (0); me = shmem_my_pe (); target = (long *) shmalloc (8 * sizeof (*target)); for (i = 0; i < _SHMEM_BCAST_SYNC_SIZE; i += 1) { pSync[i] = _SHMEM_SYNC_VALUE; } shmem_barrier_all (); shmem_broadcast64 (target, source, nlong, 1, 0, 0, 4, pSync); for (i = 0; i < 8; i++) { printf ("%d: target[%d] = %ld\n", me, i, target[i]); } shmem_barrier_all (); shfree (target); return 0; }
void init_it(int *argc, char ***argv) { //mpi_err = MPI_Init(argc,argv); //mpi_err = MPI_Comm_size( MPI_COMM_WORLD, &numnodes ); //mpi_err = MPI_Comm_rank(MPI_COMM_WORLD, &myid); start_pes(0); numnodes = shmem_n_pes(); myid = shmem_my_pe(); }
int main(void) { start_pes(0); printf("I am %d of %d. \n", shmem_my_pe(), shmem_n_pes() ); return 0; }
int main(int argc, char *argv[]){ int i,next_pivot, pivot; for (i=0; i < SHMEM_BCAST_SYNC_SIZE; i++) { pSync[i] = _SHMEM_SYNC_VALUE; } start_pes(0); me = shmem_my_pe(); npes = shmem_n_pes(); shmem_barrier_all(); srand (me+time(NULL)); N = atoi(argv[1]); //int *nelems = (int*) shmalloc(sizeof(int)); //int *nelems_import= (int*) shmalloc(sizeof(int));; printf("%d: Size = %d with np=%d\n",me,N,npes); A = (int *)shmalloc((N/npes)*sizeof(int)); temp_arr = (int *)shmalloc((2*N/npes)*sizeof(int)); if(A==NULL){ printf("\nOut of memory"); return 1; } n= N/npes; i=0; while(i<N/npes){ A[i] = rand()%(10000-0); i++; } printf("\nprocess %d elements:",me); for(i=0;i<(N/npes);i++){ printf("%d, ", A[i]); } pivot = quicksort(A, 0, n-1); printf("Process %d the pivot:%d",me, pivot); shmem_barrier_all(); //just for the sake of clear display...can be removed in the end printf("\nThe sorted list is of process %d: ",me); for(i=0;i<N/npes;i++){ printf("%d, ",A[i]); } printf("\n"); hyperquick(A,N/npes,npes); printf("\n"); shfree(temp_arr); shfree(A); shmem_finalize(); }
int main(void) { int me; start_pes(0); me = _my_pe(); printf("My PE id is: %d\n", me); return 0; }
int main (void) { int me, npes; long *dest; { time_t now; time (&now); srand (now + getpid ()); } start_pes (0); me = shmem_my_pe (); npes = shmem_n_pes (); dest = (long *) shmalloc (sizeof (*dest)); *dest = 9L; shmem_barrier_all (); if (me == 0) { int i; for (i = 0; i < 4; i += 1) { long src = 9L; shmem_long_put (dest, &src, 1, 1); fprintf (stderr, "PE %d put %d\n", me, src); } fprintf (stderr, "----------------------------\n"); for (i = 0; i < 1000; i += 1) { long src = rand () % 10; shmem_long_put (dest, &src, 1, 1); fprintf (stderr, "PE %d put %d\n", me, src); if (src != 9L) break; } } shmem_barrier_all (); if (me == 1) { shmem_long_wait (dest, 9L); fprintf (stderr, "PE %d finished wait, got %d\n", me, *dest); } shmem_barrier_all (); return 0; }
struct pe_vars init_openshmem (void) { struct pe_vars v; start_pes(0); v.me = _my_pe(); v.npes = _num_pes(); v.pairs = v.npes / 2; v.nxtpe = v.me < v.pairs ? v.me + v.pairs : v.me - v.pairs; return v; }
int main(int argc, char *argv[]) { int n = 100; // int n1=101; start_pes(0); int nn = (n-1) / _num_pes(); int n_local0 = 1 + _my_pe() * nn; int n_local1 = 1 + (_my_pe()+1) * nn; // allocate only local part + ghost zone of the arrays x,y float *x, *y; x = (float*) malloc((n_local1 - n_local0 + 2)*sizeof(float)); y = (float*) malloc((n_local1 - n_local0 + 2)*sizeof(float)); // forgot shmalloc shmem_barrier_all(); //... // fill x, y // fill ghost zone if (_my_pe() > 0) shmem_float_get(x,y,n1,1); // extra code shmem_float_put(y,x, 1, _my_pe()-1); shmem_barrier_all(); // do computation float e = 0; int i; for (i=n_local0; i<n_local1; ++i) { x[i] += ( y[i+1] + y[i-1] )*.5; e += y[i] * y[i]; } static float work[_SHMEM_REDUCE_SYNC_SIZE]; static long sync[_SHMEM_REDUCE_SYNC_SIZE]; static float el, es; el = e; shmem_float_sum_to_all(&es, &el, 1, 0, 0, _num_pes(), work, sync); e = es; // ... // output x, e x += (n_local0 - 1); y += (n_local0 - 1); shfree(x); shfree(y); return 0; }
int main(int argc, char* argv[]) { int i, Verbose=0; char *pgm; if ((pgm=strrchr(argv[0],'/'))) pgm++; else pgm = argv[0]; if (argc > 1) { if (strncmp(argv[1],"-v",3) == 0) Verbose=1; else if (strncmp(argv[1],"-h",3) == 0) { fprintf(stderr,"usage: %s {v(verbose)|h(help)}\n",pgm); exit(1); } } for (i = 0; i < _SHMEM_REDUCE_SYNC_SIZE; i += 1) { pSync[i] = _SHMEM_SYNC_VALUE; } start_pes(0); for (i = 0; i < N; i += 1) { src[i] = _my_pe() + i; } shmem_barrier_all(); shmem_long_max_to_all(dst, src, N, 0, 0, _num_pes(), pWrk, pSync); if (Verbose) { printf("%d/%d dst =", _my_pe(), _num_pes() ); for (i = 0; i < N; i+= 1) { printf(" %ld", dst[i]); } printf("\n"); } for (i = 0; i < N; i+= 1) { if (dst[i] != _num_pes() - 1 + i) return 1; } return 0; }
int main () { int old; int me; start_pes (0); me = shmem_my_pe (); value = me + 1; old = shmem_int_cswap (&value, value, -value, me); printf ("%d: value = %d, old = %d\n", me, value, old); return 0; }
int main (void) { int i; long *target; long *source; int me, npes; start_pes (0); me = shmem_my_pe (); npes = shmem_n_pes (); source = (long *) shmalloc (npes * sizeof (*source)); for (i = 0; i < npes; i += 1) { source[i] = i + 1; } target = (long *) shmalloc (npes * sizeof (*target)); for (i = 0; i < npes; i += 1) { target[i] = -999; } for (i = 0; i < _SHMEM_BCAST_SYNC_SIZE; i += 1) { pSync[i] = _SHMEM_SYNC_VALUE; } shmem_barrier_all (); shmem_broadcast64 (target, source, npes, 0, 0, 0, npes, pSync); for (i = 0; i < npes; i++) { printf ("%-8d %ld\n", me, target[i]); } shmem_barrier_all (); shfree (target); shfree (source); return 0; }
int main () { static int race_winner = -1; int oldval; int me; start_pes (0); me = shmem_my_pe (); oldval = shmem_int_cswap (&race_winner, -1, me, 0); if (oldval == -1) { printf ("pe %d was first\n", me); } return 0; }
int main (int argc, char **argv) { int nextpe; int me, npes; int src; int *dest; start_pes (0); me = shmem_my_pe (); npes = shmem_n_pes (); nextpe = (me + 1) % npes; src = nextpe; dest = (int *) shmalloc (sizeof (*dest)); /* symmetric */ assert (dest != NULL); *dest = -1; shmem_barrier_all (); shmem_int_put (dest, & src, 1, nextpe); shmem_barrier_all (); printf ("%4d: got %4d: ", me, *dest); if (*dest == me) { printf ("CORRECT"); } else { printf ("WRONG, expected %d", me); } printf ("\n"); shmem_barrier_all (); shfree (dest); return 0; }
int main (void) { static int aaa, bbb; int num_pes, my_pe, peer; start_pes(0); num_pes = _num_pes(); my_pe = _my_pe(); peer = (my_pe + 1) % num_pes; printf("Process %d gets message from %d (%d processes in ring)\n", my_pe, peer, num_pes); shmem_int_get(&aaa, &bbb, 1, peer); shmem_barrier_all(); printf("Process %d exiting\n", my_pe); return 0; }
int main(int argc, char *argv[]){ start_pes(0); int me = shmem_my_pe(); int npes = shmem_n_pes(); int i,N,n,pivot; srand (me+time(NULL)); N = atoi(argv[1]); printf("%d: Size = %d with np=%d\n",me,N,npes); int *A = (int *)shmalloc((N/npes)*sizeof(int)); if(A==NULL){ printf("\nOut of memory"); return 1; } n= N/npes; i=0; while(i<N/npes){ A[i] = rand()%(10000-0); i++; } printf("\nprocess %d elements:",me); for(i=0;i<(N/npes);i++){ printf("%d, ", A[i]); } pivot=quicksort(A, 0, n-1); printf("Process %d the pivot:%d",me, pivot); shmem_barrier_all(); printf("\nThe sorted list is of process %d: ",me); for(i=0;i<n;i++){ printf("%d, ",A[i]); } printf("\n"); shfree(A); shmem_finalize(); }
int main () { int me; start_pes (0); me = shmem_my_pe (); dst = 74; shmem_barrier_all (); if (me == 0) { shmem_int_inc (&dst, 1); } shmem_barrier_all (); printf ("%d: dst = %d\n", me, dst); return 0; }
int main(void) { double *f; int me; start_pes(0); me = _my_pe(); f = (double *) shmalloc(sizeof (*f)); *f = 3.1415927; shmem_barrier_all(); if (me == 0) shmem_double_p(f, e, 1); shmem_barrier_all(); if (me == 1) printf("%s\n", (fabs (*f - e) < epsilon) ? "OK" : "FAIL"); return 0; }
int main( ) { int i, rc; long long elapsed_us, elapsed_cyc; elapsed_us = PAPI_get_real_usec( ); elapsed_cyc = PAPI_get_real_cyc( ); start_pes( 2 ); Thread( 1000000 * ( _my_pe( ) + 1 ) ); elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc; elapsed_us = PAPI_get_real_usec( ) - elapsed_us; printf( "Master real usec : \t%lld\n", elapsed_us ); printf( "Master real cycles : \t%lld\n", elapsed_cyc ); exit( 0 ); }
int main (int argc, char *argv[]) { int me; start_pes (0); me = _my_pe (); if (me > 0) { shmem_int_add (&counter, me, 0); } shmem_barrier_all (); if (me == 0) { printf ("counter = %d\n", counter); } return 0; }
int main(void) { int me, npes; setbuf(stdout, NULL); start_pes(0); me = _my_pe(); npes = _num_pes(); if (me == 0) { int i; for (i = 1; i < npes; i += 1) { printf("From %d: PE %d is ", me, i); printf("%s", shmem_pe_accessible(i) ? "" : "NOT "); printf("accessible\n"); } } return 0; }