void sweep(int parent, heur_prob *p) { printf("\nIn sweep....\n\n"); int mytid, info, r_bufid; int i; int vertnum; sweep_data *data; float depotx, depoty; float tempx, tempy; double t=0; mytid = pvm_mytid(); (void) used_time(&t); printf("mytid in sweep.c= %i", pvm_mytid()); /*-----------------------------------------------------------------------*\ | Receive the VRP data | \*-----------------------------------------------------------------------*/ PVM_FUNC(r_bufid, pvm_recv(-1, SWEEP_TRIALS)); PVM_FUNC(info, pvm_upkint(&(p->par.sweep_trials), 1, 1)); printf("\nCheckpoint 1\n"); /*-----------------------------------------------------------------------*/ vertnum = p->vertnum; p->cur_tour = (best_tours *)calloc(1, sizeof(best_tours)); p->cur_tour->tour = (_node *)calloc(vertnum, sizeof(_node)); printf("\nCheckpoint 2\n"); data = (sweep_data *)calloc(vertnum-1, sizeof(sweep_data)); if (p->dist.coordx && p->dist.coordy){ depotx = p->dist.coordx[0]; depoty = p->dist.coordy[0]; printf("\nCheckpoint 3\n"); /*calculate angles for sorting*/ for (i=0; i<vertnum-1; i++){ tempx = p->dist.coordx[i+1] - depotx; tempy = p->dist.coordy[i+1] - depoty; data[i].angle = (float) atan2(tempy, tempx); if (data[i].angle < 0) data[i].angle += 2*M_PI; data[i].cust=i+1; } printf("\nCheckpoint 4\n"); quicksort(data, vertnum-1); printf("\nCheckpoint 5\n"); make_tour(p, data, p->cur_tour); printf("\nCheckpoint 6\n"); /*-----------------------------------------------------------------------*\ | Transmit the tour back to the parent | \*-----------------------------------------------------------------------*/ send_tour(p->cur_tour->tour, p->cur_tour->cost, p->cur_tour->numroutes, SWEEP, used_time(&t), parent, vertnum, 0, NULL); printf("\nCheckpoint 7\n"); } if (data) free((char *) data); printf("\nCheckpoint 8\n"); free_heur_prob(p); }
main() { char *me = "inheritb"; int context_original, context_1, context_2; int ptid, tid, gptid, cc; char buf[100]; char machine[25]; int i=0; gethostname( machine, 25 ); printf( "%d:%s: t%x on machine <%s> with context %d.\n", i++, me, pvm_mytid(), machine, pvm_getcontext() ); context_original = pvm_getcontext(); /* retrieve initial context */ context_1 = pvm_newcontext(); /* get new context 1 */ pvm_setcontext( context_1 ); /* activate new context 1 */ printf( "%d:%s: t%x on machine <%s> with new #1 context %d ", i++, me, pvm_mytid(), machine, pvm_getcontext() ); printf( "--> spawn 1st inherit2.\n" ); /* start 1st inherit2 worker @ context 1 */ pvm_spawn( "inherit2", (char **) 0, PvmTaskDefault, "", 1, &tid ); context_2 = pvm_newcontext(); /* get new context 2 */ pvm_setcontext(context_2); /* activate new context 2 */ printf( "%d:%s: t%x on machine <%s> with new #2 context %d ", i++, me, pvm_mytid(), machine, pvm_getcontext() ); printf( "--> spawn 2nd inherit2.\n" ); /* start 2nd inherit2 worker @ context 2 */ pvm_spawn( "inherit2", (char **) 0, PvmTaskDefault, "", 1, &tid ); /* receive from inherit2 worker 2 @ context 2 */ cc = pvm_recv( -1, -1 ); pvm_bufinfo( cc, (int *) 0, (int *) 0, &tid ); pvm_upkstr( buf ); printf( "%d:%s: t%x %s <-- received from 2nd inherit2.\n", i++, me, tid, buf); /* reactivate initial context 1*/ pvm_setcontext(context_1); printf( "%d:%s: t%x on machine <%s> with new #1 context %d.\n", i++, me, pvm_mytid(), machine, pvm_getcontext() ); /* receive from inherit2 worker 1 @ context 1 */ cc = pvm_recv( -1, -1 ); pvm_bufinfo( cc, (int *) 0, (int *) 0, &tid ); pvm_upkstr( buf ); printf( "%d:%s: t%x %s <-- received from 1st inherit2.\n", i++, me, tid, buf ); pvm_exit(); exit( 0 ); }
/// Init a pipeline manager. Void function. /// \param confFile XML file configuration, NULL if we want to make things by hand /// \param argc argc received by main function that will be forwarded to filter processes /// \param argv argv received by main function that will be forwarded to filter processes /// \return Layout of the pipeline static Layout *initManager(char *confFile, int argc, char **argv) { char hostname[50]; int i,j; int numFilterInstances = 0; //the manager pointer Layout *layout; layout = createLayout(); layout->argvSpawn = (char **)malloc(sizeof(char *) * (argc)); // my hostname gethostname(hostname, 50); fprintf(stderr, "manager: pvm tid:t%x hostname:%s\n", pvm_mytid(), hostname); printf("manager: pvm tid:t%x hostname:%s\n", pvm_mytid(), hostname); // read XML config file printf("\n====================================\n"); printf("Manager.c: start parsing the file...\n"); if (readConfig(confFile, layout) == -1) { printf("Manager.c: parse error, aborting\n"); exit(1); } printf("Manager.c: parser ended successfully\n"); printf("====================================\n\n"); // for each filter, we spawn the children process, but dont send any data yet for(i = 0; i < layout->numFilters; i++) { FilterSpec *pFilter = layout->filters[i]; // Copies argv to layout->argvSpawn, except argv[0] for (j=0; j<argc-1; j++) { layout->argvSpawn[j] = argv[j+1]; } layout->argvSpawn[argc-1] = NULL; //spawn all instances of this filter printf("Manager.c: spawning filter %s instances\n", pFilter->name); if (fsSpawnInstances(pFilter, layout->command, layout->argvSpawn) == -1) { printf("Manager.c: error spawning filter %s, aborting\n", pFilter->name); exit(1); } numFilterInstances += pFilter->filterPlacement.numInstances; #ifdef BMI_FT // Initialize the fault status pFilter->faultStatus = NO_FAULT; #endif } printf("All process started, sending data now....\n\n"); sendFiltersData(layout); #ifdef VOID_TERM gt = initGlobalTermination(layout, numFilterInstances); #endif return layout; }
int main(int argc, char** argv) { strcpy(myname, name) ; mytid = pvm_mytid() ; set_tid() ; printf("[gen_x]:my_tid=%d\n", pvm_mytid()) ; ctrl_part(_rec, _send, copyname) ; return 0 ; }
int pvm_freebuf(int bufid) { pvmc_buffer *cur_buf; int result=0; #ifdef PVM_DEBUG PRINTF("Pe(%d) tid=%d:pvm_freebuf(%d)\n",MYPE(),pvm_mytid(),bufid); #endif if ((bufid<=0) || (bufid>=MAX_BUFFERS)) { PRINTF("Pe(%d) tid=%d:%s:%d pvm_freebuf() attempted to free out of range bufid\n", MYPE(),pvm_mytid(),__FILE__,__LINE__); return -1; } cur_buf = &(CpvAccess(pvmc_bufarray)[bufid]); if (cur_buf->refcount < 1) { PRINTF("Pe(%d) tid=%d:%s:%d pvm_freebuf(%d) refcount=%d, i'm confused\n", MYPE(),pvm_mytid(),__FILE__,__LINE__,bufid,cur_buf->refcount); result=-2; } cur_buf->refcount--; if (cur_buf->refcount==0) { pvmc_emptybuf(cur_buf); cur_buf->nxt_free=CpvAccess(pvmc_freebufs); CpvAccess(pvmc_freebufs)=cur_buf; } #ifdef PVM_DEBUG { int x; int Counter=0; int FreeCounter=0; struct pvmc_buffer_s *FreeList; /* find the number that we think are free */ for(x=0; x<MAX_BUFFERS; x++) { if (CpvAccess(pvmc_bufarray)[x].refcount == 0) Counter++; } /* find the number that are linked as free */ FreeList = CpvAccess(pvmc_freebufs); while(FreeList != NULL) { FreeCounter++; FreeList = FreeList->nxt_free; } /* show the results */ PRINTF("Pe(%d) tid=%d:%s:%d unused=(%d) sizeof(freelist)=%d\n", MYPE(),pvm_mytid(),__FILE__,__LINE__,Counter,FreeCounter); } #endif return result; }
int Setup(ArgStruct * p) { p->prot.mytid = pvm_mytid(); #ifdef DEBUG printf("My task id is %d \n", p->prot.mytid); #endif }
int main(void){ int tid; /*this task id */ int bufid, master, bytes, msgtag, source; char * graph_text = NULL; int **matrix; int degree, edges; int len; int i; int greycodeLength; tid = pvm_mytid(); /*enroll in pvm */ master = pvm_parent(); /*get the master id */ while (1){ /*Get the first graph */ pvm_initsend(PvmDataDefault); pvm_pkstr(""); /*Just put something in the buffer */ pvm_send(master, MSGREQTASK); /* Request a task */ bufid = pvm_recv(master, MSGTASK); /* Get the task */ pvm_bufinfo(bufid, &bytes, &msgtag, &source); /* Get the size of the text */ graph_text = malloc(bytes); pvm_upkstr(graph_text); /* Unpack the text */ len = strlen(graph_text); if(graph_text[len - 1] == '\n') graph_text[len - 1] = '\0'; matrix = create_matrix(graph_text, °ree); /*Generate the appropriate matrix */ populate_matrix(graph_text, matrix, &edges, degree); greycodeLength = 1 << degree; // Initialize code (where the greycode is stored) int * vals = calloc(2 * greycodeLength, sizeof(int)); int ** code = malloc(greycodeLength * sizeof(int *)); for(i = 0; i < greycodeLength; i++){ /*assign rows within the allocated space */ code[i] = vals + i*2; } /*** DO GREYCODE ALGORITHM ON THE MATRIX ***/ if(greycode(degree, matrix, code) == 1){ /*If we found a code */ pvm_initsend(PvmDataDefault); pvm_pkstr(graph_text); pvm_send(master, MSGCODE); } else{ /*Didnt find a code */ pvm_initsend(PvmDataDefault); pvm_pkstr(graph_text); pvm_send(master,MSGNOCODE); } destroy_matrix(matrix); /* Free the memory associated with the matrix */ destroy_matrix(code); free(graph_text); } pvm_exit(); exit(0); }
void BBSClient::start() { char* client = 0; int tid; int n; if (started_) { return; } #if debug printf("BBSClient start\n"); fflush(stdout); #endif BBSImpl::start(); mytid_ = pvm_mytid(); if (mytid_ < 0) { perror("start"); } tid = pvm_parent(); sid_ = tid; if (tid == PvmSysErr) { perror("start"); } assert(tid > 0); { // a worker is_master_ = false; pvm_initsend(PvmDataDefault); nrnmpi_myid = get(HELLO); assert(nrnmpi_myid > 0); return; } }
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 ; }
/* initialization function */ void init_parallel(int m) { /* verify data storage consistency for packing optimization */ if (sizeof(position) != 2 + TPITS) die("sizeof(position) strange\n"); if (offsetof(c_res,rd) != 3*sizeof(int)) die("offsets in c_res strange\n"); if (sizeof(jobinfo) != (6+4*PITS)*sizeof(int) + sizeof(c_res)) die("sizeof(jobinfo) strange\n"); srandom(clock()); nw = nj = nsj = 0; wtid = 0; ja = 0; sj = 0; cj = 0; master = m; gethostname(host,100); stid = pvm_mytid(); if (master) { n = 1; wtid = malloc(sizeof(int)); wtid[0] = stid; } else hello(); }
int pvm_getrbuf(void) { #ifdef PVM_DEBUG PRINTF("Pe(%d) tid=%d:pvm_getrbuf()\n",MYPE(),pvm_mytid()); #endif return CpvAccess(pvmc_rbufid); }
FilterData *createFilterData(){ FilterData *fd = (FilterData *) malloc(sizeof(FilterData)); if(!fd){ printf("createFilterData: could not allocate memory\n"); return NULL; } // init num ports fd->numInputPorts = 0; fd->numOutputPorts = 0; // Used to now where a new port can be added fd->numInportsAdded = 0; fd->numOutportsAdded = 0; #ifdef VOID_INST //we beign at void state fd->instData = instCreate(); #endif #ifdef ATTACH fd->attached = 0; #endif #ifdef VOID_TRACER char tracefilename[ MAX_HNAME_LENGTH + 8 + 100 ], hostname[ MAX_HNAME_LENGTH ]; gethostname( hostname, MAX_HNAME_LENGTH ); sprintf( tracefilename, "trace.%s.%d", hostname, pvm_mytid() ); msgId = 0; fd->trcData = trcCreateData( tracefilename ); #endif return fd; }
int pvmc_sendmsgsz(void) { int msgsz; pvmc_buffer *cur_buf; pvmc_item *cur_item; if ((CpvAccess(pvmc_sbufid)<=0) || (CpvAccess(pvmc_sbufid) >= MAX_BUFFERS) || (CpvAccess(pvmc_bufarray)[CpvAccess(pvmc_sbufid)].refcount <= 0)) { PRINTF("Pe(%d) tid=%d:%s:%d pvmc_sendmsgsz() size requested for unused send buffer\n", MYPE(),pvm_mytid(),__FILE__,__LINE__); return -1; } cur_buf = &(CpvAccess(pvmc_bufarray)[CpvAccess(pvmc_sbufid)]); msgsz=sizeof(cur_buf->bytes)+sizeof(cur_buf->tag)+ sizeof(cur_buf->tid)+sizeof(cur_buf->num_items); cur_item=cur_buf->first_item; while (cur_item != cur_buf->last_item) { msgsz += cur_item->size+sizeof(cur_item->type)+sizeof(cur_item->size); cur_item = cur_item->nxt; } return msgsz; }
void pvm_init(int argc, char *argv[]) { int mytid, mygid, ctid[MAXPROC]; int np, i; mytid = pvm_mytid(); if((argc != 2) && (argc != 1)) goto usage; if(argc == 1) np = 1; if(argc == 2) if((np = atoi(argv[1])) < 1) goto usage; if(np > MAXPROC) goto usage; mygid = pvm_joingroup(MPGROUP); if(np > 1) if (mygid == 0) i = pvm_spawn(argv[0], argv+1, 0, "", np-1, ctid); while(pvm_gsize(MPGROUP) < np) sleep(1); /* sync */ pvm_barrier(MPGROUP, np); printf("PVM initialization done!\n"); return; usage: fprintf(stderr, "usage: %s <nproc>\n", argv[0]); pvm_exit(); exit(-1); }
int register_process() { int mytid; PVM_FUNC(mytid, pvm_mytid()); return(mytid); }
int main() { int mytid; mytid = pvm_mytid(); printf("My TID is %d\n", mytid); pvm_exit(); return 0; }
value Pvm_mytid(void) { int mytid; mytid=pvm_mytid(); if (mytid<0) TreatError(mytid); return Val_int(mytid); }
void pvmc_init_bufs(void) { int i; #ifdef PVM_DEBUG PRINTF("Pe(%d) tid=%d:%s:%d pvmc_init_bufs() initializing buffer array\n", MYPE(),pvm_mytid(),__FILE__,__LINE__); #endif CpvInitialize(pvmc_buffer*,pvmc_bufarray); CpvAccess(pvmc_bufarray)=MALLOC(sizeof(pvmc_buffer)*MAX_BUFFERS); if (CpvAccess(pvmc_bufarray)==NULL) { PRINTF("Pe(%d) tid=%d:%s:%d pvmc_init_bufs() can't alloc buffer array\n", MYPE(),pvm_mytid(),__FILE__,__LINE__); exit(1); } CpvInitialize(pvmc_buffer*,pvmc_freebufs); CpvAccess(pvmc_freebufs)=&(CpvAccess(pvmc_bufarray)[1]); /* throw away first bufid */ for(i=0;i<MAX_BUFFERS;i++) { CpvAccess(pvmc_bufarray)[i].bufid=i; CpvAccess(pvmc_bufarray)[i].bytes=0; CpvAccess(pvmc_bufarray)[i].tag=0; CpvAccess(pvmc_bufarray)[i].tid=-1; CpvAccess(pvmc_bufarray)[i].num_items=-1; CpvAccess(pvmc_bufarray)[i].refcount=0; CpvAccess(pvmc_bufarray)[i].first_item=(pvmc_item *)NULL; CpvAccess(pvmc_bufarray)[i].cur_item=(pvmc_item *)NULL; CpvAccess(pvmc_bufarray)[i].last_item=(pvmc_item *)NULL; if (i==MAX_BUFFERS-1) CpvAccess(pvmc_bufarray)[i].nxt_free=(pvmc_buffer *)NULL; else CpvAccess(pvmc_bufarray)[i].nxt_free=&(CpvAccess(pvmc_bufarray)[i+1]); CpvAccess(pvmc_bufarray)[i].data_buf=(char *)NULL; } CpvInitialize(int,pvmc_sbufid); CpvAccess(pvmc_sbufid) = 0; CpvInitialize(int,pvmc_rbufid); CpvAccess(pvmc_rbufid) = 0; }
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); }
int pvm_mkbuf(int encoding) { pvmc_buffer *new_buf; #ifdef PVM_DEBUG PRINTF("Pe(%d) tid=%d:pvm_mkbuf(%d)\n", MYPE(),pvm_mytid(),encoding); if (encoding != PvmDataRaw) PRINTF("Pe(%d) tid=%d:%s:%d Warning: only encoding=PvmDataRaw supported\n", MYPE(),pvm_mytid(),__FILE__,__LINE__); #endif new_buf = CpvAccess(pvmc_freebufs); if (new_buf == NULL) { PRINTF("Pe(%d) tid=%d:%s:%d pvm_mkbuf() no more buffers\n", MYPE(),pvm_mytid(),__FILE__,__LINE__); return -1; } CpvAccess(pvmc_freebufs)=CpvAccess(pvmc_freebufs)->nxt_free; new_buf->bytes=0; new_buf->tag=0; new_buf->tid=pvm_mytid(); new_buf->num_items = 0; if ((new_buf->first_item= (pvmc_item *)MALLOC(sizeof(pvmc_item))) == NULL) { PRINTF("Pe(%d) tid=%d:%s:%d pvm_mkbuf() MALLOC failed\n", MYPE(),pvm_mytid(),__FILE__,__LINE__); return -1; } new_buf->first_item->type=0; new_buf->first_item->size=0; new_buf->first_item->free_data=FALSE; new_buf->first_item->data=(char *)NULL; new_buf->first_item->nxt=(pvmc_item *)NULL; new_buf->cur_item=new_buf->first_item; new_buf->last_item=new_buf->first_item; new_buf->refcount=1; return new_buf->bufid; }
static int pvmc_getbuf(int bufid) { pvmc_buffer *cur_buf; if ((bufid<=0) || (bufid>=MAX_BUFFERS)) { PRINTF("Pe(%d) tid=%d:%s:%d pvmc_getbuf(%d) attempted to get out of range bufid\n", MYPE(),pvm_mytid(),__FILE__,__LINE__,bufid); return -1; } cur_buf = &(CpvAccess(pvmc_bufarray)[bufid]); if (cur_buf->refcount<1) { PRINTF("Pe(%d) tid=%d:%s:%d pvm_getbuf() trying with refcount=%d, i'm confused\n", MYPE(),pvm_mytid(),__FILE__,__LINE__,cur_buf->refcount); return -1; } cur_buf->refcount++; return bufid; }
int pvm_bufinfo(int bufid, int *bytes, int *msgtag, int *tid) { #ifdef PVM_DEBUG PRINTF("Pe(%d) tid=%d:pvm_bufinfo(%d,0x%x,0x%x,0x%x)\n", pvm_mytid(),bufid,bytes,msgtag,tid); #endif if ((bufid<=0) || (bufid >= MAX_BUFFERS) || (CpvAccess(pvmc_bufarray)[bufid].refcount <= 0)) { PRINTF("Pe(%d) tid=%d:%s:%d pvm_bufinfo(%d) info requested about unused buffer\n", MYPE(),pvm_mytid(),__FILE__,__LINE__,bufid); return -1; } if (bytes) *bytes=CpvAccess(pvmc_bufarray)[bufid].bytes; if (msgtag) *msgtag=CpvAccess(pvmc_bufarray)[bufid].tag; if (tid) *tid=CpvAccess(pvmc_bufarray)[bufid].tid; return 0; }
void *pvmc_mkitem(int nbytes, int type) { pvmc_buffer *buf; void *databuf; if ((CpvAccess(pvmc_sbufid)<=0) || (CpvAccess(pvmc_sbufid) >= MAX_BUFFERS) || (CpvAccess(pvmc_bufarray)[CpvAccess(pvmc_sbufid)].refcount <= 0)) { PRINTF("Pe(%d) tid=%d:%s:%d pvmc_mkitem() unused send buffer\n", MYPE(),pvm_mytid(),__FILE__,__LINE__); return NULL; } buf = &(CpvAccess(pvmc_bufarray)[CpvAccess(pvmc_sbufid)]); buf->last_item->type=type; buf->last_item->size=nbytes; databuf=MALLOC(nbytes); if (!databuf) { PRINTF("Pe(%d) tid=%d:%s:%d pvmc_mkitem() can't allocate data space\n", MYPE(),pvm_mytid(),__FILE__,__LINE__); return databuf; } buf->last_item->free_data=TRUE; buf->last_item->data=databuf; buf->last_item->nxt=(pvmc_item *)MALLOC(sizeof(pvmc_item)); if (buf->last_item->nxt==NULL) { PRINTF("Pe(%d) tid=%d:%s:%d pvmc_mkitem() can't allocate new item\n", MYPE(),pvm_mytid(),__FILE__,__LINE__); return NULL; } buf->last_item=buf->last_item->nxt; buf->last_item->type=0; buf->last_item->size=0; buf->last_item->free_data=FALSE; buf->last_item->data=(char *)NULL; buf->last_item->nxt=(pvmc_item *)NULL; buf->num_items++; return databuf; }
/*-------------------------------------------------------------------*/ void m2pvme_upkarray_rest(int nlhs, mxArray *plhs[], int nrhs, mxArrayIn *prhs[]) { /*-------------------------------------------------------------------*/ MATFile *pmat; char fname[256]; mxArray *array_ptr; plhs[1] = mxCreateDoubleMatrix(1,1,mxREAL); if((mxGetPr(plhs[1]))[0] = (double) pvme_upkarray_rest(&plhs[0],(char*)0)==1) { /* the data contains Matlab user defined objects! */ /* save and load this mxArray so as it will be recognized as an object */ /* object passing could be done by getting a default object from the workspace and then constructing the object in the workspace directly by using mxPutArray with each struct for each level... */ /* array_ptr = mexGetArray("def","base"); mxSetName(array_ptr, "defcopy"); mexPutArray(array_ptr, "base"); mxDestroyArray(array_ptr); */ sprintf(fname,"%s/dp_%d.mat",TMP_LOC,pvm_mytid()); /*printf(fname,"%s/dp_%d.mat",TMP_LOC,pvm_mytid());*/ pmat = matOpen(fname, "w"); if (pmat == NULL) { mexErrMsgTxt("m2libpvme:Error creating file for transferring object\n"); } mxSetName(plhs[0], "objsl"); if (matPutArray(pmat, plhs[0]) != 0) { mexErrMsgTxt("m2libpvme:m2pvme_upkarray_rest: Error saving temporary intermediate file for objects\n"); } if (matClose(pmat) != 0) { mexErrMsgTxt("m2libpvme:m2pvme_upkarray_rest:Error temporary intermediate file for object transfer\n"); } /* printf("class::::%s\n", mxGetClassName(plhs[0]));*/ if ( !( plhs[0] = mxCreateString(fname) ) ) mexErrMsgTxt("m2pvme_upkarray_rest(): mxCreateString() failed.\n"); } return; }
void main() { /* enroll in pvm */ mytid = pvm_mytid(); master = pvm_parent(); /* receive data from master */ pvm_recv(master, DATA); pvm_upkint(&nproc, 1, 1); pvm_upkdouble(&lower, 1, 1); pvm_upkdouble(&upper, 1, 1); pvm_upkdouble(&delta_x, 1, 1); pvm_upkint(&partitions, 1, 1); pvm_upkint(tids, nproc, 1); /* determine which slave I am (0..nproc-1) */ for(i=0; i<nproc; i++) if(mytid==tids[i]) { mynode = i; break; } /* start timiming */ start = clock(); /* calculate approximation */ partitions_per_slave = partitions / nproc; first = lower + mynode * ((upper-lower)/nproc); last = first + partitions_per_slave * delta_x; x = first + (delta_x/2.0); while(x<last) { approx_result += f(x) * delta_x; x += delta_x; } /* end timing */ elapse = (clock() - start) / clocks_per_sec; avg_time = elapse / partitions; /* send the results back to the master program */ pvm_initsend(PvmDataDefault); pvm_pkdouble(&elapse, 1, 1); pvm_pkdouble(&approx_result, 1, 1); pvm_pkdouble(&avg_time, 1, 1); pvm_send(master, RESULTS); /* exit pvm */ pvm_exit(); }
void *pvmc_getitem(int n_bytes, int type) { pvmc_buffer *buf; pvmc_item *item; void *data; if ((CpvAccess(pvmc_rbufid)<=0) || (CpvAccess(pvmc_rbufid) >= MAX_BUFFERS) || (CpvAccess(pvmc_bufarray)[CpvAccess(pvmc_rbufid)].refcount <= 0)) { PRINTF("Pe(%d) tid=%d:%s:%d pvmc_getitem() uninitialized recv buffer\n", MYPE(),pvm_mytid(),__FILE__,__LINE__); return NULL; } buf = &(CpvAccess(pvmc_bufarray)[CpvAccess(pvmc_rbufid)]); item = buf->cur_item; if (item==buf->last_item) { PRINTF("Pe(%d) tid=%d:%s:%d pvmc_getitem() no more items\n", MYPE(),pvm_mytid(), __FILE__,__LINE__); data=NULL; } else if (item->data==(void *)NULL) { PRINTF("Pe(%d) tid=%d:%s:%d pvmc_getitem() uninitialized data\n", MYPE(),pvm_mytid(), __FILE__,__LINE__); data=NULL; } else if (item->size < n_bytes) { PRINTF("Pe(%d) tid=%d:%s:%d pvmc_getitem() data size mismatch\n", MYPE(),pvm_mytid(), __FILE__,__LINE__); data=NULL; } else if (item->type != type) { PRINTF("Pe(%d) tid=%d:%s:%d pvmc_getitem() type mismatch\n", MYPE(),pvm_mytid(), __FILE__,__LINE__); data=NULL; } else { data=item->data; } buf->cur_item = buf->cur_item->nxt; return data; }
int pvmc_settidtag(int pvm_tid, int tag) { pvmc_buffer *cur_buf; if ((CpvAccess(pvmc_sbufid)<=0) || (CpvAccess(pvmc_sbufid) >= MAX_BUFFERS) || (CpvAccess(pvmc_bufarray)[CpvAccess(pvmc_sbufid)].refcount <= 0)) { PRINTF("Pe(%d) tid=%d:%s:%d pvmc_setidtag() unused send buffer\n", MYPE(),pvm_mytid(),__FILE__,__LINE__); return -1; } cur_buf=&(CpvAccess(pvmc_bufarray)[CpvAccess(pvmc_sbufid)]); cur_buf->tag = tag; cur_buf->tid = pvm_tid; }
int main() { int in, out, diameter, total; int mytid = pvm_mytid(); // Init messages (1) pvm_recv(-1, 1); pvm_upkint(&total, 1, 1); pvm_upkint(&diameter, 1, 1); pvm_upkint(&in, 1, 1); pvm_upkint(&out, 1, 1); // get output nodes int outNodes[out]; memset(outNodes, -1, out * sizeof(int)); pvm_upkint(outNodes, out, 1); // Election message (2) int max = mytid; int i; for (i = 0 ; i < diameter ; ++i) { // Advertise my max to everybody int j; for(j = 0 ; j < out ; j++){ pvm_initsend(PvmDataRaw); pvm_pkint(&max, 1, 1); pvm_send(outNodes[j], 2); } // Get max from the neighbors for(j = 0 ; j < in ; j++){ int tmp = 0; pvm_recv( -1, 2); pvm_upkint(&tmp, 1, 1); if(tmp>max) max = tmp; } } // Send my max to the parent pvm_initsend(PvmDataRaw); pvm_pkint(&max, 1, 1); pvm_send(pvm_parent(), 3); pvm_exit(); }
int main(int argc, char* argv[]) { int my_tid; int sender_id; int n; int num_of_configs; int config_id; int* config; int config_fit; int master_id = pvm_parent(); //printf("im a kid %d\n", master_id); my_tid = pvm_mytid(); /* -1 for these arguments mean that it matches any task identification * sent to it, and any message tag */ pvm_recv(-1, -1); /* unpackage the information sent to us from the master about how many * configurations will be recieved, and how large they are. */ pvm_upkint(&num_of_configs, 1, 1); pvm_upkint(&n, 1, 1); //printf("tid=%d; %d %d\n", my_tid, num_of_configs, n); //fflush(stdout); config = malloc(sizeof(int) * n); /* takes information about configurations to be recieved and their size * and starts recieving the configurations themselves, with their * identifier as the master knows them. Fitnesses are generated as they * are recieved and and fitness and id are then sent back to the master */ int i; pvm_recv(-1, -1); for (i = 0; i < num_of_configs; i++) { pvm_upkint(&config_id, 1, 1); pvm_upkint(config, n, 1); config_fit = fitness_test(n, config); pvm_initsend(PvmDataDefault); pvm_pkint(&config_id, 1, 1); pvm_pkint(&config_fit, 1, 1); pvm_send(master_id, 0); } pvm_exit(); return 1; }
int pvmc_packmsg(void *msgbuf) { pvmc_buffer *cur_buf; pvmc_item *cur_item; int bytes_packed=0; if ((CpvAccess(pvmc_sbufid)<=0) || (CpvAccess(pvmc_sbufid) >= MAX_BUFFERS) || (CpvAccess(pvmc_bufarray)[CpvAccess(pvmc_sbufid)].refcount <= 0)) { PRINTF("Pe(%d) tid=%d:%s:%d pvmc_packmsg() unused send buffer\n", MYPE(),pvm_mytid(),__FILE__,__LINE__); return -1; } cur_buf=&(CpvAccess(pvmc_bufarray)[CpvAccess(pvmc_sbufid)]); *((int *)((char *)msgbuf+bytes_packed)) = cur_buf->bytes; bytes_packed+=sizeof(int); *((int *)((char *)msgbuf+bytes_packed)) = cur_buf->tag; bytes_packed+=sizeof(int); *((int *)((char *)msgbuf+bytes_packed)) = cur_buf->tid; bytes_packed+=sizeof(int); *((int *)((char *)msgbuf+bytes_packed)) = cur_buf->num_items; bytes_packed+=sizeof(int); #ifdef PVM_DEBUG PRINTF("Pe(%d) pvmc_packmsg: %d items packed for tag %d\n", MYPE(),cur_buf->num_items,cur_buf->tag); #endif cur_item=cur_buf->first_item; while(cur_item!=cur_buf->last_item) { *((int *)((char *)msgbuf+bytes_packed)) = cur_item->type; bytes_packed+=sizeof(int); *((int *)((char *)msgbuf+bytes_packed)) = cur_item->size; bytes_packed+=sizeof(int); cur_item=cur_item->nxt; } cur_item=cur_buf->first_item; while(cur_item!=cur_buf->last_item) { if (cur_item->size > 0) { memcpy((void *)((char *)msgbuf+bytes_packed),cur_item->data, cur_item->size); bytes_packed+=cur_item->size; } cur_item=cur_item->nxt; } return bytes_packed; }