Esempio n. 1
0
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;
}
Esempio n. 2
0
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 );
}
Esempio n. 3
0
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 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();
}
Esempio n. 5
0
int receive(heur_prob *p)
{  
   int r_bufid, info, bytes, msgtag, parent;
   
   PVM_FUNC(r_bufid, pvm_recv(-1, VRP_BROADCAST_DATA));
   PVM_FUNC(info, pvm_bufinfo(r_bufid, &bytes, &msgtag, &parent));
   PVM_FUNC(info, pvm_upkint(&(p->dist.wtype), 1, 1));
   PVM_FUNC(info, pvm_upkint(&(p->vertnum), 1, 1));
   PVM_FUNC(info, pvm_upkint(&(p->depot), 1, 1));
   PVM_FUNC(info, pvm_upkint(&p->capacity, 1, 1));
   p->demand = (int *) calloc (p->vertnum, sizeof(int));
   PVM_FUNC(info, pvm_upkint(p->demand, p->vertnum, 1));
   p->edgenum = p->vertnum*(p->vertnum-1)/2;
   if (p->dist.wtype){ /* not EXPLICIT */
      p->dist.coordx = (double *) calloc(p->vertnum, sizeof(double));
      p->dist.coordy = (double *) calloc(p->vertnum, sizeof(double));
      PVM_FUNC(info, pvm_upkdouble(p->dist.coordx, p->vertnum, 1));
      PVM_FUNC(info, pvm_upkdouble(p->dist.coordy, p->vertnum, 1));
      if ((p->dist.wtype == _EUC_3D) || (p->dist.wtype == _MAX_3D) || 
	  (p->dist.wtype == _MAN_3D)){
	 p->dist.coordz = (double *) calloc(p->vertnum, sizeof(double));
	 PVM_FUNC(info, pvm_upkdouble(p->dist.coordz, p->vertnum, 1));
      }
   }
   else{ /* EXPLICIT */
      p->dist.cost = (int *) malloc (p->edgenum*sizeof(int));
      PVM_FUNC(info, pvm_upkint(p->dist.cost, (int)p->edgenum, 1));
   }
   PVM_FUNC(info, pvm_freebuf(r_bufid));
   return(parent);
}
Esempio n. 6
0
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);
  
}
Esempio n. 7
0
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, &degree);          /*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);

}
Esempio n. 8
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);
}
Esempio n. 9
0
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();
}
Esempio n. 10
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;
  }
Esempio n. 11
0
int receive_msg(int who, int what)
{
   int r_bufid;

   PVM_FUNC(r_bufid, pvm_recv(who, what));

   return(r_bufid);
}
Esempio n. 12
0
value
Pvm_recv(value tid,value msgtag)
{
  enter_blocking_section();
  int res = pvm_recv(Int_val(tid), Int_val(msgtag));
  leave_blocking_section();
  if (res<0) TreatError(res);
  return(Val_int(res));
}
Esempio n. 13
0
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);
}
Esempio n. 14
0
int receive_assign(tassign *assign) {
	int     bufid, tag, dummy, datasize, i, toint[ASSIGN_NINT];
	double *tdbl, todbl[ASSIGN_NDBL];
	float  *tflt;

	bufid = pvm_recv(-1,-1);
	pvm_bufinfo(bufid,&dummy,&tag,&dummy);
	if (tag == 2) return 0;
	
	pvm_upkint(toint,ASSIGN_NINT,1);
	pvm_upkdouble(todbl,ASSIGN_NDBL,1);

	assign->id         = (integer)toint[ASSIGN_ID];
	assign->chans      = (integer)toint[ASSIGN_CHANS];
	assign->frames     = (integer)toint[ASSIGN_FRAMES];
	assign->epochs     = (integer)toint[ASSIGN_EPOCHS];
	assign->bias       = (integer)toint[ASSIGN_BIAS];
	assign->signs      = (integer)toint[ASSIGN_SIGNS];
	assign->extended   = (integer)toint[ASSIGN_EXTENDED];
	assign->extblocks  = (integer)toint[ASSIGN_EXTBLOCKS];
	assign->pdfsize    = (integer)toint[ASSIGN_PDFSIZE];
	assign->nsub       = (integer)toint[ASSIGN_NSUB];
	assign->verbose    = (integer)toint[ASSIGN_VERBOSE];
	assign->block      = (integer)toint[ASSIGN_BLOCK];
	assign->maxsteps   = (integer)toint[ASSIGN_MAXSTEPS];
	
	assign->lrate      = (doublereal)todbl[ASSIGN_LRATE];
	assign->annealstep = (doublereal)todbl[ASSIGN_ANNEALSTEP];
	assign->annealdeg  = (doublereal)todbl[ASSIGN_ANNEALDEG];
	assign->nochange   = (doublereal)todbl[ASSIGN_NOCHANGE];
	assign->momentum   = (doublereal)todbl[ASSIGN_MOMENTUM];

	datasize = assign->chans * assign->frames * assign->epochs;
	assign->data = (doublereal*)malloc(datasize*sizeof(doublereal));
	if (sizeof(float) != sizeof(doublereal)) {
		tflt = (float*)malloc(datasize*sizeof(float));
		pvm_upkfloat(tflt,datasize,1);
		for (i=0 ; i<datasize ; i++) assign->data[i] = (doublereal)tflt[i];
		free(tflt);
	}
	else
		pvm_upkfloat((float*)(assign->data),datasize,1);

	datasize = assign->chans * assign->chans;
	assign->weights = (doublereal*)malloc(datasize*sizeof(doublereal));
	if (sizeof(double) != sizeof(doublereal)) {
		tdbl = (double*)malloc(datasize*sizeof(double));
		pvm_upkdouble(tdbl,datasize,1);
		for (i=0 ; i<datasize ; i++) assign->weights[i] = (doublereal)tdbl[i];
		free(tdbl);
	}
	else
		pvm_upkdouble((double*)(assign->weights),datasize,1);

	pvm_freebuf(bufid);
	return 1;
}
Esempio n. 15
0
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);
}
Esempio n. 16
0
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);
}
Esempio n. 17
0
int RecvFloat(float *FloatBuf, 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_upkfloat(FloatBuf, n, 1);
  /* pvm_upkbyte((char *)FloatBuf, n*sizeof(float), 1); */
  return(SenderTid);
}
Esempio n. 18
0
int RecvInt(int *IntBuf, int n, int tid, int MsgType)
{
  int info, BufId, NBytes, MsgTag, SenderTid;

  /*BufId = pvm_recv(-1, MsgType);*/
  BufId = pvm_recv(tid, MsgType);  /* wences */
  info  = pvm_bufinfo( BufId, &NBytes, &MsgTag, &SenderTid);
  pvm_upkint(IntBuf, n, 1);
  return(SenderTid);
}
Esempio n. 19
0
File: PVM.c Progetto: 1587/ltp
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
}
Esempio n. 20
0
char* RecvStr(int tid, int MsgType)
{
  int   info, BufId, NBytes, MsgTag, MasterTid;
  char *s1, tmp_char[200];

  BufId = pvm_recv(tid, MsgType);
  info  = pvm_bufinfo( BufId, &NBytes, &MsgTag, &MasterTid);
  pvm_upkstr(tmp_char);
  s1 = (char *)malloc(strlen(tmp_char)+1);
  strcpy(s1, tmp_char);
  return(s1);
}
Esempio n. 21
0
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();
}
Esempio n. 22
0
/**
 * Description not yet available.
 * \param
 */
void adpvm_receive_derivatives(void)
{
  verify_identifier_string("H");
  int n=restore_int_value();
  int id=restore_int_value();
  verify_identifier_string("G");
  int bid=0;
  if ( (bid=pvm_recv(id,2))<0)
  {
    cerr << "error in adpvm_receive_derivatvies" << endl;
    ad_exit(1);
  }
}
Esempio n. 23
0
/**
 * Description not yet available.
 * \param
 */
int adpvm_recv(int id,int n)
{
  int status=pvm_recv(id,n);
  //cout << status << endl;
  if (!ad_constant_flag)
  {
    save_identifier_string("E");
    save_int_value(id);
    save_int_value(n);
    save_identifier_string("F");
    gradient_structure::GRAD_STACK1->
            set_gradient_stack(adpvm_send_derivatives);
  }
  return status;
}
Esempio n. 24
0
/* add self to worker list */
void hello() {
  int i,b,n;
  pvmtaskinfo *ta;
  pvm_tasks(0,&n,&ta);
  for (i=0;i<n;i++)
    if (!strcmp(ta[i].ti_a_out,"kalah")) {
      pvm_initsend(0);
      pvm_pkstr(host);
      pvm_send(ta[i].ti_tid,TAG_HELLO);
      break;
      } 
  b = pvm_recv(-1,TAG_WORKERS); 
  if (b < 0)
    die("Failed to receive worker list\n");
  p_handle(b);
  }
Esempio n. 25
0
// Gather the population data from each of our distributed populations.
int
PVMDemeGA::collect() {
#ifdef DEBUG
  cerr << "sending request for populations...\n";
#endif

  for(int j=0; j<_ntid; j++) {
    _status = pvm_initsend(PvmDataDefault);
    _status = pvm_send(_tid[j], MSG_SEND_POPULATION);
  }

#ifdef DEBUG
  cerr << "waiting for populations from slaves...\n";
#endif

  int flag = _ntid;
  while(flag > 0) {
    int bufid = pvm_recv(-1, -1);
    if(bufid >= 0) {
      int bytes, msgtag, tid;
      _status = pvm_bufinfo(bufid, &bytes, &msgtag, &tid);
      int which = tid2idx(tid);

      switch(msgtag) {
      case MSG_INCOMING_POPULATION:
	_status = RecvPopulation(*deme[which]);
	flag--;

#ifdef DEBUG
	cerr << "  received pop from tid " << tid << " (" << which << ")\n";
#endif
	break;

      default:
	cerr << className() << ": collect:\n";
	cerr << "  unexpected msgtag: " << msgtag << "\n";
	break;
      }
    }
    else {
      cerr << className() << ": collect:\n";
      cerr << "  error from pvm_recv: " << bufid << "\n";
    }
  }

  return _status;
}
Esempio n. 26
0
/**
 * Description not yet available.
 * \param
 */
int adpvm_slave_vrecv(int ptid)
{
  int ierr=pvm_recv(ptid,-1);
  adpvm_unpack(gradient_structure::no_derivatives);

  if (!gradient_structure::no_derivatives)
  {
    save_identifier_string("E");
    save_int_value(ptid);
    save_int_value(2);
    save_identifier_string("F");
    gradient_structure::GRAD_STACK1->
            set_gradient_stack(adpvm_send_derivatives);
  }

  return ierr;
}
Esempio n. 27
0
int BBSClient::get(int type) { // blocking
fflush(stdout);
fflush(stderr);
	double st = time();	
	int bufid, nbyte, msgtag, tid, index;
	index = pvm_send(sid_, type);
	bufid = pvm_recv(sid_, -1);
	pvm_bufinfo(bufid, &nbyte, &msgtag, &tid);
	wait_time_ += time() - st;
	if (bufid < 0) { perror("take"); }
#if debug
printf("BBSClient::get return msgtag=%d\n", msgtag);
fflush(stdout);
#endif
	if (msgtag == QUIT) {
		done();
	}
	return msgtag;
}
Esempio n. 28
0
//@cindex waitForPEOp
rtsPacket 
waitForPEOp(OpCode op, GlobalTaskId who, void(*processUnexpected)(rtsPacket) )
{
  rtsPacket p;
  int nbytes;
  OpCode opCode;
  GlobalTaskId sender_id;
  rtsBool match;

  IF_PAR_DEBUG(verbose,
	       fprintf(stderr,"~~ waitForPEOp: expecting op = %x (%s), who = [%x]\n", 
		       op, getOpName(op), who)); 

  do {
    while((p = pvm_recv(ANY_TASK,ANY_OPCODE)) < 0)
      pvm_perror("waitForPEOp: Waiting for PEOp");
      
    pvm_bufinfo( p, &nbytes, &opCode, &sender_id );
    match = (op == ANY_OPCODE || op == opCode) && 
            (who == ANY_TASK || who == sender_id);

    if (match) {
      IF_PAR_DEBUG(verbose,
		   fprintf(stderr,
			   "~~waitForPEOp: Qapla! received: OpCode = %#x (%s), sender_id = [%x]",
			   opCode, getOpName(opCode), sender_id)); 

      return(p);
    }

    /* Handle the unexpected OpCodes */
    if (processUnexpected!=NULL) {
      (*processUnexpected)(p);
    } else {
      IF_PAR_DEBUG(verbose,
		   fprintf(stderr,
			   "~~ waitForPEOp: ignoring OpCode = %#x (%s), sender_id = [%x]",
			   opCode, getOpName(opCode), sender_id)); 
    }

  } while(rtsTrue);
}
Esempio n. 29
0
main()
{
	int cc, tid;
	char buf[100];

	printf("i'm t%x\n", pvm_mytid());

	cc = pvm_spawn("hello_other", (char**)0, 0, "", 1, &tid);

	if (cc == 1) {
		cc = pvm_recv(-1, -1);
		pvm_bufinfo(cc, (int*)0, (int*)0, &tid);
		pvm_upkstr(buf);
		printf("from t%x: %s\n", tid, buf);

	} else
		printf("can't start hello_other\n");

	pvm_exit();
	exit(0);
}
Esempio n. 30
0
main(){
	long clock_sec, clock_usec ;
	struct timeval tv ;

	mytid = pvm_mytid();
	

	pvm_recv( -1, MSG_MSTR);
	//Dostajemy Tids wszystkich
	pvm_upkint(&tid_master,1,1);
	pvm_upkint(tids_rycerze, RYCERZE, 1 );
	
	init_kolejka();

	SendMessagetoMaster("Zaczynamy");
	 
	Algorytm();
	

	pvm_exit();

}