void upkjobinfo_active(jobinfo *j) { pvm_upkint(&j->jid,6,1); // jid, tid, pjid, d, a, n pvm_upkint(&j->s.k,4,1); // k,o,r,rd pvm_upkbyte(&j->s.p,2+TPITS,1); pvm_upkbyte(j->s.m,MAXMVC,1); pvm_upkint(j->o,4*PITS,1); // o, js, ctid, cjid }
value Pvm_upkstring(void) { CAMLparam0(); int bufid,bytes,msgtag,tid; char *tab; CAMLlocal1(s); int res,i; res=pvm_upkint(&bytes,1,1); if (res<0) TreatError(res); tab=(char *)malloc(sizeof(char)*bytes); res = pvm_upkbyte(tab,bytes,1); if (res<0) { free(tab); TreatError(res); } s = alloc_string(bytes); for (i=0;i<bytes;i++) Byte(s,i)=tab[i]; free(tab); CAMLreturn(s); }
int NonBlockingReceiveMessage(message* m, msg_type in_type) { int stat = pvm_nrecv(-1, in_type); if( stat ) { pvm_upkbyte((char*)m, sizeof(message), 1); } return stat; }
int receive_char_array(char *array, int size) { int info; PVM_FUNC(info, pvm_upkbyte(array, size, 1)); return(info); }
int RecvCplx(complex *CplxBuf, int n, int tid, int MsgType) { int info, BufId, NBytes, MsgTag, SenderTid; BufId = pvm_recv(-1, MsgType); info = pvm_bufinfo(BufId, &NBytes, &MsgTag, &SenderTid); pvm_upkbyte((char *) CplxBuf, n*sizeof(complex), 1); return(SenderTid); }
int RecvINFO(INFO *data, int n, int tid, int MsgType) { int info, BufId, NBytes, MsgTag, SenderTid; BufId = pvm_recv(-1, MsgType); info = pvm_bufinfo(BufId, &NBytes, &MsgTag, &SenderTid); pvm_upkbyte((char *) data, n*sizeof(INFO), 1); return(SenderTid); }
void UnpackFile (int fd) { int n; char buf[PACKFILEBUFFERSIZE]; while ((n = UnpackNextInt ()) > 0) { assert (n <= sizeof (buf)); assert (! pvm_upkbyte (buf, n, 1)); assert (write (fd, buf, n) is n); } }
int RecvFI(float *FloatBuf, int nf, int *IntBuf, int ni, int tid, int MsgType) { int info, BufId, NBytes, MsgTag, SenderTid; BufId = pvm_recv(-1, MsgType); info = pvm_bufinfo( BufId, &NBytes, &MsgTag, &SenderTid); pvm_upkint(IntBuf, ni, 1); pvm_upkbyte((char *)FloatBuf, nf*sizeof(float), 1); return(SenderTid); }
void RecvData(ArgStruct * p) { #ifdef DEBUG printf(" In receive \n"); #endif pvm_recv(-1, -1); pvm_upkbyte(p->buff, p->bufflen, 1); #ifdef DEBUG printf(" message received . Size=%d \n", p->bufflen); #endif }
void IM_DN(_grid grid, IM_info* const in_info) { const IM_info* const info = in_info; const int numrecvs = info->numrecvs; int i; for (i=0; i<numrecvs; i++) { const int consecutive = info->recvinfo[i].consecutive; const int buffsize = info->recvinfo[i].buffsize; char* const buff = info->recvinfo[i].buff; const IM_comminfo* const recvinfo = info->recvinfo[i].comminfo; const int dyn_commid = info->recvinfo[i].dyn_commid; const int irecv = recvinfo->procnum; PRINT_W("[%d] recving %d fm %d on %d\n",_INDEX,buffsize,irecv,dyn_commid); pvm_recv(_tids[irecv],dyn_commid); pvm_upkbyte(buff,buffsize,1); if (!consecutive) { _IMU_Unmarshall(recvinfo,buff); } } }
/// Run the filter void runFilter(int argc, char **argv) { int i; char eowMsg[] = "EOW"; int currentWork = 0; fd = createFilterData(); if (recvFilterData(fd) == -1){ /// \todo An error ocourred! We should notify manager of this!! return; } // setFDArgc(fd, argc); setFDArgv(fd, argv); // load filter library, first try loading as a C library if (loadFDLibFunctions(fd) == -1){ // if it does not work, try lods the Event API if (loadEventAPI(fd) == -1){ // if it dosn't work, load as C++ libriry through the C++ API if (loadCppAPI(fd) == -1) { char msg[1000]; sprintf(msg, "could not load shared library %s", fd->libdata.name); sendFilterError(msg); return; } } } int parentTid = getFDParentTid(fd); #ifdef VOID_TERM tdd = initTerminationDetection(); if(tdd == NULL) { /// \todo An error ocourred! We should notify manager of this!! return; } #endif //initCache(fd->id, fd->myRank); // now, we start working! // loop getting work, till we get EOF. // for each appendWork received, calls init, process, finalize while (1) { // before init, we must reset all ports, so user get valid data // Coutinho: this must be done before the UOW recieve because after that, // the other filters are already running AND sending vaid data. /// \bug Resetting the ports even before receiving the UOW ISN'T SAFE. /// Before we even recieve the UOW, the other filters can already /// started to run and sending valid data to this filter. The only safe /// way is: send EOW at the end of finalizeFilter() and only drain /// data from the channels that doesn't recieved a EOW until recieve it // reset all input ports. They may be used in the next work for(i = 0; i < fd->numInputPorts; i++) { //resetInputPort(fd->inputPorts[i]); (fd->inputPorts[i])->numEowRecv = 0; } // reset all output ports. They may be used in the next work for(i = 0; i < fd->numOutputPorts; i++) { resetOutputPort(fd->outputPorts[i]); } //get message from manager, hopefully a work int bufId = pvm_recv(parentTid, 0); int msgSize, msgType; pvm_bufinfo(bufId, &msgSize, NULL, NULL); pvm_upkint(&msgType, 1, 1); //msg type can be either WORK, EOF or FT //leave if we get EOF if(msgType == MSGT_EOF) { #ifdef ATTACH // I'm a attached filter.. and dont realy need die now // so i'm going wait for any that would like attach me // to another pipeline if(fd->attached){ printf("I'm filter %s and i cant die\n", fd->name); destroyFilterDataAfterEOF(fd); fd = createFilterData(); if (recvFilterData(fd) == -1){ /// \todo An error ocourred! We should notify manager of this!! return; } #ifdef VOID_INST #ifdef BMI_FT restoreUserStates(fd->instData); destroyUserStateBackup(); #endif #endif // update my parent Tid parentTid = getFDParentTid(fd); continue; }else{ #endif break; #ifdef ATTACH } #endif } //get and set work int workSize = msgSize - sizeof(int); void *work = malloc(workSize); pvm_upkbyte((char *)work, workSize, 1); // For now, restart the cache for each work, but to do fault tolerance // with multiple appendWorks(), we will need to make the cache become // capable of saving/recovering multiple works. When the cache became // capable of that we will init it only once and use cacheSetCurrentWork(). // Restarting the cache should be done after the main lopp break, // otherwise we will finalize this process without cleaning the cache. // initCache(fd->id, fd->myRank); // cacheSetCurrentWork(currentWork); /// \todo put a signal handler to clean the cache on SIGTERM recievement // lets run #ifdef VOID_INST InstData *inst = fd->instData; //enter init state instSwitchState(inst, &inst->voidStates[TIMER_INIT]); #endif #ifdef VOID_TRACER // Enter init state trcEnterState( fd->trcData, VT_PROC_INIT ); #endif callFDInit(fd, work, workSize); // int weUseTasks = cacheGetUseTasks(); /* #ifdef VOID_FT if (weUseTasks) { // one fault has occurred: filters must begin in a consistent global state // Tell manager that we use tasks. pvm_initsend(PvmDataDefault); pvm_pkint(&weUseTasks, 1, 1); // Piggback :-) in this message the terminated tasks list TaskIdList *finishedTaskIdList = getFinishedTasks(); packTaskIdList(finishedTaskIdList); taskIdListDestroy(finishedTaskIdList); pvm_send(parentTid, 0); // get if we need to forward task creation and finalize messages pvm_recv(parentTid, 0); int needToForwardTaskMsgs = -1; pvm_upkint(&needToForwardTaskMsgs, 1, 1); cacheSetForwardTaskMsgs(needToForwardTaskMsgs); // Receive global state (global terminated tasks list) TaskIdList *globalTaskIdList = (TaskIdList *)unpackTaskIdList(); // Recover tasks checkpoints and restart interrupted tasks (recovery callbacks must be registered) cacheRecoverTasks(globalTaskIdList); taskIdListDestroy(globalTaskIdList); } else { #endif // Tell manager that we don't use tasks pvm_initsend(PvmDataDefault); pvm_pkint(&weUseTasks, 1, 1); pvm_send(parentTid, 0); // It will respond if we need to forward task creation messages pvm_recv(parentTid, 0); int needToForwardTaskMsgs = -1; pvm_upkint(&needToForwardTaskMsgs, 1, 1); cacheSetForwardTaskMsgs(needToForwardTaskMsgs); #ifdef VOID_FT } #endif */ #ifdef VOID_INST //leave init and enter process instSwitchState(inst, &inst->voidStates[TIMER_PROC]); #endif #ifdef VOID_TRACER // Leave init, enter process trcLeaveState( fd->trcData ); trcEnterState( fd->trcData, VT_PROC_PROC ); #endif callFDProcess(fd, work, workSize); #ifdef VOID_INST //leave process and enter VOID instSwitchState(inst, &inst->voidStates[TIMER_VOID]); #endif // here we have run init and process. We gotta close all doors before finalizing // send eow to all outputStream for(i = 0; i < fd->numOutputPorts; i++) { //close each branch of the (multi)stream if (fd->outputPorts[i]->state == OP_STATE_OPEN){ closeOutputPort(fd->outputPorts[i]); } } // and for the manager too, but here we use the type as a tag pvm_initsend(PvmDataRaw); pvm_pkbyte(eowMsg, strlen(eowMsg)+1, 1); pvm_send(parentTid, MSGT_EOW); // finalize #ifdef VOID_INST instSwitchState(fd->instData, &inst->voidStates[TIMER_FINALIZE]); #endif #ifdef VOID_TRACER // Leave process, enter finalize trcLeaveState( fd->trcData ); trcEnterState( fd->trcData, VT_PROC_FINALIZE ); #endif callFDFinalize(fd); #ifdef VOID_TRACER trcLeaveState( fd->trcData ); #endif #ifdef VOID_INST instSwitchState(fd->instData, &inst->voidStates[TIMER_VOID]); #endif // With multiple works we will modify this currentWork++; //cacheSetCurrentWork(currentWork); // destroyCache(); } //destroyCache(); destroyFilterData(fd); pvm_exit(); }
void nearest_ins(int parent, heur_prob *p) { printf("\nIn nearest_ins....\n\n"); int numroutes, cur_route, nearnode, *starter; int mytid, info, r_bufid; int *intour; int last, cost; neighbor *nbtree; _node *tour; route_data *route_info; int start; best_tours *tours; double t=0; mytid = pvm_mytid(); (void) used_time(&t); tours = p->cur_tour = (best_tours *) calloc (1, sizeof(best_tours)); /*-----------------------------------------------------------------------*\ | Receive the VRP data | \*-----------------------------------------------------------------------*/ PVM_FUNC(r_bufid, pvm_recv(-1, ROUTE_NINS_VRP_DATA)); PVM_FUNC(info, pvm_upkbyte((char *)tours, sizeof(best_tours), 1)); tour = p->cur_tour->tour = (_node *) calloc (p->vertnum, sizeof(_node)); PVM_FUNC(info, pvm_upkbyte((char *)tour, (p->vertnum)*sizeof(_node), 1)); numroutes = p->cur_tour->numroutes; starter = (int *) calloc (numroutes, sizeof(int)); route_info = p->cur_tour->route_info = (route_data *) calloc (numroutes+1, sizeof(route_data)); PVM_FUNC(r_bufid, pvm_recv(-1, ROUTE_NINS_START_RULE)); PVM_FUNC(info, pvm_upkint(&start, 1, 1));/*receive the start rule*/ if (start != FAR_INS) srand(start); /*if the start rule is random, then*\ \*initialize the random number gen.*/ starters(p, starter, route_info, start);/*generate the route starters for*\ \*all the clusters. */ /*-----------------------------------------------------------------------*\ | Allocate arrays | \*-----------------------------------------------------------------------*/ nbtree = (neighbor *) malloc (p->vertnum * sizeof(neighbor)); intour = (int *) calloc (p->vertnum, sizeof(int)); /*-----------------------------------------------------------------------*\ | Find the nearest insertion tour from 'starters' | \*-----------------------------------------------------------------------*/ for (cur_route=1; cur_route<=numroutes; cur_route++){ /*---------------------------------------------------------------------*\ | The first part of this loop adds the starter and the nearest node to | | it into the route to initialize it. Then a function is called | | which inserts the rest of the nodes into the route in nearest | | insert order. | \*---------------------------------------------------------------------*/ if (route_info[cur_route].numcust <= 1) continue; cost = 0; last = 0; intour[0] = 0; intour[starter[cur_route-1]] = IN_TOUR; ni_insert_edges(p, starter[cur_route-1], nbtree, intour, &last, tour, cur_route); nearnode = closest(nbtree, intour, &last); intour[nearnode] = IN_TOUR; ni_insert_edges(p, nearnode, nbtree, intour, &last, tour, cur_route); tour[starter[cur_route-1]].next = nearnode; tour[nearnode].next = starter[cur_route-1]; if (starter[cur_route - 1] == 0) route_info[cur_route].first = route_info[cur_route].last = nearnode; if (nearnode == 0) route_info[cur_route].first = route_info[cur_route].last = starter[cur_route-1]; cost = 2 * ICOST(&p->dist, starter[cur_route-1], nearnode); cost = nearest_ins_from_to(p, tour, cost, 2, route_info[cur_route].numcust+1, starter[cur_route-1], nbtree, intour, &last, route_info, cur_route); route_info[cur_route].cost = cost; } tour[0].next = route_info[1].first; /*-------------------------------------------------------------------------*\ | This loop points the last node of each route to the first node of the next| | route. At the end of this procedure, the last node of each route is | | pointing at the depot, which is not what we want. | \*-------------------------------------------------------------------------*/ for (cur_route = 1; cur_route< numroutes; cur_route++) tour[route_info[cur_route].last].next = route_info[cur_route+1].first; cost = compute_tour_cost(&p->dist, tour); /*-----------------------------------------------------------------------*\ | Transmit the tour back to the parent | \*-----------------------------------------------------------------------*/ send_tour(tour, cost, numroutes, tours->algorithm, used_time(&t), parent, p->vertnum, 1, route_info); if ( nbtree ) free ((char *) nbtree); if ( intour ) free ((char *) intour); if ( starter) free ((char *) starter); free_heur_prob(p); }
/** * Description not yet available. * \param */ void adpvm_unpack(char * v,int n) { pvm_upkbyte(v,n,1); }
int recvFilterData(FilterData *fData) { int bufId; int i, l, toFilter; char *cwd = (char *)malloc(MAX_CWD_LENGTH+1); int num = 0; int *tids = (int *)malloc(sizeof(int)*MAXINSTANCES); char *filterName = (char *)malloc(MAX_FNAME_LENGTH); char *libName = (char *)malloc(MAX_LNAME_LENGTH); char *hostname = (char *)malloc(MAX_HNAME_LENGTH); char *labelStreamLibname = (char *)malloc(MAX_LNAME_LENGTH); int parentTid = pvm_parent(); #ifdef ATTACH // if im using attach i dont no if the // manager process is realy my father bufId = pvm_recv(-1, 0); int bytes, msgtag,tid; pvm_bufinfo(bufId, &bytes, &msgtag, &tid ); printf("recvFilterData: bytes = %d msgtag = %d tid = %d\n", bytes, msgtag, tid); #else //We receive one message with all data in it bufId = pvm_recv(parentTid, 0); #endif //get the current working directory pvm_upkint(&l, 1, 1); pvm_upkbyte(cwd, l, 1); cwd[l] = '\0'; #ifdef DEBUG printf("cwd = %s\n",cwd); #endif // filter id, useful for debugging pvm_upkint(&num, 1, 1); setFDIdFilter(fData, num); // get my rank pvm_upkint(&num, 1, 1); setFDRank(fData, num); // total number of instances of this filter pvm_upkint(&num, 1, 1); setFDNumInstances(fData, num); // get my brothers tids pvm_upkint(tids, num, 1); setFDTids(fData, tids); #ifdef ATTACH // getting my parent Tid because if i'm a attached filter // i can be adopted for anyone.. so we do it for all filters.. // just to make the code easy to understand.. pvm_upkint(&parentTid, 1, 1); int attached; pvm_upkint(&attached, 1, 1); setFDAttached(fData, attached); #endif // if you are not using Attach the parentTid still the same // or its equal to pvm_parent() setFDParentTid(fData, parentTid); #ifdef BMI_FT int faultStatus, lastFilter; pvm_upkint(&faultStatus, 1, 1); setFDFaultStatus(fData, faultStatus); pvm_upkint(&lastFilter, 1, 1); setFDLastFilter(fData, lastFilter); #endif // filtername pvm_upkint(&l, 1, 1); pvm_upkbyte(filterName, l, 1); filterName[l] = '\0'; setFDName(fData, filterName); //machine declared memory: -1 autodetect, declared on XML pvm_upkint(&num, 1, 1); setFDMachineMem(fd, num); //number of brothers(+ me) I have on this machine, useful for memory management pvm_upkint(&num, 1, 1); setFDNumLocalInstances(fd, num); #ifdef VOID_INST char instDir[MAX_IDIR_LENGTH]; pvm_upkint(&l, 1, 1); pvm_upkbyte(instDir, l, 1); instDir[l] = '\0'; setFDInstDir(fd, instDir); #endif // receives shared lib name pvm_upkint(&l, 1, 1); pvm_upkbyte(libName, l, 1); libName[l] = '\0'; setFDLibName(fData, libName); /*if (loadFDLibFunctions(fData) == -1){ char msg[1000]; sprintf(msg, "could not load shared library %s", libName); pvm_initsend(PvmDataRaw); pvm_pkbyte(msg, strlen(msg), 1); pvm_send(pvm_parent(), MSGT_FERROR); return -1; }*/ // set hostname gethostname(hostname, MAX_HNAME_LENGTH); setFDHostName(fData, hostname); // data received till now fprintf(stderr,"filter %s (rank: %d): pvm_tid:%d hostname:%s\n", fData->name, fData->myRank, pvm_mytid(), fData->hostName); //port data //Receive numOutputs pvm_upkint(&num, 1, 1); setFDNumOutputs(fData, num); //receive numInputs pvm_upkint(&num, 1, 1); setFDNumInputs(fData, num); // for each OutputPort for(i = 0; i < fData->numOutputPorts; i++) { int nOutHosts = 0, tag = 0; int numToSend; int *outTids = NULL; int firstInstanceToWrite; char *portName = (char *)malloc(MAX_PTNAME_LENGTH + 1); char *writePolicyName = (char *)malloc(100); writePolicy_t wp; OutputPort *outputPort; pvm_upkint(&numToSend, 1, 1); //now we can create the port outputPort = createOutputPort(numToSend); //port data pvm_upkint(&l, 1, 1); pvm_upkbyte(portName, l, 1); //portname portName[l] = '\0'; setOPName(outputPort, portName); pvm_upkint(&tag, 1, 1); //get tag setOPTag(outputPort, tag); for( toFilter = 0; toFilter < numToSend; toFilter++ ) { pvm_upkint(&nOutHosts, 1, 1); //number of tids it is connected setOPNumDestinations(outputPort, toFilter, nOutHosts); outTids = (int *) malloc(sizeof(int)*nOutHosts); pvm_upkint(outTids, nOutHosts, 1); //get tids setOPTidsDestinations(outputPort, toFilter, outTids); pvm_upkint(&l, 1, 1); pvm_upkbyte(writePolicyName, l, 1); // get write policy writePolicyName[l] = '\0'; wp = getWritePolicyByName(writePolicyName); setOPWritePolicy(outputPort, toFilter, wp); // get LS sharedlib if policy is LS if (wp == LABELED_STREAM ){ pvm_upkint(&l, 1, 1); pvm_upkbyte(labelStreamLibname, l, 1); labelStreamLibname[l] = '\0'; //set output port library name setOPLibName(outputPort, toFilter, labelStreamLibname); //load output port library for ls if (loadOPLSData(outputPort, toFilter) == -1 ){ char msg[1000]; sprintf(msg, "could not load LS shared library %s", labelStreamLibname); pvm_initsend(PvmDataRaw); pvm_pkbyte(msg, strlen(msg), 1); pvm_send(pvm_parent(), MSGT_FERROR); return -1; } } else if (wp == MULTICAST_LABELED_STREAM) { pvm_upkint(&l, 1, 1); pvm_upkbyte(labelStreamLibname, l, 1); labelStreamLibname[l] = '\0'; //set output port library name setOPLibName(outputPort, toFilter, labelStreamLibname); //load output port library for ls if (loadOPMLSData(outputPort, toFilter) == -1){ char msg[1000]; sprintf(msg,"could not load MLS shared library %s", labelStreamLibname); pvm_initsend(PvmDataRaw); pvm_pkbyte(msg, strlen(msg), 1); pvm_send(pvm_parent(), MSGT_FERROR); return -1; } } else { //if not LS, we needa know who will be the first instance to receive msgs pvm_upkint(&firstInstanceToWrite, 1, 1); //the first instance to write setOPNextToSend(outputPort, toFilter, firstInstanceToWrite); } } // and we finally add the port to our filterData structure addFDOutputPort(fData, outputPort); //free pointers free(outTids); free(portName); free(writePolicyName); } // foreach InputPort for(i = 0; i < fData->numInputPorts; i++) { int nInHosts = 0; int *inTids = NULL; int inTag; char portName[MAX_PTNAME_LENGTH + 1]; int l; InputPort *inputPort = createInputPort(); //get the portName pvm_upkint(&l, 1, 1); pvm_upkbyte(portName, l, 1); portName[l] = '\0'; setIPName(inputPort, portName); // receive the number of tids of this port pvm_upkint(&nInHosts, 1, 1); // number of instances connected to this port setIPNumSources(inputPort, nInHosts); // get the tids inTids = (int *) malloc(sizeof(int)*nInHosts); pvm_upkint(inTids, nInHosts, 1); //get tids setIPTidsSources(inputPort, inTids); free(inTids); pvm_upkint(&inTag, 1, 1); //the port tag setIPTag(inputPort, inTag); int hasLabel; pvm_upkint(&hasLabel, 1, 1); toFilter = 0; // if it receives from a LS or MLS we have to have the library with // the function that extracts the label if (hasLabel){ setIPLS(inputPort, 1); pvm_upkint(&l, 1, 1); pvm_upkbyte(labelStreamLibname, l, 1); labelStreamLibname[l] = '\0'; //set output port library name setIPLibName(inputPort, toFilter, labelStreamLibname); //load output port library for ls if (loadIPLSData(inputPort, toFilter) == -1 ){ char msg[1000]; sprintf(msg, "could not load LS shared library %s", labelStreamLibname); pvm_initsend(PvmDataRaw); pvm_pkbyte(msg, strlen(msg), 1); pvm_send(pvm_parent(), MSGT_FERROR); return -1; } } //finally add the port to our filterData addFDInputPort(fData, inputPort); } free(tids); free(hostname); free(filterName); free(libName); free(labelStreamLibname); return 1; }
void upkjobinfo_done(jobinfo *j) { pvm_upkint(&j->jid,3,1); // jid, tid, pjid pvm_upkint(&j->s.k,4,1); // k,o,r,rd pvm_upkbyte(j->s.m,MAXMVC,1); }
int ReceiveMessage(message* m, msg_type in_type) { int stat = pvm_recv(-1, in_type); pvm_upkbyte((char*)m, sizeof(message), 1); return stat; }
/*--------------------------------------------------------------------------- ** MBUSRECV -- Receive a message from another application. We are normally ** called from a program i/o handler while waiting for messages. */ int mbusRecv (int *from_tid, int *to_tid, int *subject, char **host, char **msg) { int bufid, info; int tid = *to_tid; int tag = *subject; int nbytes=0, type=0, source=0; int host_len, msg_len, get_ack=0; char dummy; if (MB_DEBUG) printf("mbRecv: tid = %d tag = %d\n", tid, tag); /* On entry, to_tid/subject may be specified as '-1' to indicate that we * will accept a message from any host for any reason. We unpack the * information from the sender as part of the message and fill it in * on the way out. The caller must remember to reset this value! * * The host/msg pointers may be allocated here and will contain the * data from the message. The caller is responsible for freeing * these pointers when it's done with them, passing in a static array * will segfault. if ((bufid = pvm_nrecv (-1, -1)) < 0) { */ if ((bufid = pvm_recv (tid, tag)) < 0) { switch (bufid) { case PvmBadParam: fprintf (stderr, "mbRecv: %d fails, bad tid/msgtag\n", tid); return (ERR); case PvmSysErr: fprintf (stderr, "mbRecv: %d fails, pvmd not responding\n", tid); return (ERR); } } if (USE_ACK) { info = pvm_upkint (&get_ack, 1, 1); /* Ack required? */ } else { get_ack = 0; info = pvm_upkint (&get_ack, 1, 1); /* Ack required? */ } info = pvm_upkint (from_tid, 1, 1); /* sender */ info = pvm_upkint (to_tid, 1, 1); /* target recipient */ info = pvm_upkint (subject, 1, 1); /* subject */ info = pvm_upkint (&host_len, 1, 1); /* len of host name */ if (host_len > 0) { /* host name (optional) */ *host = calloc (1, host_len); info = pvm_upkbyte (*host, host_len-1, 1); info = pvm_upkbyte (&dummy, 1, 1); } else *host = NULL; info = pvm_upkint (&msg_len, 1, 1); /* len of msg body */ if (msg_len > 0) { /* msg body */ *msg = calloc (1, msg_len); info = pvm_upkbyte (*msg, msg_len-1, 1); info = pvm_upkbyte (&dummy, 1, 1); } else *msg = NULL; if ((info = pvm_bufinfo (bufid, &nbytes, &type, &source)) >= 0) { if (MB_DEBUG) { printf ("\nrecv: %d bytes from %d about %d\n", nbytes,source,type); printf( "mbRecv(%d): from:%d to:%d subj:%d host:'%s'(%d) msg='%s'(%d)\n", get_ack, *from_tid, *to_tid, *subject, *host, host_len, *msg, msg_len); } } /* Return ACK to the sender if requested. */ return (get_ack ? mbusAck (source, type) : OK); }
/// user function:add a new query to a pipeline of filters. Called by user manager runs this. /// \param layout System Layout. /// \param work Buffer with a Unit of Work (UoW) /// \param workSize Unit of Work Size (UoW) /// \return Zero on success, -1 on error. int appendWork(Layout *layout, void *work, int workSize) { #ifdef NO_BARRIER // sends work for each filter pvm_initsend(PvmDataRaw); // First tell that is a mensage of WORK int msgType = MSGT_WORK; pvm_pkint(&msgType, 1, 1); //then attach the work to it pvm_pkbyte((char *)work, workSize, 1); // for each filter, send his work for(i = 0; i < layout->numFilters; i++) { FilterPlacement *pFilterP = &(layout->filters[i]->filterPlacement); // sends work to all filters of this set pvm_mcast(pFilterP->tids, pFilterP->numInstances, 0); } #else int i; int totalEows = 0, numEowsReceived; #ifdef ATTACH int totalAttachedFilters = 0; #endif int reconf = 0 /** should we reconfigure? */, remainingReconfs = 0; //how many times should we try? #ifdef VOID_INST #ifdef BMI_FT char instDir[MAX_IDIR_LENGTH]; sprintf(instDir, "%s/", INST_DIR); for (i=0; i < layout->numFilters-1; i++) { if (strlen(instDir) >= (MAX_IDIR_LENGTH - 3)) { //dont want to overflow this array fprintf(stderr, "%s %d: warning, instrumentation directory name too big, truncating to %s\n", __FILE__, __LINE__, instDir); break; } sprintf(instDir, "%s%d-", instDir, layout->filters[i]->filterPlacement.numInstances); } sprintf(instDir, "%s%d", instDir, layout->filters[layout->numFilters-1]->filterPlacement.numInstances); char managerLogFile[MAX_IDIR_LENGTH+20]; sprintf(managerLogFile, "%s/manager.time", instDir); FILE *fp = fopen(managerLogFile, "w"); struct timeval tv; struct timezone tz; //not used //get the time gettimeofday(&tv, &tz); if(fp != NULL) fprintf(fp, "1 %ld %ld\n", tv.tv_sec, tv.tv_usec); #endif #endif //before sending, we check if we received any filter error int bufid = pvm_probe(-1, MSGT_FERROR); if (bufid != 0) { int bytes, tag, tid; char *msg; pvm_bufinfo(bufid, &bytes, &tag, &tid); msg = (char*)malloc(bytes+1); pvm_recv(tid, MSGT_FERROR); pvm_upkbyte(msg, bytes, 1); msg[bytes] = '\0'; fprintf(stderr, "Manager.c: Error, received death notification\n"); fprintf(stderr, "Manager.c: %s\n", msg); free(msg); killAllFilters(layout); exit(-1); } printf("Manager.c: starting work...\n"); // number of EOWs we expect to receive for(i = 0; i < layout->numFilters; i++) { totalEows += layout->filters[i]->filterPlacement.numInstances; #ifdef ATTACH if(layout->filters[i]->attached) { totalAttachedFilters += layout->filters[i]->filterPlacement.numInstances; } // TODO:TOSCO::: if(layout->filters[i]->attach) return 0; #endif } //we stay in this loop while we have to reconfigure //usually, this will be only one time, unless a we get some reconf message do { // sends work for each filter pvm_initsend(PvmDataRaw); int msgType; #ifdef VOID_FT if(!reconf) { #endif // First tell that is a mensage of WORK msgType = MSGT_WORK; #ifdef VOID_FT } else { // one fault has occurred msgType = MSGT_FT; } #endif pvm_pkint(&msgType, 1, 1); //then attach the work to it pvm_pkbyte((char *)work, workSize, 1); reconf = 0; //we are optimistic, always expect to not reconfigure // for each filter, send his work for(i = 0; i < layout->numFilters; i++) { FilterPlacement *pFilterP = &(layout->filters[i]->filterPlacement); // sends work to all filters of this set pvm_mcast(pFilterP->tids, pFilterP->numInstances, 0); } /* TaskIdList *finalTaskIdList = NULL, *currentTaskIdList; int filtersThatUseTasks = 0; // Manager receives filter's terminated tasks list for(i = 0; i < layout->numFilters; i++) { FilterPlacement *pFilterP = &(layout->filters[i]->filterPlacement); #ifdef ATTACH // if this filter is of the attached // type i dont need worry about use Task // if(layout->filters[i]->attached)continue; #endif for(j = 0; j < pFilterP->numInstances; j++) { int instanceUseTasks = -1; // Get is this filter use tasks pvm_recv(pFilterP->tids[j], 0); pvm_upkint(&instanceUseTasks, 1, 1); layout->filters[i]->useTasks = instanceUseTasks; #ifdef VOID_FT if (instanceUseTasks) { currentTaskIdList = (TaskIdList *)unpackTaskIdList(); // Para fazer intersecao, gerente ordenar? as listas de tarefas recebidas e utilizar? a fun??o meet() do CrazyMiner/ID3. qsort(currentTaskIdList->vetor, currentTaskIdList->size, sizeof(int), compareTaskId); if(finalTaskIdList == NULL) { finalTaskIdList = currentTaskIdList; } else { // Manager makes the intersection of all finished tasks lists finalTaskIdList = taskIdListIntersection(finalTaskIdList, currentTaskIdList); taskIdListDestroy(currentTaskIdList); } } #endif } // for if (layout->filters[i]->useTasks) filtersThatUseTasks++; } // Gerente devolve resultado das intersecoes para todas as instancias de todos os filtros. for(i = 0; i < layout->numFilters; i++) { FilterPlacement *pFilterP = &(layout->filters[i]->filterPlacement); #ifdef ATTACH // if this filter is of the attached // type i dont need worry about use Task //TODO if(layout->filters[i]->attached)continue; #endif int needForwardTaskMessages = 1; if (filtersThatUseTasks < 2) needForwardTaskMessages = 0; #ifdef VOID_FT if (layout->filters[i]->useTasks) { // Send if they should forward task messages // and pigback :-) the final task id list pvm_initsend(PvmDataDefault); pvm_pkint(&needForwardTaskMessages, 1, 1); packTaskIdList(finalTaskIdList); pvm_mcast(pFilterP->tids, pFilterP->numInstances, 0); } else { #endif // Only send if they should forward task messages pvm_initsend(PvmDataDefault); pvm_pkint(&needForwardTaskMessages, 1, 1); pvm_mcast(pFilterP->tids, pFilterP->numInstances, 0); #ifdef VOID_FT } #endif } taskIdListDestroy(finalTaskIdList); */ //now we receive the EOWs numEowsReceived = 0; //now we expect to receive EOW or errors while(numEowsReceived < totalEows) { //we are open to receive anything from anyone here //all messages to the manager should be tagged, so we now their type int szMsg = -1; int inst_tid = -1; int msgTag = -1; int bufid = pvm_recv(-1, -1); pvm_bufinfo(bufid, &szMsg, &msgTag, &inst_tid); switch (msgTag) { case (MSGT_EOW): { //received EOW, expect this usually int instance = -1; FilterSpec *pFilter = NULL; getFilterByTid(layout, inst_tid, &pFilter, &instance); if ((pFilter != NULL) && (instance != -1)) { printf("Manager.c: EOW received from %s, instance %d\n", pFilter->name, instance); } else { fprintf(stderr, "Manager.c: unknown EOW received! Shouldnt get here!\n"); } numEowsReceived++; break; } case (MSGT_AEXIT): case (MSGT_FERROR): { //someone called dsExit or system error at the filter side //common cause for this are library not found, wrong initscritpt etc char *message = (char*)malloc(sizeof(char)*szMsg+1); pvm_upkbyte(message, szMsg, 1); message[szMsg] = '\0'; //the filter and the instance FilterSpec *fp = NULL; int instance = -1; getFilterByTid(layout, inst_tid, &fp, &instance); if (msgTag == MSGT_AEXIT) { printf("Manager.c: Filter %s, instance %d(tid %x) called dsExit: %s\n", fp->name, instance, inst_tid, message); } else { printf("Manager.c: Filter %s error, instance %d(tid %x) called exit: %s\n", fp->name, instance, inst_tid, message); } free(message); // kill all instances killAllFilters(layout); exit(-1); break; } //task exited or host crashed case (MSGT_TEXIT): case (MSGT_HDEL): { //we only reconfigure a fixed number of times if (remainingReconfs <= 0) { //max number of reconfigurations reached... aborting fprintf(stderr, "Manager.c: max reconfigurations reached, aborting...\n"); fflush(stderr); fprintf(stdout, "Manager.c: max reconfigurations reached, aborting...\n"); fflush(stdout); reconf = 0; // kill all instances which might be alive killAllFilters(layout); exit(-1);; } #ifdef BMI_FT gettimeofday(&tv, &tz); fprintf(fp, "2 %ld %ld\n", tv.tv_sec, tv.tv_usec); #endif remainingReconfs--; reconf = 1; // In case of pvm notification, inst_tid will be t80000000 int notifiesRecv = 1; // We are receiving the first death notification int deadFilterTid = -1; FilterSpec *pFilter = NULL; int instanceDead = -1; // Get the tid and name of the dead filter int info = pvm_upkint(&deadFilterTid, 1, 1); if (info < 0) pvm_perror("Manager.c: error calling pvm_upkint"); //discover which filter died getFilterByTid(layout, deadFilterTid, &pFilter, &instanceDead); if((pFilter != NULL) && (instanceDead != -1)) { if (msgTag == MSGT_TEXIT) { fprintf(stderr, "Manager.c: filter %s: instance %d (tid t%x) of %d is dead!!!\n", pFilter->name, instanceDead, deadFilterTid, pFilter->filterPlacement.numInstances); } else { fprintf(stderr, "Manager.c: filter %s: instance %d (tid t%x) of %d machine's crashed!!!\n", pFilter->name, instanceDead, deadFilterTid, pFilter->filterPlacement.numInstances); } } printf("Manager.c: starting reconfiguration\n"); // kill all filters in the pipeline killAllFilters(layout); if (msgTag == MSGT_HDEL) { //int his case, host died, so we must change layout replaceCrashedHost(layout, pFilter, instanceDead); } #ifdef ATTACH if (pFilter->attached) { // In this case, all filters that were killed have to notify // their dead. notifiesRecv = 0; } #endif //Flush the streams //receive all messages which are about to arrive till we get the death notification //pvm order should garantee this #ifdef ATTACH while (notifiesRecv < (totalEows - totalAttachedFilters)) { #else while (notifiesRecv < totalEows) { #endif int newMsgTag = -1; bufid = pvm_recv(-1, MSGT_TEXIT); info = pvm_bufinfo(bufid, NULL, &newMsgTag, &inst_tid); info = pvm_upkint(&deadFilterTid, 1, 1); if (info < 0) pvm_perror("Manager.c: error calling pvm_upkint"); fprintf(stderr, "Manager.c: WARNING: received notification (tag %d) about pvm tid t%x death\n", newMsgTag, deadFilterTid); notifiesRecv++; } #ifdef ATTACH if(pFilter->attached) { notifiesRecv = 1; } else { notifiesRecv = 0; } // Receive all EOW messages from the attached filters. while(notifiesRecv < totalAttachedFilters) { int newMsgTag = -1; bufid = pvm_recv(-1, MSGT_EOW); info = pvm_bufinfo(bufid, NULL, &newMsgTag, &inst_tid); if (info < 0) pvm_perror("Manager.c: error calling pvm_upkint"); fprintf(stderr, "Manager.c: WARNING: received EOW (tag %d) from pvm tid t%x\n", newMsgTag, inst_tid); notifiesRecv++; } #endif // probes for remaining machine crash notifications while (pvm_probe(-1, MSGT_HDEL) > 0) { int newMsgTag = -1; bufid = pvm_recv(-1, MSGT_HDEL); info = pvm_bufinfo(bufid, NULL, &newMsgTag, &inst_tid); info = pvm_upkint(&deadFilterTid, 1, 1); if (info < 0) pvm_perror("Manager.c: error calling pvm_upkint"); fprintf(stderr, "Manager.c: WARNING: received notification (tag %d) about pvm tid t%x machine's crash\n", newMsgTag, deadFilterTid); // Replace the died host FilterSpec *pCrashedFilter = NULL; int crashedInstance = -1; getFilterByTid(layout, deadFilterTid, &pCrashedFilter, &crashedInstance); replaceCrashedHost(layout, pCrashedFilter, crashedInstance); } #ifdef BMI_FT updateAllFiltersFaultStatus(layout, FAULT_OTHER_FILTER_INST); pFilter->faultStatus = instanceDead; #endif //spawn all filters again spawnAllFilter(layout); #ifdef ATTACH // Verifies if the dead filter is an attached. If yes, spawn it. if(pFilter->attached == 1) { spawnOneAttachedInstance(layout, pFilter, instanceDead); } #endif resetStreams(layout); //resend the data sendFiltersData(layout); //start all over again numEowsReceived = 0; #ifdef BMI_FT gettimeofday(&tv, &tz); fprintf(fp, "3 %ld %ld\n", tv.tv_sec, tv.tv_usec); #endif break; } #ifdef VOID_TERM // One filter instance detected local termination case (MSGT_LOCALTERM): { int localTermTag; // filter instance local termination tag pvm_upkint(&localTermTag, 1, 1); verifyGlobalTermination(inst_tid, localTermTag); break; } #endif default: { fprintf(stderr, "Manager.c: error receiving EOW, unknown tag!!!\n"); } } //end switch message tag if((msgTag == MSGT_TEXIT) || (msgTag == MSGT_HDEL)) { // work should be sent again break; } } //end receiving eows } while(reconf == 1); //leave this loop if we will not reconfigure #ifdef BMI_FT gettimeofday(&tv, &tz); fprintf(fp, "4 %ld %ld\n", tv.tv_sec, tv.tv_usec); #endif printf("Manager.c: Work ended\n\n"); return 0; #endif } /// Finalize a Void pipeline. Only manager runs this. int finalizeDs(Layout *layout) { #ifdef NO_BARRIER #else int i; // Envia eof para todos os filtros // Primeiro envia se eh work (WORK) ou EOF (END_OF_FILTER) pvm_initsend(PvmDataRaw); int tipo_msg = MSGT_EOF; pvm_pkint(&tipo_msg, 1, 1); //sends the EOF message for all instances of the filter for(i = 0; i < layout->numFilters; i++) { FilterPlacement *pFilterP = &(layout->filters[i]->filterPlacement); #ifdef ATTACH if(layout->filters[i]->attach) continue;// this filter cant not receive a EOF because // it needs still runnig #endif pvm_mcast(pFilterP->tids, pFilterP->numInstances, 0); } destroyLayout(layout); pvm_exit(); return 0; #endif }
render_frame() { pixel Pixel_colour ; /* pixel colour values */ int X_counter ; /* X axis counter */ int Y_counter ; /* Y axis counter */ int Block_counter ; /* block section counter */ int Worker_counter ; /* counter for the number of workers done */ double Block_angle ; /* angle between blocks */ viewer Viewpoint ; /* the viewpoint of the user */ /* copy the users viewpoint into the working variable */ Viewpoint.X=User.X ; Viewpoint.Y=User.Y ; Viewpoint.Z=User.Z ; Viewpoint.X_angle=User.X_angle ; Viewpoint.Y_angle=User.Y_angle ; Viewpoint.Z_angle=User.Z_angle ; /* set up the ray angles */ Block_angle=(X_view_angle/User_view.X_size)*Pixel_buffer_width ; Viewpoint.Z_angle=Viewpoint.Z_angle-(X_view_angle/2)-((1/360)*2*M_PI) ; for (Block_counter=0;Block_counter<Number_of_workers;Block_counter++) { /* send out work to worker */ pvm_initsend (PvmDataDefault) ; pvm_pkdouble(&Viewpoint.X,1,1); pvm_pkdouble(&Viewpoint.Y,1,1) ; pvm_pkdouble(&Viewpoint.Z,1,1) ; pvm_pkdouble(&Viewpoint.X_angle,1,1) ; pvm_pkdouble(&Viewpoint.Y_angle,1,1) ; pvm_pkdouble(&Viewpoint.Z_angle,1,1) ; pvm_send (Worker_tids[Block_counter],WORK) ; /* set the viewpoint for the next one */ Viewpoint.Z_angle=Viewpoint.Z_angle+Block_angle ; } /* end of for loop */ /* finished sending the data */ /* set the number of workers finished to zero */ Worker_counter=0 ; /* get the data back */ while ( Worker_counter < Number_of_workers) { for (Block_counter=0;Block_counter<Number_of_workers;Block_counter++) { if (pvm_probe (Worker_tids[Block_counter],DATA)) /* wait for reply */ { pvm_recv (Worker_tids[Block_counter],DATA) ; pvm_upkbyte (Pixel_buffer,Pixel_buffer_size,1) ; /* increment the counter for the number of workers that have finished */ Worker_counter=Worker_counter+1 ; /* copy the pixel to the image buffer */ for (X_counter=0 ; X_counter<Pixel_buffer_width ; X_counter++ ) { for (Y_counter=0; Y_counter<User_view.Y_size ; Y_counter++ ) { /* copy pixel data */ Image_buffer [(Y_counter*User_view.X_size*3)+ (X_counter*3)+ (Block_counter*Pixel_buffer_width*3)+ 0] = Pixel_buffer[(Y_counter*Pixel_buffer_width*3)+ (X_counter*3)+ 0] ; Image_buffer[(Y_counter*User_view.X_size*3)+ (X_counter*3)+ (Block_counter*Pixel_buffer_width*3)+ 1] = Pixel_buffer[(Y_counter*Pixel_buffer_width*3)+ (X_counter*3)+ 1] ; Image_buffer[(Y_counter*User_view.X_size*3)+ (X_counter*3)+ (Block_counter*Pixel_buffer_width*3)+ 2] = Pixel_buffer[(Y_counter*Pixel_buffer_width*3)+ (X_counter*3)+ 2] ; /* end Y loop */ } /* end X loop */ } } /* end the if */ } /* end the while loop */ /* end drawing code */ } /* copy the data to the window */ glDrawPixels(User_view.X_size,User_view.Y_size,GL_RGB, GL_UNSIGNED_BYTE,Image_buffer) ; /* flush the graphics pipeline */ glFlush(); }