/** * Simple constructor */ gridpack::goss::GOSSUtils::GOSSUtils() { p_open = false; #ifndef GOSS_DEBUG p_connection = NULL; p_session = NULL; p_destination = NULL; p_producer = NULL; activemq::library::ActiveMQCPP::initializeLibrary(); #endif p_grp = GA_Pgroup_get_world(); }
int nw_inp_from_string(Integer rtdb, const char *input) { char filename[30]; FILE *file; #if defined(USE_FCD) || defined(CRAY_T3E) || defined(WIN32) _fcd fstring; #else char fstring[255]; #endif int status; const char base[] = "temp"; const char ending[] = ".nw"; int number ; // This is bad, not 100% sure to be unique, since could be subgroup if (GA_Pgroup_get_world() != GA_Pgroup_get_default()) { number = (int) util_sgroup_mygroup_() ; } else { number = 0 ; } sprintf(filename, "%s%d%s", base,number,ending); if (GA_Nodeid() == 0) { if (!(file = fopen(filename,"w"))) { GA_Error("nw_inp_from_string: failed to open temp.nw\n",0); } if (fwrite(input, 1, strlen(input), file) != strlen(input)) { GA_Error("nw_inp_from_string: failed to write to temp.nw\n",0); } if (fwrite("\n", 1, 1, file) != 1) { GA_Error("nw_inp_from_string: failed to write to temp.nw\n",0); } (void) fclose(file); } #if defined(CRAY_T3E) fstring = _cptofcd(filename, strlen(filename)); status = nw_inp_from_file_(&rtdb, fstring); #elif defined(WIN32) fstring.string = filename; fstring.len = strlen(filename); status = nw_inp_from_file_(&rtdb, fstring); #elif defined(USE_FCD) #error Do something about _fcd #else status = nw_inp_from_file_(&rtdb, filename, strlen(filename)); #endif if (GA_Nodeid() == 0) (void) unlink(filename); return status; }
int main(int argc, char **argv) { int me; int nproc; int status; int g_a; int dims[NDIM]; int chunk[NDIM]; int pg_world; size_t num = 10; double *p1 = NULL; double *p2 = NULL; size_t i; int num_mutex; int lo[1]; int hi[1]; int ld[1]={1}; MPI_Comm comm; MP_INIT(argc,argv); GA_INIT(argc,argv); me = GA_Nodeid(); nproc = GA_Nnodes(); comm = GA_MPI_Comm_pgroup_default(); printf("%d: Hello world!\n",me); if (me==0) printf("%d: GA_Initialize\n",me); /*if (me==0) printf("%d: ARMCI_Init\n",me);*/ /*ARMCI_Init();*/ /*if (me==0) printf("%d: MA_Init\n",me);*/ /*MA_init(MT_DBL, 8*1024*1024, 2*1024*1024);*/ if (me==0) printf("%d: GA_Create_handle\n",me); g_a = GA_Create_handle(); if (me==0) printf("%d: GA_Set_array_name\n",me); GA_Set_array_name(g_a,"test array A"); dims[0] = 30; if (me==0) printf("%d: GA_Set_data\n",me); GA_Set_data(g_a,NDIM,dims,MT_DBL); chunk[0] = -1; if (me==0) printf("%d: GA_Set_chunk\n",me); GA_Set_chunk(g_a,chunk); if (me==0) printf("%d: GA_Pgroup_get_world\n",me); pg_world = GA_Pgroup_get_world(); if (me==0) printf("%d: GA_Set_pgroup\n",me); GA_Set_pgroup(g_a,pg_world); if (me==0) printf("%d: GA_Allocate\n",me); status = GA_Allocate(g_a); if(0 == status) MPI_Abort(comm,100); if (me==0) printf("%d: GA_Zero\n",me); GA_Zero(g_a); if (me==0) printf("%d: GA_Sync\n",me); GA_Sync(); num = 10; p1 = malloc(num*sizeof(double)); /*double* p1 = ARMCI_Malloc_local(num*sizeof(double));*/ if (p1==NULL) MPI_Abort(comm,1000); p2 = malloc(num*sizeof(double)); /*double* p2 = ARMCI_Malloc_local(num*sizeof(double));*/ if (p2==NULL) MPI_Abort(comm,2000); for ( i=0 ; i<num ; i++ ) p1[i] = 7.0; for ( i=0 ; i<num ; i++ ) p2[i] = 3.0; num_mutex = 17; status = GA_Create_mutexes(num_mutex); if (me==0) printf("%d: GA_Create_mutexes = %d\n",me,status); /***************************************************************/ if (me==0) { printf("%d: before GA_Lock\n",me); GA_Lock(0); lo[0] = 0; hi[0] = num-1; GA_Init_fence(); NGA_Put(g_a,lo,hi,p1,ld); GA_Fence(); GA_Unlock(0); printf("%d: after GA_Unlock\n",me); } GA_Print(g_a); if (me==1) { printf("%d: before GA_Lock\n",me); GA_Lock(0); lo[0] = 0; hi[0] = num-1; GA_Init_fence(); NGA_Get(g_a,lo,hi,p2,ld); GA_Fence(); GA_Unlock(0); printf("%d: after GA_Unlock\n",me); for ( i=0 ; i<num ; i++ ) printf("p2[%2lu] = %20.10f\n", (long unsigned)i,p2[i]); } /***************************************************************/ status = GA_Destroy_mutexes(); if (me==0) printf("%d: GA_Destroy_mutexes = %d\n",me,status); /*ARMCI_Free(p2);*/ /*ARMCI_Free(p1);*/ free(p2); free(p1); if (me==0) printf("%d: GA_Destroy\n",me); GA_Destroy(g_a); /*if (me==0) printf("%d: ARMCI_Finalize\n",me);*/ /*ARMCI_Finalize();*/ if (me==0) printf("%d: GA_Terminate\n",me); GA_Terminate(); if (me==0) printf("%d: MPI_Finalize\n",me); MPI_Finalize(); return(0); }
int main(int argc, char **argv) { int me; int g_a; int status; int i,j; int dims[] = {n,n}; int proc_group[PROC_LIST_SIZE],proclist[PROC_LIST_SIZE],inode; int sbuf[1],rbuf[1]; MPI_Comm comm; MP_INIT(argc,argv); GA_Initialize(); me = GA_Nodeid(); status = MA_init(MT_DBL, 100000, 100000); if (!status) GA_Error("ma_init failed",-1); status = MA_set_auto_verify(1); status = MA_set_hard_fail(1); status = MA_set_error_print(1); inode = GA_Cluster_nodeid(); if (me == 0) { printf("there are %d nodes, node 0 has %d procs\n", GA_Cluster_nnodes(), GA_Cluster_nprocs(0)); fflush(stdout); } GA_Sync(); for (i=0; i<GA_Cluster_nnodes(); ++i) { for (j=0; j<GA_Cluster_nprocs(i); ++j) { proclist[j]=GA_Cluster_procid(i,j); } proc_group[i]=GA_Pgroup_create(proclist,GA_Cluster_nprocs(i)); } GA_Sync(); for (i=0; i<GA_Cluster_nnodes(); ++i) { if (i == inode) { printf("%d joining group %d\n", me, proc_group[inode]); GA_Pgroup_set_default(proc_group[inode]); g_a = NGA_Create(C_DBL, 2, dims, "a", NULL); if (!g_a) GA_Error("NGA_Create failed",-1); printf("%d Created array of group %d as proc no. %d\n", me, proc_group[inode], GA_Nodeid()); GA_Print_distribution(g_a); comm = GA_MPI_Comm_pgroup_default(); if (comm != MPI_COMM_NULL) { sbuf[0] = GA_Nodeid(); status = MPI_Allreduce(sbuf, rbuf, 1, MPI_INT, MPI_MAX, comm); printf("%d max nodeid is %d\n", me, rbuf[0]); if ((rbuf[0]+1) != GA_Cluster_nprocs(i)) { GA_Error("MPI_Allreduce failed",1); } } else { printf("MPI_Comm was null!\n"); } GA_Pgroup_set_default(GA_Pgroup_get_world()); } GA_Sync(); } GA_Terminate(); MP_FINALIZE(); return 0; }
/** Client code. Receives signals from the server to process a task or terminate processing and return*/ void client_code() { int *buf = NULL, buf_size; int flag; MPI_Status status; Integer p_handle; int ntsks=0, src; const char *pname = "client_code"; double e1, e2, e3, e4, e5, f1, f2, f3, f4,f5,f6,f7,f8; double t_prepar=0, t_wait_start=0, t_grp=0,t_sync=0,t_compl=0,t_dest=0; /* double get_doit_time_(); */ /* double get_esp_time_(); */ /* double get_gm_crt_time_(); */ /* double get_chrg_set_time_(); */ /* double get_gm_push_time_(); */ const int server = GA_Pgroup_absolute_id(ga_pgroup_get_default_(),SVR); const int default_grp = ga_pgroup_get_default_();; /*default GA group for this dispatcher instance*/ const int world_me = GA_Nodeid(); const int nproc = GA_Nnodes(); t_ptask = 0.0; /* fprintf(stderr, "%d: 0 server=%d %s\n", GA_Nodeid(), server,pname); */ e1 = util_wallsec_(); /* fprintf(stderr, "%d: 0 %s\n", GA_Nodeid(), pname); */ /* GA_Pgroup_set_default(GA_Pgroup_get_world()); */ /* fprintf(stderr, "%d: 1 %s\n", world_me, pname); */ buf_size = 1+ /*action to perform*/ 1+ /*task id - if TASK_SIGNAL*/ nproc /*process group info*/ ; /* buf = (int *)malloc(buf_size*sizeof(int)); */ buf = (int *)alloca(buf_size*sizeof(int)); assert(buf != NULL); /* fprintf(stderr, "%d: 2 %s\n", world_me, pname); */ e2 = util_wallsec_(); while(1) { int nelem, grp_me; Integer tskid; f1 = util_wallsec_(); /* fprintf(stderr, "%d:: Waiting for work\n", world_me); */ MPI_Recv(buf, buf_size, MPI_INT, MPI_ANY_SOURCE, SIGNAL_TAG, MPI_COMM_WORLD, &status); f2 = util_wallsec_(); t_wait_start += (f2-f1); /* fprintf(stderr, "%d:: Client got msg from %d\n", world_me, status.MPI_SOURCE); */ MPI_Get_elements(&status, MPI_INT, &nelem); assert(nelem >= 1); if(buf[0] == TERM_CLIENT) { /*process termination and return*/ /* fprintf(stderr, "%d:: Recv-ed term signal\n", GA_Nodeid()); */ /* free(buf); */ /* fprintf(stderr, "%d:: Terminating client\n", GA_Nodeid()); */ #ifdef LEADER_BCAST signal_termination(SVR,status.MPI_SOURCE); #endif break; } /* fprintf(stderr, "%d:: got a task to process\n", world_me); */ /*Got a task to process*/ assert(buf[0] == TASK_START); ntsks += 1; if(status.MPI_SOURCE == server) { qsort(buf+2, nelem-2, sizeof(int), int_compare); } f3 = util_wallsec_(); t_prepar += (f3-f2); #if LEADER_BCAST src = (server==status.MPI_SOURCE)?buf[2]:status.MPI_SOURCE; broadcast(nelem-2,buf+2,buf[2],src,buf,nelem*sizeof(int)); #endif /*The proc ids are in world group. So create sub-group of world group*/ GA_Pgroup_set_default(GA_Pgroup_get_world()); p_handle = GA_Pgroup_create(&buf[2], nelem-2); GA_Pgroup_set_default(p_handle); /* GA_Pgroup_sync(p_handle); */ f4 = MPI_Wtime(); t_grp += (f4-f3); tskid = buf[1]; /* fprintf(stderr, "%d(%d):: Invoking process task tskid=%d\n", grp_me, world_me, tskid); */ process_task_(&tskid, &p_handle); f5 = MPI_Wtime(); t_ptask += (f5-f4); GA_Pgroup_sync(p_handle); grp_me = GA_Nodeid(); f6 = util_wallsec_(); t_sync += (f6-f5); if(grp_me == 0) { int v[2] = {TASK_DONE, tskid}; /* fprintf(stderr, "%d(%d):: Sending ack for task %d to %d\n", */ /* grp_me, world_me, tskid, SERVER); */ MPI_Send(v, 2, MPI_INT, server, SIGNAL_TAG, MPI_COMM_WORLD); } f7 = util_wallsec_(); t_compl += (f7-f6); /* GA_Pgroup_sync(p_handle); */ GA_Pgroup_destroy(p_handle); GA_Pgroup_set_default(default_grp); f8 = util_wallsec_(); t_dest += (f8-f7); } e3 = util_wallsec_(); /* fprintf(stderr, "%d:: CLIENT total time=%lf\n", ga_nodeid_(), e3-e1); */ /* fprintf(stderr, "%d:: CLIENT ntsks=%d\n", ga_nodeid_(), ntsks); */ /* fprintf(stderr, "%d:: CLIENT loop time=%lf\n", ga_nodeid_(), e3-e2); */ /* fprintf(stderr, "%d:: CLIENT wait start time=%lf\n", ga_nodeid_(),t_wait_start); */ /* fprintf(stderr, "%d:: CLIENT prepare time=%lf\n", ga_nodeid_(),t_prepar); */ /* fprintf(stderr, "%d:: CLIENT grp crt time=%lf\n", ga_nodeid_(), t_grp); */ /* fprintf(stderr, "%d:: CLIENT ptask time=%lf\n", ga_nodeid_(), t_ptask); */ /* fprintf(stderr, "%d:: CLIENT sync time=%lf\n", ga_nodeid_(), t_sync); */ /* fprintf(stderr, "%d:: CLIENT compl time=%lf\n", ga_nodeid_(), t_compl); */ /* fprintf(stderr, "%d:: CLIENT grp dstry time=%lf\n", ga_nodeid_(), t_dest); */ /* fflush(stdout); */ /* fprintf(stderr, "%d:: CLIENT doit time=%lf\n",ga_nodeid_(),get_doit_time_()); */ /* fprintf(stderr, "%d:: CLIENT esp time=%lf\n",ga_nodeid_(),get_esp_time_()); */ /* fprintf(stderr, "%d:: CLIENT chrg_set time=%lf\n",ga_nodeid_(),get_chrg_set_time_()); */ /* fprintf(stderr, "%d:: CLIENT gm_crt time=%lf\n",ga_nodeid_(),get_gm_crt_time_()); */ /* fprintf(stderr, "%d:: CLIENT gm_push time=%lf\n",ga_nodeid_(),get_gm_push_time_()); */ }