static int gasnetc_reghandlers(gasnet_handlerentry_t *table, int numentries, int lowlimit, int highlimit, int dontcare, int *numregistered) { int i; *numregistered = 0; for (i = 0; i < numentries; i++) { int newindex; if ((table[i].index == 0 && !dontcare) || (table[i].index && dontcare)) continue; else if (table[i].index) newindex = table[i].index; else { /* deterministic assignment of dontcare indexes */ for (newindex = lowlimit; newindex <= highlimit; newindex++) { if (!checkuniqhandler[newindex]) break; } if (newindex > highlimit) { char s[255]; snprintf(s, sizeof(s), "Too many handlers. (limit=%i)", highlimit - lowlimit + 1); GASNETI_RETURN_ERRR(BAD_ARG, s); } } /* ensure handlers fall into the proper range of pre-assigned values */ if (newindex < lowlimit || newindex > highlimit) { char s[255]; snprintf(s, sizeof(s), "handler index (%i) out of range [%i..%i]", newindex, lowlimit, highlimit); GASNETI_RETURN_ERRR(BAD_ARG, s); } /* discover duplicates */ if (checkuniqhandler[newindex] != 0) GASNETI_RETURN_ERRR(BAD_ARG, "handler index not unique"); checkuniqhandler[newindex] = 1; /* register the handler */ if (AM_SetHandler(gasnetc_endpoint, (handler_t)newindex, table[i].fnptr) != AM_OK) GASNETI_RETURN_ERRR(RESOURCE, "AM_SetHandler() failed while registering handlers"); #ifdef GASNETC_MAX_NUMHANDLERS /* Maintain a shadow handler table */ gasnetc_handler[(gasnet_handler_t)newindex] = (gasneti_handler_fn_t)table[i].fnptr; #endif /* The check below for !table[i].index is redundant and present * only to defeat the over-aggressive optimizer in pathcc 2.1 */ if (dontcare && !table[i].index) table[i].index = newindex; (*numregistered)++; } return GASNET_OK; }
int main(int argc, char **argv) { eb_t eb; ep_t ep; uint64_t networkpid; int64_t begin, end, total; int polling = 1; int iters = 0; TEST_STARTUP(argc, argv, networkpid, eb, ep, 1, 2, "iters (Poll/Block)"); /* setup handlers */ AM_Safe(AM_SetHandler(ep, LARGE_REQ_HANDLER, large_request_handler)); AM_Safe(AM_SetHandler(ep, LARGE_REP_HANDLER, large_reply_handler)); setupUtilHandlers(ep, eb); /* get SPMD info */ myproc = AMX_SPMDMyProc(); numprocs = AMX_SPMDNumProcs(); if (argc > 1) iters = atoi(argv[1]); if (!iters) iters = 1; if (argc > 2) { switch(argv[2][0]) { case 'p': case 'P': polling = 1; break; case 'b': case 'B': polling = 0; break; default: printf("polling must be 'P' or 'B'..\n"); AMX_SPMDExit(1); } } if (numprocs % 2 != 0 && numprocs > 1) { printf("requires an even or unary number of processors\n"); AMX_SPMDExit(1); } VMseg = (uint32_t *)malloc(AM_MaxLong()+100); memset(VMseg, 0, AM_MaxLong()+100); AM_Safe(AM_SetSeg(ep, VMseg, AM_MaxLong()+100)); if (myproc % 2 == 0) partner = (myproc + 1) % numprocs; else partner = (myproc - 1); AM_Safe(AMX_SPMDBarrier()); if (myproc == 0) printf("Running %i iterations of bulk bounce test...\n", iters); begin = getCurrentTimeMicrosec(); if (myproc % 2 == 1 || numprocs == 1) { int q; for (q=0; q<iters; q++) { /* init my source mem */ int i; uint32_t *srcmem = (uint32_t *)(((uint8_t*)VMseg)+100); for (i = 0; i < AM_MaxLong()/4; i++) { srcmem[i] = (uint32_t)((count << 16) + i); } #if VERBOSE printf("%i: sending request...", myproc); fflush(stdout); #endif done = 0; AM_Safe(AM_RequestXfer1(ep, partner, 100, LARGE_REQ_HANDLER, srcmem, AM_MaxLong(), 666)); if (polling) { /* poll until everyone done */ while (!done) { AM_Safe(AM_Poll(eb)); } } else { while (!done) { AM_Safe(AM_SetEventMask(eb, AM_NOTEMPTY)); AM_Safe(AM_WaitSema(eb)); AM_Safe(AM_Poll(eb)); } } } } else { if (polling) { /* poll until everyone done */ while (count<iters*2) { AM_Safe(AM_Poll(eb)); } } else { while (count<iters*2) { AM_Safe(AM_SetEventMask(eb, AM_NOTEMPTY)); AM_Safe(AM_WaitSema(eb)); AM_Safe(AM_Poll(eb)); } } } end = getCurrentTimeMicrosec(); total = end - begin; printf("Slave %i: %i microseconds total, throughput: %8.3f KB/sec\n", myproc, (int)total, (float)(((float)1000000)*AM_MaxLong()*iters/((int)total))/1024.0); fflush(stdout); /* dump stats */ AM_Safe(AMX_SPMDBarrier()); printGlobalStats(); AM_Safe(AMX_SPMDBarrier()); /* exit */ AM_Safe(AMX_SPMDExit(0)); return 0; }
/* ------------------------------------------------------------------------------------ */ extern int gasnetc_amregister(gex_AM_Index_t index, gex_AM_Entry_t *entry) { if (AM_SetHandler(gasnetc_endpoint, (handler_t)index, entry->gex_fnptr) != AM_OK) GASNETI_RETURN_ERRR(RESOURCE, "AM_SetHandler() failed while registering handlers"); return GASNET_OK; }
int main(int argc, char **argv) { eb_t eb; ep_t ep; uint64_t networkpid; int64_t begin, end, total; int polling = 1; int fullduplex = 0; int rightguy; uint32_t *srcmem; int iters = 0; TEST_STARTUP(argc, argv, networkpid, eb, ep, 1, 4, "iters (bulkmsgsize) (Poll/Block) (Half/Full)"); /* setup handlers */ AM_Safe(AM_SetHandler(ep, BULK_REQ_HANDLER, bulk_request_handler)); AM_Safe(AM_SetHandler(ep, BULK_REP_HANDLER, bulk_reply_handler)); setupUtilHandlers(ep, eb); /* get SPMD info */ myproc = AMX_SPMDMyProc(); numprocs = AMX_SPMDNumProcs(); if (argc > 1) iters = atoi(argv[1]); if (!iters) iters = 1; if (argc > 2) size = atoi(argv[2]); if (size == -1) size = 512; if (argc > 3) { switch(argv[3][0]) { case 'p': case 'P': polling = 1; break; case 'b': case 'B': polling = 0; break; default: printf("polling must be 'P' or 'B'..\n"); AMX_SPMDExit(1); } } if (argc > 4) { switch(argv[4][0]) { case 'h': case 'H': fullduplex = 0; break; case 'f': case 'F': fullduplex = 1; break; default: printf("duplex must be H or F..\n"); AMX_SPMDExit(1); } } if (!fullduplex && numprocs > 1 && numprocs % 2 != 0) { printf("half duplex requires an even number of processors\n"); AMX_SPMDExit(1); } msg_size = (size > AM_MaxLong() ? AM_MaxLong() : size); nummsgs = (size % AM_MaxLong() == 0 ? size / AM_MaxLong() : (size / AM_MaxLong())+1); srcmem = (uint32_t *)malloc(msg_size); memset(srcmem, 0, msg_size); VMseg = (uint32_t *)malloc(msg_size+100); memset(VMseg, 0, msg_size+100); AM_Safe(AM_SetSeg(ep, VMseg, msg_size+100)); rightguy = (myproc + 1) % numprocs; { /* init my source mem */ int i; int numints = msg_size/4; for (i=0; i < numints; i++) srcmem[i] = i; } AM_Safe(AMX_SPMDBarrier()); if (myproc == 0) printf("Running %s bulk test sz=%i...\n", (fullduplex?"full-duplex":"half-duplex"), size); begin = getCurrentTimeMicrosec(); if (fullduplex || myproc % 2 == 1 || numprocs == 1) { int q; for (q=0; q<iters; q++) { int j; msg_size = AM_MaxLong(); for (j = 0; j < nummsgs; j++) { if (j == nummsgs-1 && size % AM_MaxLong() != 0) msg_size = size % AM_MaxLong(); /* last one */ #if VERBOSE_PING printf("%i: sending request...", myproc); fflush(stdout); #endif AM_Safe(AM_RequestXfer1(ep, rightguy, 100, BULK_REQ_HANDLER, srcmem, msg_size, 666)); } } } { int expectedmsgs = nummsgs*iters; if (numprocs == 1 || fullduplex) expectedmsgs *= 2; if (polling) { /* poll until everyone done */ while (done<expectedmsgs) { AM_Safe(AM_Poll(eb)); } } else { while (done<expectedmsgs) { AM_Safe(AM_SetEventMask(eb, AM_NOTEMPTY)); AM_Safe(AM_WaitSema(eb)); AM_Safe(AM_Poll(eb)); } } } end = getCurrentTimeMicrosec(); total = end - begin; if (fullduplex || myproc % 2 == 1 || numprocs == 1) printf("Slave %i: %i microseconds total, throughput: %8.3f KB/sec\n", myproc, (int)total, (float)(((float)1000000)*size*iters/((int)total))/1024.0); fflush(stdout); /* dump stats */ AM_Safe(AMX_SPMDBarrier()); printGlobalStats(); AM_Safe(AMX_SPMDBarrier()); /* exit */ AM_Safe(AMX_SPMDExit(0)); return 0; }
/* usage: testlatency numprocs spawnfn iters P/B */ int main(int argc, char **argv) { uint64_t networkpid; int64_t begin, end, total; int polling = 1; int k; int iters = 0; TEST_STARTUP(argc, argv, networkpid, eb, ep, 1, 2, "iters (Poll/Block)"); /* setup handlers */ AM_Safe(AM_SetHandler(ep, PING_REQ_HANDLER, ping_request_handler)); AM_Safe(AM_SetHandler(ep, PING_REP_HANDLER, ping_reply_handler)); setupUtilHandlers(ep, eb); /* get SPMD info */ myproc = AMX_SPMDMyProc(); numprocs = AMX_SPMDNumProcs(); if (argc > 1) iters = atoi(argv[1]); if (!iters) iters = 1; if (argc > 2) { switch(argv[2][0]) { case 'p': case 'P': polling = 1; break; case 'b': case 'B': polling = 0; break; default: printf("polling must be 'P' or 'B'..\n"); AMX_SPMDExit(1); } } outputTimerStats(); AM_Safe(AMX_SPMDBarrier()); if (myproc == 0) printf("Running %i iterations of latency test...\n", iters); if (myproc == 0 && numprocs > 1) numleft = (numprocs-1)*iters; AM_Safe(AMX_SPMDBarrier()); begin = getCurrentTimeMicrosec(); if (myproc == 0 && numprocs > 1) { mywait(polling); } else { /* everybody sends packets to 0 */ int expect = (numprocs > 1 ? 1 : 2); for (k=0;k < iters; k++) { numleft = expect; #if VERBOSE printf("%i: sending request...", myproc); fflush(stdout); #endif AM_Safe(AM_Request0(ep, 0, PING_REQ_HANDLER)); mywait(polling); } } end = getCurrentTimeMicrosec(); total = end - begin; if (myproc != 0 || numprocs == 1) printf("Slave %i: %i microseconds total, throughput: %i requests/sec (%.3f us / request)\n", myproc, (int)total, (int)(((float)1000000)*iters/((int)total)), ((double)total)/iters); else printf("Slave 0 done.\n"); fflush(stdout); /* dump stats */ AM_Safe(AMX_SPMDBarrier()); printGlobalStats(); AM_Safe(AMX_SPMDBarrier()); /* exit */ AM_Safe(AMX_SPMDExit(0)); return 0; }