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); }
int main(int argc, char **argv){ int bufid,ptid; NodoBusqueda nodo_inicial, *resul; int exito=1,fracaso=0; ptid=pvm_parent(); bufid=pvm_recv(ptid,_TIPOMSG_NODOBUSQUEDA); pvm_upkNodoBusqueda(&nodo_inicial); resul=resolverRecursivo(nodo_inicial); if(resul){ //enviamos que tuvimos exito, para luego enviar el NodoBusqueda pvm_initsend(PvmDataDefault); pvm_pkint(&exito,1,1); pvm_send(ptid,_TIPOMSG_EXITOFRACASO); pvm_initsend(PvmDataDefault); pvm_pkNodoBusqueda(resul); pvm_send(ptid,_TIPOMSG_NODOBUSQUEDA); }else{ //enviar mensaje de que no se alcanzo solucion por esta rama pvm_initsend(PvmDataDefault); pvm_pkint(&fracaso,1,1); pvm_send(ptid,_TIPOMSG_EXITOFRACASO); } pvm_exit(); exit(0); }
/* steal jobs from other workers */ jobinfo* steal() { int i,w,b; int len,tid,tag; jobinfo *j; w = random() % nw; for (;;) { if (wtid[w] != stid) { pvm_initsend(0); pvm_send(wtid[w],TAG_REQUEST); for (;;) { b = pvm_recv(-1,-1); pvm_bufinfo(b,&len,&tag,&tid); if (tag == TAG_JOB || tag == TAG_NO_JOB) break; else if (tag == TAG_REQUEST) { pvm_initsend(0); pvm_send(tid,TAG_NO_JOB); } else p_handle(b); } if (tag == TAG_JOB) break; } if (++w == nw) w = 0; } j = malloc(sizeof(jobinfo)); upkjobinfo_active(j); ha_lookup(ha,&j->s.da,&j->s.p); return j; }
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(); }
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; }
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; } }
void gen_x(int num) { copy_request("get_mul", 1) ; sleep(1) ; int mul_tid = get_tid("get_mul_copy", 1) ; int mynum = copynum(myname, mytid) ; int mul_inpnum ; if(mynum == 1) mul_inpnum = 0; else if(mynum == 2) mul_inpnum = 1 ; else { printf("[%s][gen_x]:my copy num=%d, but conditions are only for 1 and 2\n",myname, mynum) ; pvm_exit() ; exit(0) ; } for(int i = 0 ; i < num; ++i) { pvm_initsend(PvmDataDefault) ; pvm_pkint(&mul_inpnum, 1, 1) ; int num = i + 1 ; pvm_pkint(&num, 1 ,1) ; pvm_send(mul_tid, i) ; } return ; }
// To initialize this genetic algorithm, we make sure all of our spawns are // not evolving then we tell them all to initialize themselves. Then we wait // and copy their populations into our own. Update our stats based upon the // harvested populations. void PVMDemeGA::initialize(unsigned int seed) { GARandomSeed(seed); if(_mid == 0) return; #ifdef DEBUG cerr << "sending initialize command to slaves...\n"; #endif for(int j=0; j<_ntid; j++) { _status = pvm_initsend(PvmDataDefault); _status = pvm_send(_tid[j], MSG_INITIALIZE); } collect(); for(int i=0; i<_ntid; i++) { pstats[i].reset(*deme[i]); pop->individual(i).copy(deme[i]->best()); } pop->touch(); stats.reset(*pop); }
int main(int argc, char **argv){ NodoBusqueda nodo_problema; int mintareas=4, cantidad_tareas, numt, *tids=NULL,i; GList *tareas, *tarptr; NodoBusqueda solucion; int problema[_SUDOK_FILAS][_SUDOK_COLUMNAS] = { {1,0,0,0,0,7,0,9,0}, {0,3,0,0,2,0,0,0,8}, {0,0,9,6,0,0,5,0,0}, {0,0,5,3,0,0,9,0,0}, {0,1,0,0,8,0,0,0,2}, {6,0,0,0,0,4,0,0,0}, {3,0,0,0,0,0,0,1,0}, {0,4,0,0,0,0,0,0,7}, {0,0,7,0,0,0,3,0,0} }; inicializarMatrizAdyacencia(); nodo_problema= nodoInicial(problema); tareas=generarTareas(nodo_problema,mintareas); cantidad_tareas = g_list_length(tareas); tids=malloc(sizeof(int)*cantidad_tareas); numt=pvm_spawn("sudokuterm",NULL,0,"",cantidad_tareas,tids); if(numt<cantidad_tareas){ fprintf(stderr, "ERROR. sudokuhub: no se pudo hacer spawn de todas las tareas"); exit(1); } //iteramos sobre las tareas y les pasamos los datos tarptr=g_list_first(tareas); for(i=0;i<cantidad_tareas;i++){ pvm_initsend(PvmDataDefault); pvm_pkNodoBusqueda((NodoBusqueda*)(tarptr->data)); pvm_send(tids[i],_TIPOMSG_NODOBUSQUEDA); tarptr=tarptr->next; } //esperamos las respuestas y velamos por una solucion for(i=0;i<cantidad_tareas;i++){ int exitofracaso,j; pvm_recv(tids[i],_TIPOMSG_EXITOFRACASO); pvm_upkint(&exitofracaso,1,1); if(exitofracaso==1){ pvm_recv(tids[i],_TIPOMSG_NODOBUSQUEDA); pvm_upkNodoBusqueda(&solucion); printf("\nSE ENCONTRO UNA SOLUCION\n"); printNodoBusqueda(&solucion); for(j=0;j<cantidad_tareas;j++) pvm_kill(tids[j]); pvm_exit(); exit(0); } } printf("\nNO SE ENCONTRO NINGUNA SOLUCION\n"); return 0; }
void send_kill(int tid) { int bufid; bufid = pvm_initsend(PvmDataDefault); pvm_send(tid,2); pvm_freebuf(bufid); }
void mcast_accept_msg(struct state_info info) { char diag[200]; GQueue *waiting_req_q = (*info.my_lift_number == LIFT_1) ? info.waiting_req_q1 : info.waiting_req_q2; int len = g_queue_get_length(waiting_req_q); // diag_msg(info.mstrtid, info.mytid, "*** 0"); int *tids = malloc(len * sizeof(int)); int i = 0; sprintf(diag, "*** %d processes awaiting accepts", g_queue_get_length(info.waiting_req_q)); diag_msg(info.mstrtid, info.mytid, diag); while (!g_queue_is_empty(waiting_req_q)) { int *tid = g_queue_pop_head(waiting_req_q); int *sender_weight_ptr = g_hash_table_lookup(info.skiers_weights, tid); int *lift_free = (*info.my_lift_number == LIFT_1) ? info.lift1_free : info.lift2_free; *lift_free -= *sender_weight_ptr; tids[i] = *tid; i++; sprintf(diag, "*** mcast MSG_ACCEPT to %d [weight=%d]", *tid, *sender_weight_ptr); diag_msg(info.mstrtid, info.mytid, diag); } *info.local_clock += 1; int tag = MSG_ACCEPT; pvm_initsend(PvmDataDefault); pvm_pkint(&tag, 1, 1); pvm_pkint(&info.mytid, 1, 1); pvm_pkint(info.local_clock, 1, 1); pvm_mcast(tids, len, tag); sprintf(diag, "mcast MSG_ACCEPT to %d waiting processes [timestamp=%d]", len, *info.local_clock); diag_msg(info.mstrtid, info.mytid, diag); }
void sendEof(FilterPlacement *pFilterP) { pvm_initsend(PvmDataRaw); int tipo_msg = MSGT_EOF; pvm_pkint(&tipo_msg, 1, 1); //sends the EOF message for all instances of the filter pvm_mcast(pFilterP->tids, pFilterP->numInstances, 0); }
void SendTime(ArgStruct *p, double *t) { pvm_initsend( PVMDATA ); pvm_pkdouble( t, 1, 1 ); pvm_send( p->prot.othertid, 1); }
int main(int argc, char **argv) { int nproc, status; int tids[SLAVENUM], ok, mytid; nproc = pvm_spawn("sort_slave",0,PvmTaskDefault, "LINUX64",SLAVENUM, tids); printf("Master id %d\n", nproc ); //app for sorting do { status = 0; //if 0 - all done //if 1 - continue for(int i = 0; i < SLAVENUM; i++) { int slave_status ; pvm_recv (-1 , TAG_SLAVE); pvm_upkint(&slave_status, 1, 1); if (slave_status == 0) { status = 1; } } for (int i = 0; i < SLAVENUM; ++i) { pvm_initsend( PvmDataRaw ); pvm_pkint(&status, 1, 1); pvm_send( tids[i], TAG_MASTER ); } } while(status == 1); printf("Master end!"); pvm_exit(); }
void kill_workers () { printf ("INFO: Killing the workers\n") ; /* kill all the worker */ pvm_initsend(PvmDataDefault) ; pvm_mcast (Worker_tids,NUMBER_OF_WORKERS,KILL) ; /* close the window */ auxCloseWindow() ; /* exit pvm */ pvm_exit() ; /* free the pixel buffer */ free (Pixel_buffer) ; /* free the pixel buffer */ free (Image_buffer) ; /* free the worker tids */ free (Worker_tids) ; /* exit the program */ auxQuit() ; }
void SendRepeat(ArgStruct *p, int rpt) { pvm_initsend( PVMDATA ); pvm_pkint( &rpt, 1, 1 ); pvm_send( p->prot.othertid, 1); }
//@cindex sendOpNV void sendOpNV(OpCode op, GlobalTaskId task, int nelem, StgWord *datablock, int narg, ...) { va_list ap; int i; StgWord arg; va_start(ap, narg); traceSendOp(op, task, 0, 0); IF_PAR_DEBUG(trace, fprintf(stderr,"~~ sendOpNV: op = %x (%s), task = %x, narg = %d, nelem = %d", op, getOpName(op), task, narg, nelem)); pvm_initsend(PvmDataRaw); for (i = 0; i < narg; ++i) { arg = va_arg(ap, StgWord); IF_PAR_DEBUG(trace, fprintf(stderr,"~~ sendOpNV: arg = %d\n",arg)); PutArgN(i, arg); } arg = (StgWord) nelem; PutArgN(narg, arg); /* for (i=0; i < nelem; ++i) fprintf(stderr, "%d ",datablock[i]); */ /* fprintf(stderr," in sendOpNV\n");*/ PutArgs(datablock, nelem); va_end(ap); pvm_send(task, op); }
int SendReady(int tid) { int status = 0; status = pvm_initsend(PvmDataDefault); status = pvm_send(tid, MSG_READY); return status; }
/*-------------------------------------------------------------------------- ** MBUSACK -- Send an ACK to the message bus. **/ int mbusAck (int tid, int tag) { int ack = OK, info; pvm_initsend (PvmDataDefault); pvm_pkint (&ack, 1, 1); if (MB_DEBUG) fprintf (stderr, "Sending ACK to %d about %d: ", tid, tag); if ((info = pvm_send (tid, tag)) < 0) { switch (info) { case PvmBadParam: fprintf (stderr, "ACK to %d fails, bad tid or msgtag\n", tid); return (ERR); case PvmSysErr: fprintf (stderr, "ACK to %d fails, pvmd not responding\n", tid); return (ERR); case PvmNoBuf: fprintf (stderr, "ACK to %d fails, no active buffer\n", tid); return (ERR); } } if (MB_DEBUG) fprintf (stderr, "status=%d\n", info); return (info); }
int init_send(int data_packing) { int s_bufid; PVM_FUNC(s_bufid, pvm_initsend(PvmDataRaw)); return(s_bufid); }
/*Function: get_task * Given a taskid of the task requesting a new graph, a graph will be sent off of the queue * taskid: the id of the requesting task that needs a new graph */ void send_task(int taskid){ struct entry * task; task = TAILQ_FIRST(&head); TAILQ_REMOVE(&head, task, entries); /*Pop from the queue */ pvm_initsend(PvmDataDefault); /*Clear the buffer */ pvm_pkstr(task->graph_text); pvm_send(taskid, MSGTASK); }
//@cindex sendOp void sendOp(OpCode op, GlobalTaskId task) { traceSendOp(op, task,0,0); pvm_initsend(PvmDataRaw); pvm_send(task, op); }
/** used to notify manager some system error happened, and filter is aborting, * similar to AEXIT. * * @param msg Message to send describing the error * */ void sendFilterError( char *msg ){ pvm_initsend(PvmDataRaw); pvm_pkbyte(msg, strlen(msg), 1); pvm_send(pvm_parent(), MSGT_FERROR); return; }
int BBSClient::get(int key, int type) { #if debug printf("BBSClient::get %d type=%d\n", key, type); fflush(stdout); #endif pvm_initsend(PvmDataDefault); pvm_pkint(&key, 1, 1); return get(type)-1; // sent id+1 so cannot be mistaken for QUIT }
//@cindex sendOp1 void sendOp1(OpCode op, GlobalTaskId task, StgWord arg1) { traceSendOp(op, task, arg1,0); pvm_initsend(PvmDataRaw); PutArg1(arg1); pvm_send(task, op); }
void Semafor::sendAllow(int who, int turn) { //wyslanie zgody int type = SEM_ALLOW; pvm_initsend(PvmDataDefault); pvm_pkint(&mytid,1,1); pvm_pkint(&type,1,1); pvm_pkint(&turn,1,1); //tutaj ta tura to nie jest tura tego obiektu, to tura odebrana z zadania do wejscia do sekcji pvm_pkint(&my_id,1,1); pvm_send(who, my_id); }
int BBSClient::get(const char* key, int type) { #if debug printf("BBSClient::get |%s| type=%d\n", key, type); fflush(stdout); #endif int bufid, nbyte, msgtag, tid, index; pvm_initsend(PvmDataDefault); pvm_pkstr((char*)key); return get(type); }
// Send/receive the information we need to configure and initialize a genome. // In this case, send the length the genome should be, but we let the slave do // the initialization. If you wanted your slaves to read data from a file, you // could pass the filename here. int SendGenomeInitialize(GAGenome& g, int tid) { GA1DBinaryStringGenome& genome = (GA1DBinaryStringGenome&)g; int status = 0; int length = genome.length(); status = pvm_initsend(PvmDataDefault); status = pvm_pkint(&length, 1, 1); status = pvm_send(tid, MSG_GENOME_INITIALIZE); return status; }
// Send the specified number of individuals from the current population to // the specified task. int SendMigration(int toid, GAGeneticAlgorithm& ga, int count) { int status = 0; status = pvm_initsend(PvmDataDefault); status = pvm_pkint(&count, 1, 1); for(int i=0; i<count && status>=0; i++) status = PackIndividual(ga.population().best(i)); status = pvm_send(toid, MSG_INCOMING_MIGRATION); return status; }
// Send only the score of the genome to the specified task. int SendGenomeScore(GAGenome& g, int tid) { int status = 0; float score = g.score(); status = pvm_initsend(PvmDataDefault); status = pvm_pkfloat(&score, 1, 1); status = pvm_send(tid, MSG_GENOME_SCORE); return status; }