// Send the bits of the genome to the task that requested them. First we send // the number of bits, then we send the bits themselves. Note that we can // handle genomes of varying lengths with this setup. We also pack the score // and stuff that in as well (so that they don't have to do an eval at the // other end). If we did this as a member function we could save the hassle // of an extra copy of the bits... // Returns negative number (error code) if failure. int PackIndividual(GAGenome& g) { GA1DBinaryStringGenome& genome = (GA1DBinaryStringGenome&)g; static int* bits = 0; static int nbits = 0; int status = 0;; if(nbits < genome.length()){ nbits = genome.length(); delete [] bits; bits = new int [nbits]; } int length = genome.length(); for(int i=0; i<length; i++) bits[i] = genome.gene(i); status = pvm_pkint(&length, 1, 1); status = pvm_pkint(bits, length, 1); float score = g.score(); status = pvm_pkfloat(&score, 1, 1); return status; }
/* data packing functions */ void pkjobinfo_active(jobinfo *j) { pvm_pkint(&j->jid,6,1); // jid, tid, pjid, d, a, n pvm_pkint(&j->s.k,4,1); // k,o,r,rd pvm_pkbyte(&j->s.p,2+TPITS,1); pvm_pkbyte(j->s.m,MAXMVC,1); pvm_pkint(j->o,4*PITS,1); // o, js, ctid, cjid }
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); }
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 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 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 ; }
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); }
/** * Description not yet available. * \param */ void pvm_pack(const dvar_vector& _v) { dvar_vector& v =(dvar_vector&) _v; int imin=v.indexmin(); int imax=v.indexmax(); pvm_pkint(&imin,1,1); pvm_pkint(&imax,1,1); pvm_pkdouble(&(value(v(imin))),imax-imin+1,1); }
/** * Description not yet available. * \param */ void adpvm_pack(const ivector& _v) { ivector& v =(ivector&) _v; int imin=v.indexmin(); int imax=v.indexmax(); pvm_pkint(&imin,1,1); pvm_pkint(&imax,1,1); pvm_pkint(&(v(imin)),imax-imin+1,1); }
void PackFile (int fd) { int n; char buf[PACKFILEBUFFERSIZE]; while ((n = read (fd, buf, sizeof (buf))) > 0) { assert (! pvm_pkint (&n, 1, 1)); assert (! pvm_pkbyte (buf, n, 1)); } n = 0; assert (! pvm_pkint (&n, 1, 1)); }
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 PackBufferedTree (BufferedTreeT *bt, int support_stuff) { int i; /* { */ /* int i; */ /* fprintf (stderr, "packing tree:\n"); */ /* LoopBelow (i, bt->n_placed_taxa) */ /* fprintf (stderr, "%d %d %c\n", */ /* bt->placed_taxa_indices[i], */ /* bt->nodes[i].parent_index, */ /* bt->nodes[i].on_left? 'l': 'r'); */ /* } */ assert (! pvm_pkint (&bt->n_placed_taxa, 1, 1)); assert (! pvm_pkint ((int *)bt->nodes, bt->n_placed_taxa, 1)); assert (! pvm_pkint (bt->placed_taxa_indices, bt->n_placed_taxa, 1)); if (support_stuff) { SENTWITH++; assert (! pvm_pkint (&bt->n_supported_clades, 1, 1)); LoopBelow (i, bt->n_supported_clades) assert (! pvm_pkint (bt->supported_clades[i], BitVectorWords, 1)); assert (! pvm_pkint (&bt->supported_clades_hash, 1, 1)); } else { SENTWITHOUT++; bt->n_supported_clades = bt->supported_clades_hash = 0; } assert (! pvm_pkint (&bt->cost, 1, 1)); assert (! pvm_pkint (&bt->generation, 1, 1)); }
void Semafor::broadcastAcquire() { int i; int type = SEM_ACQUIRE; for (i=0;i<nproc;i++) { if (tids[i]!=mytid) { //wyslanie do kazdego procz siebie, bo po co pvm_initsend(PvmDataDefault); pvm_pkint(&mytid,1,1); pvm_pkint(&type,1,1); pvm_pkint(&tura,1,1); pvm_pkint(&my_id,1,1); pvm_send(tids[i], my_id); } } }
void Buffer::broadcast_update(int newval) { int i; int info = newval; int typ = BUFFER_UPDATE; for (i=0;i<nproc;i++) { if (tids[i]!=mytid) { pvm_initsend(PvmDataDefault); pvm_pkint(&mytid,1,1); pvm_pkint(&typ,1,1); pvm_pkint(&info,1,1); pvm_pkint(&my_id,1,1); pvm_send(tids[i],my_id); } } }
/** * Description not yet available. * \param */ void adpvm_pack(const dvar_vector& _v) { dvar_vector& v =(dvar_vector&) _v; int imin=v.indexmin(); int imax=v.indexmax(); pvm_pkint(&imin,1,1); pvm_pkint(&imax,1,1); pvm_pkdouble(&(value(v(imin))),imax-imin+1,1); save_identifier_string("X"); v.save_dvar_vector_position(); save_identifier_string("Y"); gradient_structure::GRAD_STACK1-> set_gradient_stack(adpvm_unpack_vector_derivatives); }
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; }
void bcast_request_msg(struct state_info info) { int tag = MSG_REQUEST; *info.local_clock += 1; pvm_initsend(PvmDataDefault); pvm_pkint(&tag, 1, 1); pvm_pkint(&info.mytid, 1, 1); pvm_pkint(info.local_clock, 1, 1); pvm_pkint(info.my_lift_number, 1, 1); pvm_bcast(GROUP, MSG_REQUEST); *info.my_request_timestamp = *info.local_clock; char diag[200]; sprintf(diag, "bcast MSG_REQUEST [timestamp=%d, lift_number=%s]", *info.local_clock, stringify(*info.my_lift_number)); diag_msg(info.mstrtid, info.mytid, diag); }
void BBSClient::save_args(int userid) { #if defined(HAVE_PKMESG) #if defined(HAVE_STL) int bufid = pvm_setsbuf(pvm_mkbuf(PvmDataDefault)); pvm_pkmesgbody(bufid); keepargs_->insert( pair<const int, int>(userid, bufid) ); #endif post_todo(working_id_); #else int index, os; os = pvm_setsbuf(pvm_mkbuf(PvmDataDefault)); pvm_pkint(&working_id_, 1, 1); pvm_send(sid_, CRAY_POST_TODO); os = pvm_setsbuf(os); index = pvm_send(sid_, CRAY_POST_TODO); os = pvm_setsbuf(os); #if defined(HAVE_STL) keepargs_->insert( pair<const int, int>(userid, os) ); #endif #endif }
/*-------------------------------------------------------------------------- ** 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); }
void SendRepeat(ArgStruct *p, int rpt) { pvm_initsend( PVMDATA ); pvm_pkint( &rpt, 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 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 update_my_czasid(){ int czas_sekcji = czas_w_sekcji(); struct timeval current_time; gettimeofday(¤t_time,NULL) ; int new_czasid = current_time.tv_sec + czas_sekcji ; czas_do_czekania = bezpieczny_czas_id(new_czasid); //SendMessagetoMasterTyp("CZASID:",czas_do_czekania); //SendMessagetoMaster("Wszystkim moj czasid"); //Wysylamy wszystkim nasz czasid int i ; for(i = 0 ; i<RYCERZE ; i++){ int tid_rycerza = kolejka[i].rycerz ; if(tid_rycerza != mytid){ pvm_initsend(PvmDataDefault); int typ = REQUEST; pvm_pkint(&typ,1,1); pvm_pkint(&mytid,1,1); pvm_pkint(&new_czasid,1,1); pvm_send(tid_rycerza,MSG_CZASID); } } //SendMessagetoMaster("CZEKAM NA ODP"); struct timeval timeout; timeout.tv_sec = 1; wszyscy_odpowiedzieli = 0 ; ile_odpowiedzialo = 0 ; while(update_kolejka(&timeout) == 0){ //SendMessagetoMaster("Nadal czekam"); } //SendMessagetoMaster("PO CZEKANIU"); update_rycerz(mytid,new_czasid); }
int send_int_array(int *array, int size) { int info; PVM_FUNC(info, pvm_pkint(array, size, 1)); return(info); }
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 }
void send_accept_msg(int dest_tid, struct state_info info) { int *sender_weight_ptr = g_hash_table_lookup(info.skiers_weights, &dest_tid); int old_free = *info.lift_free; *info.lift_free -= *sender_weight_ptr; *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_send(dest_tid, tag); char diag[200]; sprintf(diag, "sent MSG_ACCEPT to %d [timestamp=%d], was %d now %d", dest_tid, *info.local_clock, old_free, *info.lift_free); diag_msg(info.mstrtid, info.mytid, diag); }
void sendEowToAllInputs(FilterSpec * filterSpec) { int i, j; // for each input Port of this filter for(i = 0; i < filterSpec->numInputs; i++) { // i must send 1 Eow for each instace that writes to this filter for(j = 0; j < filterSpec->inputs[i]->fromFilter->filterPlacement.numInstances; j++) { //send our EOW to listeners on the other side int msgType = MSGT_EOW; int taskId = -1; pvm_initsend(PvmDataRaw); pvm_pkint(&msgType, 1, 1); pvm_pkint(&taskId, 1, 1); pvm_mcast(filterSpec->filterPlacement.tids, filterSpec->filterPlacement.numInstances, filterSpec->inputs[i]->tag); } } }
/** * Description not yet available. * \param */ void adpvm_pack(const i3_array & _m) { i3_array& m = (i3_array &) _m; if (allocated(m)) { int imin=m.indexmin(); int imax=m.indexmax(); pvm_pkint(&imin,1,1); pvm_pkint(&imax,1,1); for (int i=imin;i<=imax;i++) adpvm_pack(m(i)); } else { int imin=0; int imax=-1; pvm_pkint(&imin,1,1); pvm_pkint(&imax,1,1); } }
/** * Description not yet available. * \param */ void adpvm_pack(const dvector& _v) { dvector& v =(dvector&) _v; if (allocated(v)) { int imin=v.indexmin(); int imax=v.indexmax(); pvm_pkint(&imin,1,1); pvm_pkint(&imax,1,1); pvm_pkdouble(&(v(imin)),imax-imin+1,1); } else { int imin=0; int imax=-1; pvm_pkint(&imin,1,1); pvm_pkint(&imax,1,1); } }