void BBSDirectServer::context(int ncids, int* cids) { #if defined(HAVE_STL) int cid, j; //printf("ncids=%d\n", ncids); if (remaining_context_cnt_ > 0) { printf("some workers did not receive previous context\n"); // send_context_->clear(); send_context_->erase(send_context_->begin(), send_context_->end()); pvm_freebuf(context_buf_); } remaining_context_cnt_ = ncids; for (j = 0; j < ncids; ++j) { send_context_->insert(cids[j]); } LookingToDoList::iterator i = looking_todo_->begin(); while (i != looking_todo_->end()) { cid = (*i); looking_todo_->erase(i); //printf("sending context to already waiting %x\n", cid); pvm_send(cid, CONTEXT+1); --ncids; i = send_context_->find(cid); send_context_->erase(i); --remaining_context_cnt_; i = looking_todo_->begin(); } if (remaining_context_cnt_ > 0) { context_buf_ = pvm_setsbuf(pvm_mkbuf(PvmDataDefault)); }else{ pvm_freebuf(pvm_setsbuf(pvm_mkbuf(PvmDataDefault))); } #endif }
int main(int argc, char** argv) { const int minp = 2 ; const int dinp = 0 ; strcpy(myname, name) ; if( minp ) { std::map<int, std::vector<int> > tagbufs ; while(1) { std::vector<int> inputs = get_inputs(minp, dinp, tagbufs) ; //input0 int inp0 ; int inp0buf = inputs[0] ; pvm_setrbuf(inp0buf) ; pvm_upkint(&inp0, 1 ,1 ) ; pvm_freebuf(inp0buf) ; //input1 int inp1 ; int inp1buf = inputs[1] ; pvm_setrbuf(inp1buf) ; pvm_upkint(&inp1, 1 ,1 ) ; pvm_freebuf(inp1buf) ; get_mul(inp0, inp1) ; } } return 0 ; }
void send_kill(int tid) { int bufid; bufid = pvm_initsend(PvmDataDefault); pvm_send(tid,2); pvm_freebuf(bufid); }
value Pvm_freebuf(value bufid) { int res = pvm_freebuf(Int_val(bufid)); if (res<0) TreatError(res); return; }
void send_tour(_node *tour, int cost, int numroutes, int algorithm, double cpu_time, int parent, int vertnum, int routes, route_data *route_info) { int s_bufid, info; PVM_FUNC(s_bufid, pvm_initsend(PvmDataRaw)); PVM_FUNC(info, pvm_pkbyte((char *)tour, (vertnum)*sizeof(_node), 1)); PVM_FUNC(info, pvm_pkint(&cost, 1, 1)); PVM_FUNC(info, pvm_pkint(&numroutes, 1, 1)); PVM_FUNC(info, pvm_pkint(&algorithm, 1, 1)); PVM_FUNC(info, pvm_pkdouble(&cpu_time, 1, 1)); if (routes){ PVM_FUNC(info, pvm_pkbyte((char *)route_info, (numroutes+1)*sizeof(route_data), 1)); PVM_FUNC(info, pvm_send(parent, HEUR_TOUR_WITH_ROUTES)); printf("\nSent HEUR_TOUR_WITH_ROUTES\n\n"); } else{ PVM_FUNC(info, pvm_send(parent, HEUR_TOUR)); printf("\nSent HEUR_TOUR\n\n"); } PVM_FUNC(info, pvm_freebuf(s_bufid)); return; }
int receive(heur_prob *p) { int r_bufid, info, bytes, msgtag, parent; PVM_FUNC(r_bufid, pvm_recv(-1, VRP_BROADCAST_DATA)); PVM_FUNC(info, pvm_bufinfo(r_bufid, &bytes, &msgtag, &parent)); PVM_FUNC(info, pvm_upkint(&(p->dist.wtype), 1, 1)); PVM_FUNC(info, pvm_upkint(&(p->vertnum), 1, 1)); PVM_FUNC(info, pvm_upkint(&(p->depot), 1, 1)); PVM_FUNC(info, pvm_upkint(&p->capacity, 1, 1)); p->demand = (int *) calloc (p->vertnum, sizeof(int)); PVM_FUNC(info, pvm_upkint(p->demand, p->vertnum, 1)); p->edgenum = p->vertnum*(p->vertnum-1)/2; if (p->dist.wtype){ /* not EXPLICIT */ p->dist.coordx = (double *) calloc(p->vertnum, sizeof(double)); p->dist.coordy = (double *) calloc(p->vertnum, sizeof(double)); PVM_FUNC(info, pvm_upkdouble(p->dist.coordx, p->vertnum, 1)); PVM_FUNC(info, pvm_upkdouble(p->dist.coordy, p->vertnum, 1)); if ((p->dist.wtype == _EUC_3D) || (p->dist.wtype == _MAX_3D) || (p->dist.wtype == _MAN_3D)){ p->dist.coordz = (double *) calloc(p->vertnum, sizeof(double)); PVM_FUNC(info, pvm_upkdouble(p->dist.coordz, p->vertnum, 1)); } } else{ /* EXPLICIT */ p->dist.cost = (int *) malloc (p->edgenum*sizeof(int)); PVM_FUNC(info, pvm_upkint(p->dist.cost, (int)p->edgenum, 1)); } PVM_FUNC(info, pvm_freebuf(r_bufid)); return(parent); }
int main(int argc, char** argv) { const int minp = 1 ; const int dinp = 0 ; strcpy(myname, name) ; mytid = pvm_mytid() ; printf("[gen_x_copy]: hello!\n") ; //просто запускаем функцию и выходим. if( minp ) { std::map<int, std::vector<int> > tagbufs ; while(1) { printf("[gen_x_copy]:waiting for inputs\n") ; std::vector<int> inputs = get_inputs(minp, dinp, tagbufs) ; printf("[gen_x_copy]:inputs are receiving\n") ; int inp0 ; int inp0buf = inputs[0] ; printf("[gen_x_copy]:inp0buf=%d\n", inp0buf) ; pvm_setrbuf(inp0buf) ; pvm_upkint(&inp0, 1 ,1 ) ; printf("[gen_x_copy]:after unpack inp0=%d\n", inp0) ; gen_x(inp0) ; pvm_freebuf(inp0buf) ; } } return 0 ; }
int freebuf(int bufid) { int info; PVM_FUNC(info, pvm_freebuf(bufid)); return(info); }
int receive_assign(tassign *assign) { int bufid, tag, dummy, datasize, i, toint[ASSIGN_NINT]; double *tdbl, todbl[ASSIGN_NDBL]; float *tflt; bufid = pvm_recv(-1,-1); pvm_bufinfo(bufid,&dummy,&tag,&dummy); if (tag == 2) return 0; pvm_upkint(toint,ASSIGN_NINT,1); pvm_upkdouble(todbl,ASSIGN_NDBL,1); assign->id = (integer)toint[ASSIGN_ID]; assign->chans = (integer)toint[ASSIGN_CHANS]; assign->frames = (integer)toint[ASSIGN_FRAMES]; assign->epochs = (integer)toint[ASSIGN_EPOCHS]; assign->bias = (integer)toint[ASSIGN_BIAS]; assign->signs = (integer)toint[ASSIGN_SIGNS]; assign->extended = (integer)toint[ASSIGN_EXTENDED]; assign->extblocks = (integer)toint[ASSIGN_EXTBLOCKS]; assign->pdfsize = (integer)toint[ASSIGN_PDFSIZE]; assign->nsub = (integer)toint[ASSIGN_NSUB]; assign->verbose = (integer)toint[ASSIGN_VERBOSE]; assign->block = (integer)toint[ASSIGN_BLOCK]; assign->maxsteps = (integer)toint[ASSIGN_MAXSTEPS]; assign->lrate = (doublereal)todbl[ASSIGN_LRATE]; assign->annealstep = (doublereal)todbl[ASSIGN_ANNEALSTEP]; assign->annealdeg = (doublereal)todbl[ASSIGN_ANNEALDEG]; assign->nochange = (doublereal)todbl[ASSIGN_NOCHANGE]; assign->momentum = (doublereal)todbl[ASSIGN_MOMENTUM]; datasize = assign->chans * assign->frames * assign->epochs; assign->data = (doublereal*)malloc(datasize*sizeof(doublereal)); if (sizeof(float) != sizeof(doublereal)) { tflt = (float*)malloc(datasize*sizeof(float)); pvm_upkfloat(tflt,datasize,1); for (i=0 ; i<datasize ; i++) assign->data[i] = (doublereal)tflt[i]; free(tflt); } else pvm_upkfloat((float*)(assign->data),datasize,1); datasize = assign->chans * assign->chans; assign->weights = (doublereal*)malloc(datasize*sizeof(doublereal)); if (sizeof(double) != sizeof(doublereal)) { tdbl = (double*)malloc(datasize*sizeof(double)); pvm_upkdouble(tdbl,datasize,1); for (i=0 ; i<datasize ; i++) assign->weights[i] = (doublereal)tdbl[i]; free(tdbl); } else pvm_upkdouble((double*)(assign->weights),datasize,1); pvm_freebuf(bufid); return 1; }
void BBSDirect::return_args(int userid) { #if defined(HAVE_STL) KeepArgs::iterator i = keepargs_->find(userid); if (i != keepargs_->end()) { int bufid = (*i).second; keepargs_->erase(i); pvm_freebuf(pvm_setrbuf(bufid)); BBSImpl::return_args(userid); } #endif }
void send_result(int tid, tresult *result) { int *tint, bufid, datasize, i, toint[RESULT_NINT]; double *tdbl, todbl[RESULT_NDBL]; toint[RESULT_ID] = (int)(result->id); toint[RESULT_CHANS] = (int)(result->chans); toint[RESULT_BIAS] = (int)(result->bias != NULL); toint[RESULT_SIGNS] = (int)(result->signs != NULL); todbl[RESULT_LRATE] = (double)(result->lrate); bufid = pvm_initsend(PvmDataDefault); pvm_pkint(toint,RESULT_NINT,1); pvm_pkdouble(todbl,RESULT_NDBL,1); datasize = result->chans * result->chans; if (sizeof(double) != sizeof(doublereal)) { tdbl = (double*)malloc(datasize*sizeof(double)); for (i=0 ; i<datasize ; i++) tdbl[i] = (double)(result->weights[i]); pvm_pkdouble(tdbl,datasize,1); free(tdbl); } else pvm_pkdouble((double*)(result->weights),datasize,1); if (result->bias != NULL) { datasize = result->chans; if (sizeof(double) != sizeof(doublereal)) { tdbl = (double*)malloc(datasize*sizeof(double)); for (i=0 ; i<datasize ; i++) tdbl[i] = (double)(result->bias[i]); pvm_pkdouble(tdbl,datasize,1); free(tdbl); } else pvm_pkdouble((double*)(result->bias),datasize,1); } if (result->signs != NULL) { datasize = result->chans; if (sizeof(int) != sizeof(integer)) { tint = (int*)malloc(datasize*sizeof(int)); for (i=0 ; i<datasize ; i++) tint[i] = (int)(result->signs[i]); pvm_pkint(tint,datasize,1); free(tint); } else pvm_pkint((int*)(result->signs),datasize,1); } pvm_send(tid,1); pvm_freebuf(bufid); }
void send_assign(int tid, tassign *assign) { int bufid, datasize, i, toint[ASSIGN_NINT]; double *tdbl, todbl[ASSIGN_NDBL]; float *tflt; toint[ASSIGN_ID] = (int)(assign->id); toint[ASSIGN_CHANS] = (int)(assign->chans); toint[ASSIGN_FRAMES] = (int)(assign->frames); toint[ASSIGN_EPOCHS] = (int)(assign->epochs); toint[ASSIGN_BIAS] = (int)(assign->bias); toint[ASSIGN_SIGNS] = (int)(assign->signs); toint[ASSIGN_EXTENDED] = (int)(assign->extended); toint[ASSIGN_EXTBLOCKS] = (int)(assign->extblocks); toint[ASSIGN_PDFSIZE] = (int)(assign->pdfsize); toint[ASSIGN_NSUB] = (int)(assign->nsub); toint[ASSIGN_VERBOSE] = (int)(assign->verbose); toint[ASSIGN_BLOCK] = (int)(assign->block); toint[ASSIGN_MAXSTEPS] = (int)(assign->maxsteps); todbl[ASSIGN_LRATE] = (double)(assign->lrate); todbl[ASSIGN_ANNEALSTEP] = (double)(assign->annealstep); todbl[ASSIGN_ANNEALDEG] = (double)(assign->annealdeg); todbl[ASSIGN_NOCHANGE] = (double)(assign->nochange); todbl[ASSIGN_MOMENTUM] = (double)(assign->momentum); bufid = pvm_initsend(PvmDataDefault); pvm_pkint(toint,ASSIGN_NINT,1); pvm_pkdouble(todbl,ASSIGN_NDBL,1); datasize = assign->chans * assign->frames * assign->epochs; if (sizeof(float) != sizeof(doublereal)) { tflt = (float*)malloc(datasize*sizeof(float)); for (i=0 ; i<datasize ; i++) tflt[i] = (float)(assign->data[i]); pvm_pkfloat(tflt,datasize,1); free(tflt); } else pvm_pkfloat((float*)(assign->data),datasize,1); datasize = assign->chans * assign->chans; if (sizeof(double) != sizeof(doublereal)) { tdbl = (double*)malloc(datasize*sizeof(double)); for (i=0 ; i<datasize ; i++) tdbl[i] = (double)(assign->weights[i]); pvm_pkdouble(tdbl,datasize,1); free(tdbl); } else pvm_pkdouble((double*)(assign->weights),datasize,1); pvm_send(tid,1); pvm_freebuf(bufid); }
void BBSDirectServer::post(const char* key) { #if defined(HAVE_STL) int cid; int bufid = pvm_getsbuf(); // printf("DirectServer::post |%s| bufid=%d\n", key, bufid); if (take_pending(key, &cid)) { pvm_send(cid, TAKE); pvm_freebuf(bufid); }else{ MessageList::iterator m = messages_->insert( pair<const char* const, const int>(newstr(key), bufid) ); } pvm_setsbuf(pvm_mkbuf(PvmDataDefault)); #endif }
bool BBSDirectServer::send_context(int cid) { #if defined(HAVE_STL) LookingToDoList::iterator i = send_context_->find(cid); if (i != send_context_->end()) { send_context_->erase(i); int oldbuf = pvm_setsbuf(context_buf_); //printf("sending context to %x\n", cid); pvm_send(cid, CONTEXT+1); pvm_setsbuf(oldbuf); if(--remaining_context_cnt_ <= 0) { pvm_freebuf(context_buf_); } return true; } #endif return false; }
bool BBSDirectServer::look(const char* key) { bool b = false; #if defined(HAVE_STL) MessageList::iterator m = messages_->find(key); if (m != messages_->end()) { b = true; int buf = (*m).second; pvm_initsend(PvmDataDefault); pvm_pkmesgbody(buf); buf = pvm_getrbuf(); pvm_setrbuf(pvm_setsbuf(pvm_mkbuf(PvmDataDefault))); pvm_freebuf(buf); } // printf("DirectServer::look %d |%s|\n", b, key); #endif return b; }
int BBSDirectServer::look_take_todo() { #if defined(HAVE_STL) ReadyList::iterator i = todo_->begin(); if (i != todo_->end()) { WorkItem* w = (WorkItem*)(*i); todo_->erase(i); int oldbuf = pvm_setrbuf(w->bufid_); pvm_freebuf(oldbuf); w->bufid_ = 0; return w->id_; }else{ return 0; } #else return 0; #endif }
void BBSClient::post_result(int id) { #if debug printf("BBSClient::post_result %d\n", id); fflush(stdout); #endif int index, os; os = pvm_setsbuf(pvm_mkbuf(PvmDataDefault)); pvm_pkint(&id, 1, 1); #if defined(HAVE_PKMESG) pvm_pkmesg(os); index = pvm_send(sid_, POST_RESULT); #else pvm_send(sid_, CRAY_POST_RESULT); os = pvm_setsbuf(os); index = pvm_send(sid_, CRAY_POST_RESULT); #endif pvm_freebuf(os); if (index < 0) {perror("post_result");} }
int pvm_initsend(int encoding) { int newbufid; #ifdef PVM_DEBUG PRINTF("Pe(%d) tid=%d:pvm_initsend(%d)\n",MYPE(),pvm_mytid(),encoding); #endif if (CpvAccess(pvmc_sbufid) > 0) pvm_freebuf(CpvAccess(pvmc_sbufid)); newbufid=pvm_mkbuf(encoding); if (newbufid<=0) { PRINTF("Pe(%d) tid=%d:%s:%d pvm_initsend() couldn't alloc new buffer\n", MYPE(),pvm_mytid(),__FILE__,__LINE__); } CpvAccess(pvmc_sbufid)=newbufid; return CpvAccess(pvmc_sbufid); }
void BBSClient::post(const char* key) { #if debug printf("BBSClient::post |%s|\n", key); fflush(stdout); #endif int index, os; os = pvm_setsbuf(pvm_mkbuf(PvmDataDefault)); pvm_pkstr((char*)key); #if defined(HAVE_PKMESG) pvm_pkmesg(os); index = pvm_send(sid_, POST); #else pvm_send(sid_, CRAY_POST); os = pvm_setsbuf(os); index = pvm_send(sid_, CRAY_POST); #endif pvm_freebuf(os); if (index < 0) {perror("post");} }
int BBSDirectServer::look_take_result(int pid) { #if defined(HAVE_STL) ResultList::iterator i = results_->find(pid); if (i != results_->end()) { WorkItem* w = (WorkItem*)((*i).second); results_->erase(i); int oldbuf = pvm_setrbuf(w->bufid_); pvm_freebuf(oldbuf); int id = w->id_; WorkList::iterator j = work_->find(id); work_->erase(j); delete w; return id; }else{ return 0; } #else return 0; #endif }
void BBSDirectServer::post_todo(int pid, int cid){ #if defined(HAVE_STL) int bufid = pvm_getsbuf(); WorkItem* w = new WorkItem(next_id_++, bufid, cid); WorkList::iterator p = work_->find(pid); if (p != work_->end()) { w->parent_ = (WorkItem*)((*p).second); } work_->insert(pair<const int, const WorkItem*>(w->id_, w)); LookingToDoList::iterator i = looking_todo_->begin(); if (i != looking_todo_->end()) { cid = (*i); looking_todo_->erase(i); // the send buffer is correct pvm_send(cid, w->id_ + 1); w->bufid_ = 0; pvm_freebuf(pvm_getsbuf()); }else{ todo_->insert(w); } pvm_setsbuf(pvm_mkbuf(PvmDataDefault)); #endif }
bool BBSDirectServer::look_take(const char* key) { bool b = false; #if defined(HAVE_STL) MessageList::iterator m = messages_->find(key); if (m != messages_->end()) { b = true; int buf = (*m).second; buf = pvm_setrbuf(buf); //printf("free %d\n", buf); pvm_freebuf(buf); char* s = (char*)((*m).first); messages_->erase(m); delete [] s; } #if debug if (b) { printf("DirectServer::look_take |%s| %d\n", key, pvm_getrbuf()); }else{ printf("DirectServer::look_take |%s| fail\n", key); } #endif #endif return b; }
int receive_result(tresult *result) { int *tint, bufid, datasize, bias, signs, toint[RESULT_NINT]; int i, buflen, tag, tid; double *tdbl, todbl[RESULT_NDBL]; bufid = pvm_recv(-1,-1); pvm_upkint(toint,RESULT_NINT,1); pvm_upkdouble(todbl,RESULT_NDBL,1); result->id = (integer)toint[RESULT_ID]; result->chans = (integer)toint[RESULT_CHANS]; bias = (integer)toint[RESULT_BIAS]; signs = (integer)toint[RESULT_SIGNS]; result->lrate = (doublereal)todbl[RESULT_LRATE]; datasize = result->chans * result->chans; result->weights = (doublereal*)malloc(datasize*sizeof(doublereal)); if (sizeof(double) != sizeof(doublereal)) { tdbl = (double*)malloc(datasize*sizeof(double)); pvm_upkdouble(tdbl,datasize,1); for (i=0 ; i<datasize ; i++) result->weights[i] = (doublereal)tdbl[i]; free(tdbl); } else pvm_upkdouble((double*)(result->weights),datasize,1); if (bias) { datasize = result->chans; result->bias = (doublereal*)malloc(datasize*sizeof(doublereal)); if (sizeof(double) != sizeof(doublereal)) { tdbl = (double*)malloc(datasize*sizeof(double)); pvm_upkdouble(tdbl,datasize,1); for (i=0 ; i<datasize ; i++) result->bias[i] = (doublereal)tdbl[i]; free(tdbl); } else pvm_upkdouble((double*)(result->bias),datasize,1); } else result->bias = NULL; if (signs) { datasize = result->chans; result->signs = (integer*)malloc(datasize*sizeof(integer)); if (sizeof(int) != sizeof(integer)) { tint = (int*)malloc(datasize*sizeof(int)); pvm_upkint(tint,datasize,1); for (i=0 ; i<datasize ; i++) result->signs[i] = (integer)tint[i]; free(tint); } else pvm_upkint((int*)(result->signs),datasize,1); } else result->signs = NULL; pvm_bufinfo(bufid,&buflen,&tag,&tid); pvm_freebuf(bufid); return tid; }
int main (int argc, char **argv) { int nt; /* number of time samples */ int nz; /* number of migrated depth samples */ int nx,nxshot; /* number of midpoints,shotgathers, the folds in a shot gather */ int flag=1; /*flag to use ft or meter as the unit*/ int dip=65; /*maximum dip angle to migrate*/ int iz,iw,ix,it,oldsx; /* loop counters*/ int ntfft; /* fft size*/ int nw; /* number of wave numbers */ int mytid,tids[NNTASKS],msgtype,rc,i;/*variable for PVM function*/ int nw1,task; int lpad=9999,rpad=9999; /*zero-traces padded on left and right sides*/ float f1,f2,f3,f4; /*frequencies to build the Hamming window*/ int nf1,nf2,nf3,nf4; /*the index for above frequencies*/ int NTASKS=0; /*number of slave tasks to start*/ char cpu_name[NNTASKS][80]; /*strings to store the computers' name*/ int flag_cpu=0; /*flag to control if using NTASKS variable*/ float sx,gxmin,gxmax; /*location of geophone and receivers*/ int isx,nxo,ifx=0; /*index for geophone and receivers*/ int ix1,ix2,ix3,il,ir; /*dummy index*/ float *wl,*wtmp; /*pointers for the souce function*/ float Fmax=25; /*peak frequency to make the Ricker wavelet*/ int ntw,truenw; /*number of frequencies to be migrated*/ float dt=0.004,dz; /*time, depth sampling interval*/ float ft; /*first time sample*/ float dw; /*frequency sampling interval*/ float fw; /*first frequency*/ float dx; /*spatial sampling interval*/ float **p,**cresult,**result_tmp; /* input, output data*/ float **v; /*double pointer direct to velocity structure*/ complex *wlsp,**cp,**cq,**cq1; /*pointers for internal usage*/ char *vfile=""; /* name of file containing velocities */ char *cpufile=""; /* name of file containing CPU name */ FILE *vfp,*cpu_fp; /* hook up getpar to handle the parameters */ initargs(argc,argv); requestdoc(1); /* get optional parameters */ if (!getparfloat("ft",&ft)) ft = 0.0; if (!getparint("nz",&nz)) err("nz must be specified"); if (!getparfloat("dz",&dz)) err("dz must be specified"); if (!getparstring("vfile", &vfile)) err("vfile must be specified"); if (!getparint("nxo",&nxo)) err("nxo must be specified"); if (!getparint("nxshot",&nxshot)) err("nshot must be specified"); if (!getparfloat("Fmax",&Fmax)) err("Fmax must be specified"); if (!getparfloat("f1",&f1)) f1 = 10.0; if (!getparfloat("f2",&f2)) f2 = 20.0; if (!getparfloat("f3",&f3)) f3 = 40.0; if (!getparfloat("f4",&f4)) f4 = 50.0; if (!getparint("lpad",&lpad)) lpad=9999; if (!getparint("rpad",&rpad)) rpad=9999; if (!getparint("flag",&flag)) flag=1; if (!getparint("dip",&dip)) dip=65; if (getparstring("cpufile", &cpufile)){ cpu_fp=fopen(cpufile,"r"); NTASKS=0; while(!feof(cpu_fp)){ fscanf(cpu_fp,"%s",cpu_name[NTASKS]); NTASKS++; } NTASKS-=1; flag_cpu=1; } else /*if cpufile not specified, the use NTASKS*/ if (!getparint("NTASKS",&NTASKS)) err("No CPUfile specified, NTASKS must be specified"); /*allocate space for the velocity profile*/ tshot=nxshot; v=alloc2float(nxo,nz); /*load velicoty file*/ vfp=efopen(vfile,"r"); efread(v[0],FSIZE,nz*nxo,vfp); efclose(vfp); /*PVM communication starts here*/ mytid=pvm_mytid(); /*get my pid*/ task=NTASKS; warn("\n %d",task); rc=0; /*spawn slave processes here*/ if(!flag_cpu){ rc=pvm_spawn(child,NULL,PvmTaskDefault,"",task,tids); } else{ for(i=0;i<NTASKS;i++){ rc+=pvm_spawn(child,NULL,PvmTaskHost,cpu_name[i],1,&tids[i]); } } /*show the pid of slaves if*/ for(i=0;i<NTASKS;i++){ if(tids[i]<0)warn("\n %d",tids[i]); else warn("\nt%x\t",tids[i]); } /*if not all the slaves start, then quit*/ if(rc<NTASKS){ warn("error");pvm_exit();exit(1);} /*broadcast the global parameters nxo,nz,dip to all slaves*/ pvm_initsend(PvmDataDefault); rc=pvm_pkint(&nxo,1,1); rc=pvm_pkint(&nz,1,1); rc=pvm_pkint(&dip,1,1); msgtype=PARA_MSGTYPE; task=NTASKS; rc=pvm_mcast(tids,task,msgtype); /*broadcast the velocity profile to all slaves*/ pvm_initsend(PvmDataDefault); rc=pvm_pkfloat(v[0],nxo*nz,1); msgtype=VEL_MSGTYPE; rc=pvm_mcast(tids,task,msgtype); /*free the space for velocity profile*/ free2float(v); /*loop over shot gathers begin here*/ loop: /* get info from first trace */ if (!gettr(&tr)) err("can't get first trace"); nt = tr.ns; /* let user give dt and/or dx from command line */ if (!getparfloat("dt", &dt)) { if (tr.dt) { /* is dt field set? */ dt = ((double) tr.dt)/1000000.0; } else { /* dt not set, assume 4 ms */ dt = 0.004; warn("tr.dt not set, assuming dt=0.004"); } } if (!getparfloat("dx",&dx)) { if (tr.d2) { /* is d2 field set? */ dx = tr.d2; } else { dx = 1.0; warn("tr.d2 not set, assuming d2=1.0"); } } sx=tr.sx; isx=sx/dx; gxmin=gxmax=tr.gx; oldsx=sx; /* determine frequency sampling interval*/ ntfft = npfar(nt); nw = ntfft/2+1; dw = 2.0*PI/(ntfft*dt); /*compute the index of the frequency to be migrated*/ fw=2.0*PI*f1; nf1=fw/dw+0.5; fw=2.0*PI*f2; nf2=fw/dw+0.5; fw=2.0*PI*f3; nf3=fw/dw+0.5; fw=2.0*PI*f4; nf4=fw/dw+0.5; /*the number of frequency to migrated*/ truenw=nf4-nf1+1; fw=0.0+nf1*dw; warn("nf1=%d nf2=%d nf3=%d nf4=%d nw=%d",nf1,nf2,nf3,nf4,truenw); fw=0.0; /* allocate space */ wl=alloc1float(ntfft); wlsp=alloc1complex(nw); /*generate the Ricker wavelet*/ wtmp=ricker(Fmax,dt,&ntw); for(it=0;it<ntfft;it++) wl[it]=0.0; for(it=0;it<ntw-12;it++) wl[it]=wtmp[it+12]; free1float( wtmp); /*Fourier transform the Ricker wavelet to frequency domain*/ pfarc(-1,ntfft,wl,wlsp); /* allocate space */ p = alloc2float(ntfft,nxo); cp = alloc2complex(nw,nxo); for (ix=0; ix<nxo; ix++) for (it=0; it<ntfft; it++) p[ix][it] = 0.0; /*read in a single shot gather*/ ix=tr.gx/dx; memcpy( (void *) p[ix], (const void *) tr.data,nt*FSIZE); nx = 0; while(gettr(&tr)){ int igx; if(tr.sx!=oldsx){ fseek(stdin,(long)(-240-nt*4),SEEK_CUR); break;} igx=tr.gx/dx; memcpy( (void *) p[igx], (const void *) tr.data,nt*FSIZE); if(gxmin>tr.gx)gxmin=tr.gx; if(gxmax<tr.gx)gxmax=tr.gx; nx++; oldsx=tr.sx; } warn("\nnx= %d",nx); warn("sx %f , gxmin %f gxmax %f",sx,gxmin,gxmax); /*transform the shot gather from time to frequency domain*/ pfa2rc(1,1,ntfft,nxo,p[0],cp[0]); /*compute the most left and right index for the migrated section*/ ix1=sx/dx; ix2=gxmin/dx; ix3=gxmax/dx; if(ix1>=ix3)ix3=ix1; if(ix1<=ix2)ix2=ix1; il=ix2; ir=ix3; ix2-=lpad; ix3+=rpad; if(ix2<0)ix2=0; if(ix3>nxo-1)ix3=nxo-1; /*the total traces to be migrated*/ nx=ix3-ix2+1; /*allocate space*/ cq = alloc2complex(nx,nw); cq1 = alloc2complex(nx,nw); /*transpose the frequency domain data from data[ix][iw] to data[iw][ix] and apply a Hamming at the same time*/ for (ix=0; ix<nx; ix++) for (iw=0; iw<nw; iw++){ float tmpp=0.0,tmppp=0.0; if(iw<nf1||iw>nf4) cq[iw][ix]=cmplx(0.0,0.0); else{ if(iw>=nf1&&iw<=nf2){tmpp=PI/(nf2-nf1);tmppp=tmpp*(iw-nf1)-PI;tmpp=0.54+0.46*cos(tmppp); cq[iw][ix]=crmul(cp[ix+ix2][iw],tmpp);} else{ if(iw>=nf3&&iw<=nf4){tmpp=PI/(nf4-nf3);tmppp=tmpp*(iw-nf3);tmpp=0.54+0.46*cos(tmppp); cq[iw][ix]=crmul(cp[ix+ix2][iw],tmpp);} else {cq[iw][ix]=cp[ix+ix2][iw];} } } cq[iw][ix]=cp[ix+ix2][iw]; cq1[iw][ix]=cmplx(0.0,0.0); } ix=sx/dx-ifx; warn("ix %d",ix); for(iw=0;iw<nw;iw++){ cq1[iw][ix-ix2]=wlsp[iw]; } free2float(p); free2complex(cp); free1float(wl); free1complex(wlsp); /*if the horizontal spacing interval is in feet, convert it to meter*/ if(!flag) dx*=0.3048; /*start of the timing function*/ time(&t1); /* send local parameters to all slaves*/ pvm_initsend(PvmDataDefault); ix=15; rc=pvm_pkint(&ix,1,1); rc=pvm_pkint(&ntfft,1,1); rc=pvm_pkint(&ix2,1,1); rc=pvm_pkint(&ix3,1,1); rc=pvm_pkint(&isx,1,1); rc=pvm_pkint(&il,1,1); rc=pvm_pkint(&ir,1,1); rc=pvm_pkfloat(&dx,1,1); rc=pvm_pkfloat(&dz,1,1); rc=pvm_pkfloat(&dw,1,1); rc=pvm_pkfloat(&dt,1,1); msgtype=PARA_MSGTYPE; task=NTASKS; rc=pvm_mcast(tids,task,msgtype); /* send all the frequency to slaves*/ count=NTASKS*5; /*count is the number of frequency components in a shot gather*/ nw=truenw; nw1=nw/(count); if(nw1==0)nw1=1; total=count=ceil(nw*1.0/nw1); /* if it is the first shot gather, send equal data to all the slaves, then for the following shot gathers, only send data when slave requests*/ if(nxshot==tshot){ for(i=0;i<NTASKS;i++){ float *tmpp; float fw1; int nww,byte,nwww; pvm_initsend(PvmDataDefault); nww=nf1+i*nw1;fw1=fw+nww*dw; nwww=nw1; byte=UnDone; rc=pvm_pkint(&byte,1,1); rc=pvm_pkfloat(&fw1,1,1); rc=pvm_pkint(&nwww,1,1); rc=pvm_pkfloat((float *)cq[nww],nx*nwww*2,1); rc=pvm_pkfloat((float *)cq1[nww],nx*nwww*2,1); msgtype=DATA_MSGTYPE; pvm_send(tids[i],msgtype); } count-=NTASKS; } while(count){ int tid0,bufid; float *tmpp; float fw1; int nww,byte,nwww; int i; i=total-count; msgtype=COM_MSGTYPE; bufid=pvm_recv(-1,msgtype); rc=pvm_upkint(&tid0,1,1); pvm_freebuf(bufid); pvm_initsend(PvmDataDefault); nww=nf1+i*nw1;fw1=fw+nww*dw; if(i==total-1)nwww=nw-nw1*i; else nwww=nw1; byte=UnDone; rc=pvm_pkint(&byte,1,1); rc=pvm_pkfloat(&fw1,1,1); rc=pvm_pkint(&nwww,1,1); rc=pvm_pkfloat((float *)cq[nww],nx*nwww*2,1); rc=pvm_pkfloat((float *)cq1[nww],nx*nwww*2,1); msgtype=DATA_MSGTYPE; pvm_send(tid0,msgtype); count--; } ix=Done; pvm_initsend(PvmDataDefault); rc=pvm_pkint(&ix,1,1); msgtype=DATA_MSGTYPE; pvm_mcast(tids,task,msgtype); free2complex(cq); free2complex(cq1); time(&t2); warn("\n %d shot been finished in %f seconds, Ntask=%d",nxshot,difftime(t2,t1),NTASKS); nxshot--; if(nxshot)goto loop; /*when all the shot gathers done, send signal to all slaves to request the partial imaging*/ ix=FinalDone; pvm_initsend(PvmDataDefault); rc=pvm_pkint(&ix,1,1); msgtype=PARA_MSGTYPE; pvm_mcast(tids,task,msgtype); /*allocate space for the final image*/ cresult = alloc2float(nz,nxo); for(ix=0;ix<nxo;ix++) for(iz=0;iz<nz;iz++) { cresult[ix][iz]=0.0; } result_tmp= alloc2float(nz,nxo); /*receive partial image from all the slaves*/ msgtype=RESULT_MSGTYPE; i=0; while(i<NTASKS){ int bufid; bufid=pvm_recv(-1,msgtype); rc=pvm_upkfloat(result_tmp[0],nxo*nz,1); pvm_freebuf(bufid); for(ix=0;ix<nxo;ix++) for(iz=0;iz<nz;iz++) { cresult[ix][iz]+=result_tmp[ix][iz]; } i=i+1; warn("\n i=%d been received",i); } /*send signal to all slaves to kill themselves*/ pvm_initsend(PvmDataDefault); pvm_mcast(tids,task,COM_MSGTYPE); /*output the final image*/ for(ix=0; ix<nxo; ix++){ tr.ns = nz ; tr.dt = dz*1000000.0 ; tr.d2 = dx; tr.offset = 0; tr.cdp = tr.tracl = ix; memcpy( (void *) tr.data, (const void *) cresult[ix],nz*FSIZE); puttr(&tr); } pvm_exit(); return EXIT_SUCCESS; }