/** @file * transpose of 1-d array. * E,g: (1 2 3 4 5 6 7 8 9 10) => (10 9 8 7 6 5 4 3 2 1) */ #define TOTALELEMS 1007031 #include #include #include #include #include #include #include "mp3.h" #include "armci.h" void VERIFY(void **b_ptr, int *dims, int *map) { int i, j, length, icnt, ichk, lmin, lmax; int *buf, *b; void *src_ptr, *dst_ptr; int me, nprocs; /* Find local processor ID and number of processors */ me = armci_msg_me(); nprocs = armci_msg_nproc(); /* Process 0 verifies that inversion is correct. Start by allocating buffer and guarantee that it is big enough */ length = (int)(((double)dims[0])/((double)nprocs)) + 1; buf = (int*)malloc(length*sizeof(int)); if (me == 0) { icnt = 0; ichk = 0; for (i=0; i= map[i]) { pmin = i; } else { break; } } pmax = nprocs-1; for (i=nprocs-2; i>=0; i--) { if (max < map[i+1]) { pmax = i; } else { break; } } /* Loop over processors that will receive data and copy inverted data to processors */ for (i=pmin; i<=pmax; i++) { /* Find min and max indices owned by processor i */ lmin = map[i]; if (i min) { cmin = lmin; } else { cmin = min; } if (lmax < max) { cmax = lmax; } else { cmax = max; } /* Find offsets on source and destination processors */ src_offset = cmin - min; src_ptr = (void*)(buf + src_offset); dst_offset = cmin - lmin; dst_ptr = (u_int8_t*)b_ptr[i] + sizeof(int)*dst_offset; /* Find length of data (in bytes) to be sent to processor i */ length = sizeof(int)*(cmax-cmin+1); /* Send data to processor */ ARMCI_Put(src_ptr, dst_ptr, length, i); } ARMCI_AllFence(); MP_BARRIER(); free(buf); VERIFY(b_ptr, dims, map); free(map); MP_BARRIER(); ARMCI_Free(a_ptr[me]); ARMCI_Free(b_ptr[me]); free(a_ptr); free(b_ptr); } int main(int argc, char **argv) { /* int heap=300000, stack=300000; */ int me, nprocs; /* Step1: Initialize Message Passing library */ MP_INIT(argc, argv); /* Step2: Initialize ARMCI */ ARMCI_Init(); /* Step3: Initialize Memory Allocator (MA) */ /*bjp if(! MA_init(C_DBL, stack, heap) ) ARMCI_Error("MA_init failed",stack+heap); */ me = armci_msg_me(); nprocs = armci_msg_nproc(); if(me==0) { printf("\nUsing %d processes\n\n", nprocs); fflush(stdout); } TRANSPOSE1D(); if(me==0)printf("\nTerminating ..\n"); ARMCI_Finalize(); MP_FINALIZE(); return(0); }