int main(int argc, char ** argv) { int rank, nproc, i; int *buf; MPI_Init(&argc, &argv); ARMCI_Init(); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &nproc); if (rank == 0) printf("Starting ARMCI GOP test with %d processes\n", nproc); buf = malloc(DATA_SZ*sizeof(int)); if (rank == 0) printf(" - Testing ABSMIN\n"); for (i = 0; i < DATA_SZ; i++) buf[i] = (rank+1) * ((i % 2) ? -1 : 1); armci_msg_igop(buf, DATA_SZ, "absmin"); for (i = 0; i < DATA_SZ; i++) if (buf[i] != 1) { printf("Err: buf[%d] = %d expected 1\n", i, buf[i]); ARMCI_Error("Fail", 1); } if (rank == 0) printf(" - Testing ABSMAX\n"); for (i = 0; i < DATA_SZ; i++) buf[i] = (rank+1) * ((i % 2) ? -1 : 1); armci_msg_igop(buf, DATA_SZ, "absmax"); for (i = 0; i < DATA_SZ; i++) if (buf[i] != nproc) { printf("Err: buf[%d] = %d expected %d\n", i, buf[i], nproc); ARMCI_Error("Fail", 1); } free(buf); if (rank == 0) printf("Pass.\n"); ARMCI_Finalize(); MPI_Finalize(); return 0; }
void armci_client_connect_to_servers() { int stat,c, nall; char str[100]; #ifndef SERVER_THREAD int p; /* master has to close all sockets -- they are used by server PROCESS */ if(armci_master==armci_me)for(p=0; p< armci_nproc; p++){ close(CLN_sock[p]); } #endif /* exchange port numbers with processes in all cluster nodes * save number of messages by using global sum -only masters contribute */ nall = armci_nclus*armci_nproc; armci_msg_igop(AR_port,nall,"+"); /*using port number create socket & connect to data server in each clus node*/ for(c=0; c< armci_nclus; c++){ int off_port = c*armci_nproc; #ifdef SERVER_THREAD /*no intra node socket connection with server thread*/ if(c == armci_clus_me) SRV_sock[c]=-1; else #endif SRV_sock[c] = armci_CreateSocketAndConnect(armci_clus_info[c].hostname, AR_port[off_port + armci_me]); if(DEBUG_ && SRV_sock[c]!=-1){ printf("%d: client connected to %s:%d\n",armci_me, armci_clus_info[c].hostname, AR_port[off_port + armci_me]); fflush(stdout); } } if(DEBUG_){ bzero(str,99); for(c=0; c< armci_nclus; c++)if(SRV_sock[c]!=-1){ stat =armci_ReadFromSocket(SRV_sock[c],str, sizeof(msg)+1); if(stat<0)armci_die("read failed",stat); printf("in client %d message was=%s from%d\n",armci_me,str,c); fflush(stdout); } } free(AR_port); /* we do not need the port numbers anymore */ }
void test_gop2_or_reduce(const int datatype, char * op, const int reduce_test) { void *a[6]; int len[6] = {1, 10, 100, 1000, 10000, 100000}; int len_length = 3; int datatype_size = 0; int i, j; char * test_type; int verbose = 0; if(reduce_test == 0) test_type = "gop2"; else test_type = "reduce"; switch(datatype) { case ARMCI_INT: datatype_size = sizeof(int); for(i = 0; i < len_length; i++) a[i] = malloc(len[i] * datatype_size); for(i = 0; i < len_length; i++) for(j = 0; j < len[i]; j++) ((int *) a[i])[j] = (int) (me + j) * (((me + j) % 2 == 0) ? 1 : -1); for(i = 0; i < len_length; i++) { if(me == 0 && verbose != 0) printf("testing %s %s message size = %d op = %s\n", test_type, "ARMCI_INT", len[i], op); if(reduce_test == 0) armci_msg_igop(a[i], len[i], op); else armci_msg_reduce(a[i], len[i], op, datatype); } if(me == 0 || reduce_test == 0) for(i = 0; i < len_length; i++) { if(me == 0 && verbose != 0) printf("checking %s %s message size = %d op = %s\n", test_type, "ARMCI_INT", len[i], op); for(j = 0; j < len[i]; j++) if(strncmp(op, "+", 1) == 0) { int compare = 0; if(nproc % 2 == 0) { if(j % 2 == 0) compare = -nproc / 2; else compare = nproc / 2; } else { if(j % 2 == 0) compare = j + nproc / 2; else compare = -(j + nproc / 2); } if(((int *) a[i])[j] != compare) { printf("ERROR %s %s %s a[%d][%d] = %d != %d\n", test_type, "ARMCI_INT", op, i, j, ((int *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "*", 1) == 0) { int compare = 1; int k = 0; for(k = 0; k < nproc; k++) compare *= (k + j) * (((k + j) % 2 == 0) ? 1 : -1); if(((int *) a[i])[j] != compare) { printf("ERROR %s %s %s a[%d][%d] = %d != %d\n", test_type, "ARMCI_INT", op, i, j, ((int *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "min", 3) == 0) { int compare = -(j + nproc - 1); if(compare % 2 == 0 && nproc > 1) compare = -(j + nproc - 2); if(((int *) a[i])[j] != compare) { printf("ERROR %s %s %s a[%d][%d] = %d != %d\n", test_type, "ARMCI_INT", op, i, j, ((int *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "max", 3) == 0) { int compare = j + nproc - 1; if(compare % 2 != 0 && nproc > 1) compare = j + nproc - 2; if(((int *) a[i])[j] != compare) { printf("ERROR %s %s %s a[%d][%d] = %d != %d\n", test_type, "ARMCI_INT", op, i, j, ((int *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "absmax", 6) == 0) { int compare = j + nproc - 1; if(((int *) a[i])[j] != compare) { printf("ERROR %s %s %s a[%d][%d] = %d != %d\n", test_type, "ARMCI_INT", op, i, j, ((int *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "absmin", 6) == 0) { int compare = j; if(((int *) a[i])[j] != compare) { printf("ERROR %s %s %s a[%d][%d] = %d != %d\n", test_type, "ARMCI_INT", op, i, j, ((int *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "or", 2) == 0) { } } break; case ARMCI_LONG: datatype_size = sizeof(long); for(i = 0; i < len_length; i++) a[i] = malloc(len[i] * datatype_size); for(i = 0; i < len_length; i++) for(j = 0; j < len[i]; j++) ((long *) a[i])[j] = (long) (me + j) * (((me + j) % 2 == 0) ? 1 : -1); for(i = 0; i < len_length; i++) { if(me == 0 && verbose != 0) printf("testing %s %s message size = %d op = %s\n", test_type, "ARMCI_LONG", len[i], op); if(reduce_test == 0) armci_msg_lgop(a[i], len[i], op); else armci_msg_reduce(a[i], len[i], op, datatype); } if(me == 0 || reduce_test == 0) for(i = 0; i < len_length; i++) { if(me == 0 && verbose != 0) printf("checking %s %s message size = %d op = %s\n", test_type, "ARMCI_LONG", len[i], op); for(j = 0; j < len[i]; j++) if(strncmp(op, "+", 1) == 0) { int compare = 0; if(nproc % 2 == 0) { if(j % 2 == 0) compare = -nproc / 2; else compare = nproc / 2; } else { if(j % 2 == 0) compare = j + nproc / 2; else compare = -(j + nproc / 2); } if(((long *) a[i])[j] != compare) { printf("ERROR %s %s %s a[%d][%d] = %ld != %d\n", test_type, "ARMCI_LONG", op, i, j, ((long *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "*", 1) == 0) { int compare = 1; int k = 0; for(k = 0; k < nproc; k++) compare *= (k + j) * (((k + j) % 2 == 0) ? 1 : -1); if(((long *) a[i])[j] != compare) { printf("ERROR %s %s %s a[%d][%d] = %ld != %d\n", test_type, "ARMCI_LONG", op, i, j, ((long *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "min", 3) == 0) { int compare = -(j + nproc - 1); if(compare % 2 == 0 && nproc > 1) compare = -(j + nproc - 2); if(((long *) a[i])[j] != compare) { printf("ERROR %s %s %s a[%d][%d] = %ld != %d\n", test_type, "ARMCI_LONG", op, i, j, ((long *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "max", 3) == 0) { int compare = j + nproc - 1; if(compare % 2 != 0 && nproc > 1) compare = j + nproc - 2; if(((long *) a[i])[j] != compare) { printf("ERROR %s %s %s a[%d][%d] = %ld != %d\n", test_type, "ARMCI_LONG", op, i, j, ((long *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "absmax", 6) == 0) { int compare = j + nproc - 1; if(((long *) a[i])[j] != compare) { printf("ERROR %s %s %s a[%d][%d] = %ld != %d\n", test_type, "ARMCI_LONG", op, i, j, ((long *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "absmin", 6) == 0) { int compare = j; if(((long *) a[i])[j] != compare) { printf("ERROR %s %s %s a[%d][%d] = %ld != %d\n", test_type, "ARMCI_LONG", op, i, j, ((long *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "or", 2) == 0) { } } break; case ARMCI_FLOAT: datatype_size = sizeof(float); for(i = 0; i < len_length; i++) a[i] = malloc(len[i] * datatype_size); for(i = 0; i < len_length; i++) for(j = 0; j < len[i]; j++) ((float *) a[i])[j] = (float) (me + j) * (((me + j) % 2 == 0) ? 1.0 / nproc : -1.0 / nproc); for(i = 0; i < len_length; i++) { if(me == 0 && verbose != 0) printf("testing %s ARMCI_FLOAT message size = %d op = %s\n", test_type, len[i], op); if(reduce_test == 0) armci_msg_fgop(a[i], len[i], op); else armci_msg_reduce(a[i], len[i], op, datatype); } if(me == 0 || reduce_test == 0) for(i = 0; i < len_length; i++) { if(me == 0 && verbose != 0) printf("checking %s ARMCI_FLOAT message size = %d op = %s\n", test_type, len[i], op); for(j = 0; j < len[i]; j++) if(strncmp(op, "+", 1) == 0) { float compare = 0.0; if(nproc % 2 == 0) { if(j % 2 == 0) compare = -(((int)nproc / 2) / (float) nproc); else compare = ((int)nproc / 2) / (float) nproc; } else { if(j % 2 == 0) compare = ((int) j + nproc / 2) / (float) nproc; else compare = -(((int) j + nproc / 2) / (float) nproc); } if(ARMCI_ABS(((float *) a[i])[j] - compare) > ARMCI_ABS(compare) * FLOAT_EPS) { printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_FLOAT", op, i, j, ((float *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "*", 1) == 0) { float compare = 1.0; int k = 0; for(k = 0; k < nproc; k++) compare *= ((float) k + j) / (float) nproc; if((nproc / 2) % 2 != 0) if(nproc % 2 != 0) if(j % 2 == 0) compare *= -1.0; if(ARMCI_ABS(((float *) a[i])[j] - compare) > ARMCI_ABS(compare) * FLOAT_EPS) { printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_FLOAT", op, i, j, ((float *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "min", 3) == 0) { float compare = -((float) j + nproc - 1) / nproc; if((j + nproc - 1)% 2 == 0 && nproc > 1) compare = -((float) j + nproc - 2) / nproc; if(((float *) a[i])[j] != compare) { printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_FLOAT", op, i, j, ((float *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "max", 3) == 0) { float compare = ((float) j + nproc - 1) / nproc; if((j + nproc - 1) % 2 != 0 && nproc > 1) compare = ((float) j + nproc - 2) / nproc; if(((float *) a[i])[j] != compare) { printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_FLOAT", op, i, j, ((float *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "absmax", 6) == 0) { float compare = ((float) j + nproc - 1) / nproc; if(((float *) a[i])[j] != compare) { printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_FLOAT", op, i, j, ((float *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "absmin", 6) == 0) { float compare = (float) j / nproc; if(((float *) a[i])[j] != compare) { printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_FLOAT", op, i, j, ((float *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } } break; case ARMCI_DOUBLE: datatype_size = sizeof(double); for(i = 0; i < len_length; i++) a[i] = malloc(len[i] * datatype_size); for(i = 0; i < len_length; i++) for(j = 0; j < len[i]; j++) ((double *) a[i])[j] = (double) (me + j) * (((me + j) % 2 == 0) ? 1.0 / nproc : -1.0 / nproc); for(i = 0; i < len_length; i++) { if(me == 0 && verbose != 0) printf("testing %s ARMCI_DOUBLE message size = %d op = %s\n", test_type, len[i], op); if(reduce_test == 0) armci_msg_dgop(a[i], len[i], op); else armci_msg_reduce(a[i], len[i], op, datatype); } if(me == 0 || reduce_test == 0) for(i = 0; i < len_length; i++) { if(me == 0 && verbose != 0) printf("checking %s ARMCI_DOUBLE message size = %d op = %s\n", test_type, len[i], op); for(j = 0; j < len[i]; j++) if(strncmp(op, "+", 1) == 0) { double compare = 0.0; if(nproc % 2 == 0) { if(j % 2 == 0) compare = -(((int)nproc / 2) / (double) nproc); else compare = ((int)nproc / 2) / (double) nproc; } else { if(j % 2 == 0) compare = ((int) j + nproc / 2) / (double) nproc; else compare = -(((int) j + nproc / 2) / (double) nproc); } if(ARMCI_ABS(((double *) a[i])[j] - compare) > ARMCI_ABS(compare) * DOUBLE_EPS) { printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_DOUBLE", op, i, j, ((double *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "*", 1) == 0) { double compare = 1.0; int k = 0; for(k = 0; k < nproc; k++) compare *= ((float) k + j) / (float) nproc; if((nproc / 2) % 2 != 0) if(nproc % 2 != 0) if(j % 2 == 0) compare *= -1.0; if(ARMCI_ABS(((double *) a[i])[j] - compare) > ARMCI_ABS(compare) * DOUBLE_EPS) { printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_DOUBLE", op, i, j, ((double *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "min", 3) == 0) { double compare = -((double) j + nproc - 1) / nproc; if((j + nproc - 1)% 2 == 0 && nproc > 1) compare = -((double) j + nproc - 2) / nproc; if(ARMCI_ABS(((double *) a[i])[j] - compare) > ARMCI_ABS(compare) * DOUBLE_EPS) { printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_DOUBLE", op, i, j, ((double *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "max", 3) == 0) { double compare = ((double) j + nproc - 1) / nproc; if((j + nproc - 1) % 2 != 0 && nproc > 1) compare = ((double) j + nproc - 2) / nproc; if(ARMCI_ABS(((double *) a[i])[j] - compare) > ARMCI_ABS(compare) * DOUBLE_EPS) { printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_DOUBLE", op, i, j, ((double *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "absmax", 6) == 0) { double compare = ((double) j + nproc - 1) / nproc; if(ARMCI_ABS(((double *) a[i])[j] - compare) > ARMCI_ABS(compare) * DOUBLE_EPS) { printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_DOUBLE", op, i, j, ((double *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } else if(strncmp(op, "absmin", 6) == 0) { double compare = (double) j / nproc; if(ARMCI_ABS(((double *) a[i])[j] - compare) > ARMCI_ABS(compare) * DOUBLE_EPS) { printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_DOUBLE", op, i, j, ((double *) a[i])[j], compare); ARMCI_Error("test_gop2_or_reduce failed\n",0); } } } break; default: break; } for(i = 0; i < len_length; i++) free(a[i]); }
void TestGlobals() { #define MAXLENG 256*1024 double *dtest; int *itest; long *ltest; int len; int ifrom=nproc-1,lfrom=1,dfrom=1; if (me == 0) { printf("Global test ... broadcast and reduction for int, long, double\n----------\n"); fflush(stdout); } if (!(dtest = (double *) malloc((unsigned) (MAXLENG*sizeof(double))))) ARMCI_Error("TestGlobals: failed to allocated dtest", MAXLENG); if (!(ltest = (long *) malloc((unsigned) (MAXLENG*sizeof(long))))) ARMCI_Error("TestGlobals: failed to allocated ltest", MAXLENG); if (!(itest = (int *) malloc((unsigned) (MAXLENG*sizeof(int))))) ARMCI_Error("TestGlobals: failed to allocated itest", MAXLENG); for (len=1; len<MAXLENG; len*=2) { int ilen = len*sizeof(int); int dlen = len*sizeof(double); int llen = len*sizeof(long); int i; ifrom = (ifrom+1)%nproc; lfrom = (lfrom+1)%nproc; dfrom = (lfrom+1)%nproc; #if 0 printf("%d:ifrom=%d lfrom=%d dfrom=%d\n",me,ifrom,lfrom,dfrom);fflush(stdout); #endif if (me == 0) { printf("Test length = %d ... ", len); fflush(stdout); } if(me == ifrom)for (i=0; i<len; i++)itest[i]=i; else for (i=0; i<len; i++)itest[i]=0; if(me == lfrom)for (i=0; i<len; i++)ltest[i]=(long)i; else for (i=0; i<len; i++)ltest[i]=0L; if(me == dfrom)for (i=0; i<len; i++)dtest[i]=(double)i; else for (i=0; i<len; i++)dtest[i]=0.0; /* Test broadcast */ armci_msg_brdcst(itest, ilen, ifrom); armci_msg_brdcst(ltest, llen, lfrom); armci_msg_brdcst(dtest, dlen, dfrom); for (i=0; i<len; i++){ if (itest[i] != i) armci_die2("int broadcast failed", i,itest[i]); if (ltest[i] != (long)i) armci_die2("long broadcast failed", i,(int)ltest[i]); if (dtest[i] != (double)i) armci_die2("double broadcast failed", i,(int)dtest[i]); } if (me == 0) { printf("broadcast OK ..."); fflush(stdout); } /* Test global sum */ for (i=0; i<len; i++) { itest[i] = i*me; ltest[i] = (long) itest[i]; dtest[i] = (double) itest[i]; } armci_msg_igop(itest, len, "+"); armci_msg_lgop(ltest, len, "+"); armci_msg_dgop(dtest, len, "+"); for (i=0; i<len; i++) { int iresult = i*nproc*(nproc-1)/2; if (itest[i] != iresult || ltest[i] != (long)iresult || dtest[i] != (double) iresult) ARMCI_Error("TestGlobals: global sum failed", (int) i); } if (me == 0) { printf("global sums OK\n"); fflush(stdout); } } /* now we get timing data */ time_gop(dtest,MAXLENG); time_reduce(dtest,MAXLENG); free((char *) itest); free((char *) ltest); free((char *) dtest); }
int PARMCI_Create_mutexes(int num) { int rc,p, totcount; int *mutex_count = (int*)armci_internal_buffer; if((sizeof(int)*armci_nproc) > armci_getbufsize()) { mutex_count = (double *)malloc(sizeof(int)*armci_nproc); } if (num < 0 || num > MAX_LOCKS) return(FAIL); if(num_mutexes) armci_die("mutexes already created",num_mutexes); if(armci_nproc == 1) { num_mutexes=1; return(0); } /* local memory allocation for mutex arrays*/ mutex_mem_ar = (void*) malloc(armci_nproc*sizeof(void*)); if(!mutex_mem_ar) armci_die("ARMCI_Create_mutexes: malloc failed",0); glob_mutex = (void*)malloc(armci_nproc*sizeof(mutex_entry_t)); if(!glob_mutex) { free(mutex_mem_ar); armci_die("ARMCI_Create_mutexes: malloc 2 failed",0); } /* bzero(mutex_count,armci_nproc*sizeof(int));*/ bzero((char*)mutex_count,sizeof(int)*armci_nproc); /* find out how many mutexes everybody allocated */ mutex_count[armci_me]=num; armci_msg_igop(mutex_count, armci_nproc, "+"); for(p=totcount=0; p< armci_nproc; p++)totcount+=mutex_count[p]; tickets = calloc(totcount,sizeof(int)); if(!tickets) { free(glob_mutex); free(mutex_mem_ar); return(FAIL2); } /* we need memory for token and turn - 2 ints */ rc = PARMCI_Malloc(mutex_mem_ar,2*num*sizeof(int)); if(rc) { free(glob_mutex); free(mutex_mem_ar); free(tickets); return(FAIL3); } if(num)bzero((char*)mutex_mem_ar[armci_me],2*num*sizeof(int)); /* setup global mutex array */ for(p=totcount=0; p< armci_nproc; p++) { glob_mutex[p].token = mutex_mem_ar[p]; glob_mutex[p].turn = glob_mutex[p].token + mutex_count[p]; glob_mutex[p].count = mutex_count[p]; glob_mutex[p].tickets = tickets + totcount; totcount += mutex_count[p]; } num_mutexes= totcount; #ifdef LAPI mymutexcount = num; #endif PARMCI_Barrier(); if(DEBUG) fprintf(stderr,"%d created (%d,%d) mutexes\n",armci_me,num,totcount); return(0); }