本文整理汇总了C++中pvm_initsend函数的典型用法代码示例。如果您正苦于以下问题:C++ pvm_initsend函数的具体用法?C++ pvm_initsend怎么用?C++ pvm_initsend使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pvm_initsend函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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);
}
示例2: main
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);
}
示例3: steal
/* 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;
}
示例4: main
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();
}
示例5: send_tour
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;
}
示例6: printf
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;
}
}
示例7: gen_x
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 ;
}
示例8: GARandomSeed
// 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);
}
示例9: main
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;
}
示例10: send_kill
void send_kill(int tid) {
int bufid;
bufid = pvm_initsend(PvmDataDefault);
pvm_send(tid,2);
pvm_freebuf(bufid);
}
示例11: mcast_accept_msg
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);
}
示例12: sendEof
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);
}
示例13: SendTime
void
SendTime(ArgStruct *p, double *t)
{
pvm_initsend( PVMDATA );
pvm_pkdouble( t, 1, 1 );
pvm_send( p->prot.othertid, 1);
}
示例14: main
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();
}
示例15: kill_workers
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() ;
}