Example #1
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();
}
Example #2
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);

}
Example #3
0
static void
stop(const char * msg)
{
   printf("%s", msg);
   pvm_exit();
   abort();
}
Example #4
0
value
Pvm_exit(void)
{
  int res = pvm_exit();
  if (res<0) TreatError(res);
  return;
}
Example #5
0
void exit_prog(char * message, int code){
    if(message){
        printf("%s", message);
    }
    pvm_exit();
    exit(code);
}
Example #6
0
void pvm_init(int argc, char *argv[])
{
    int mytid, mygid, ctid[MAXPROC];
    int np, i;

    mytid = pvm_mytid();
    if((argc != 2) && (argc != 1)) goto usage;
    if(argc == 1) np = 1;
    if(argc == 2)
       if((np = atoi(argv[1])) < 1) goto usage;
    if(np > MAXPROC) goto usage;

    mygid = pvm_joingroup(MPGROUP);

    if(np > 1)
       if (mygid == 0) 
          i = pvm_spawn(argv[0], argv+1, 0, "", np-1, ctid);

    while(pvm_gsize(MPGROUP) < np) sleep(1);

    /* sync */
    pvm_barrier(MPGROUP, np);
    
    printf("PVM initialization done!\n");
    
    return;

  usage:
    fprintf(stderr, "usage: %s <nproc>\n", argv[0]);
    pvm_exit();
    exit(-1);
}
Example #7
0
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 ;
}
Example #8
0
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() ;

}
Example #9
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);
}
Example #10
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;
}
Example #11
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 );
}
Example #12
0
void BBSClient::done() {
#if debug
printf("BBSClient::done\n");
fflush(stdout);
#endif
	BBSImpl::done();
	if (pvm_exit()) {perror("BBSClient::done");}
	exit(0);
}
Example #13
0
/* closing function */
void close_parallel() {
  int i;
  pvm_exit();
  free(wtid);
  free(sj);
  for (i=0;i<nj;i++)
    free(ja[i]);
  free(ja);
  }
Example #14
0
File: hello.c Project: skoneka/prir
int main()
{
  int mytid;

  mytid = pvm_mytid();
  printf("My TID is %d\n", mytid);
  pvm_exit();
  return 0;
}
Example #15
0
//@cindex shutDownPE
void
shutDownPE(void)
{    
  IF_PAR_DEBUG(verbose,
	       fprintf(stderr, "== [%x] PEshutdown\n", mytid));

  checkComms(pvm_lvgroup(PEGROUP),"PEShutDown");
  checkComms(pvm_exit(),"PEShutDown");
}
Example #16
0
// Now shut down all of the PVM stuff.  Tell all of the slaves to quit.  We
// can do this by sending the quit message or just by killing them all.  We'll
// just kill them all rather than telling them to quit nicely (sinister grin).
int
ShutdownPVM(PVMData& d) {
  for(int i=0; i<d.ntasks; i++)
    pvm_kill(d.tid[i]);
  delete [] d.tid;

  pvm_exit();			// leave the PVM

  return 0;
}
Example #17
0
// Reap all of our spawned processes and detach ourselves from the PVM.
void
PVMDemeGA::reap() {
  for(int j=0; j<_Ntid; j++)
    if(_tid[j] > 0) pvm_kill(_tid[j]);
  delete [] _tid; 
  _tid = 0;
  _ntid = _Ntid = 0;
  if(_mid > 0) pvm_exit();
  _mid = 0;
}
Example #18
0
static void
pvm_ferror(const char *string, int p)
{
    if(p)
        pvm_perror((char*)string);
    else
        fprintf(stderr, "%s\n", string);
    pvm_exit();
    exit(1);
}
Example #19
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();
}
Example #20
0
File: log.c Project: girving/kalah
void die(char *fmt, ...) {
  if (fmt) {
    va_list ap;
    logheader();
    va_start(ap,fmt);
    fputs("Fatal: ",log);
    vfprintf(log,fmt,ap);
    va_end(ap);
    }
  fclose(log);
  pvm_exit();
  exit(-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();
}
Example #22
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;	
}
Example #23
0
main()
{
        int ptid;
        char greetings[100];

        ptid=pvm_parent(); /*get tid of task that started me*/
        strcpy(greetings,"Hello world from ");
        gethostname(greetings + strlen(greetings));

        pvm_initsend(PvmDataDefault); /*initialize send buffer*/
        pvm_pkstr(greetings); /*XDR encode string into send buffer*/
        pvm_send(ptid,1);

        pvm_exit(); /*disconnect from the PVM*/
        exit(0);
}
Example #24
0
main()
{
	int ptid;
	char buf[100];

	ptid = pvm_parent();

	strcpy(buf, "hello, world from ");
	gethostname(buf + strlen(buf), 64);

	pvm_initsend(PvmDataDefault);
	pvm_pkstr(buf);
	pvm_send(ptid, 1);

	pvm_exit();
	exit(0);
}
Example #25
0
void BBSDirect::done() {
	int i;
	if (done_) {
		return;
	}
	BBSImpl::done();
	done_ = true;
printf("done: ncids=%d\n", ncids);
	for (i=0; i < ncids; ++i) {
		pvm_initsend(PvmDataDefault);
		pvm_send(cids[i], QUIT);		
//printf("kill %d\n", cids[i]);
//		pvm_kill(cids[i]);
	}
	if (pvm_exit()) {perror("BBSDirect::done");}
	BBSDirectServer::server_->done();
}
Example #26
0
main()
{
    int mytid;                  /* my task id */
    int *tids;                  /* array of task ids */
    int me;                     /* my process number */
    int i;
	int ntids;

    /* enroll in pvm */
    mytid = pvm_mytid();

	/* determine the size of my sibling list */

	ntids = pvm_siblings(&tids);

	for (i = 0; i < ntids; i ++)
		if ( tids[i] == mytid)
		{
			me = i;
			break;
		}
		
	if (me == 0)
	{
		printf("Pass a token through the %3d tid ring:\n", ntids);
		for (i = 0; i < ntids; i ++)
		{
			printf( "%6d -> ", tids[i]);
			if (i % 6 == 0 && i > 0)
				printf("\n");	
		}
		printf("%6d \n", tids[0]);
	}
/*--------------------------------------------------------------------------*/
     
     dowork( me, ntids, tids );

     /* program finished exit pvm */
     pvm_exit();
     exit(1);
}
Example #27
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);
}
Example #28
0
int StartLog(SeisSlave *node)
{
	char	log_file[256], myhost[256];
	char	*hd;
	FILE *fp;
	
	if ((node -> NodeTid = pvm_mytid()) < 0) {
		pvm_perror("Error enrolling");
		return(-1);
	} 

/* Get host info */
	(void) gethostname(myhost, sizeof(myhost));
	node -> machine = (char *)malloc(strlen(myhost));
	strcpy(node -> machine, myhost);

/* Open the log file */
	if ( !(hd = (char *)getenv("PVMLOG")) ) {
	    hd = "/tmp"; /* Default value */
            fprintf(stderr, "Warning: Variable PVMLOG has not been  set\n");
      	}

	/* creating log files */
	sprintf(log_file, "%s/PSU%s%d\0", hd, myhost, node -> NodeTid);
	/* if ( (node -> fd_log = open(log_file,O_CREAT)) == -1) { */
	if ( (node -> fp_log = freopen(log_file,"w", stderr)) == NULL) {
		fprintf(stderr, "Error opening the log file: %s\n", log_file);
		pvm_exit();
		return(-1);
	}
	
/* Write a header in the log file */
	fprintf(stderr, "%s\n", node -> apl_name);
	fprintf(stderr, 
		"\tFile\t--> %s\n\tapl-tid\t--> %d\n\tMachine\t--> %s \n",
		log_file, node -> NodeTid, node -> machine);
	fflush(stderr);

	return(0);
} /* end of StartLog() */
Example #29
0
// Set up the PVM stuff.  Register this task then set up all of the slaves.
// Return 1 if a problem, 0 if everything went ok.
int
StartupPVM(const char* prog, PVMData& d) {
  int i;

  d.masterid = pvm_mytid();
  
  int nhost, narch;
  struct pvmhostinfo* hostp;
  int status = pvm_config(&nhost, &narch, &hostp);
  if(status == PvmSysErr) {
    cerr<<"\n" << prog << ": PVM not responding. Have you started the PVM?\n";
    return 1;
  }
  
  d.tid = new int [d.nreq];	// task IDs for the slaves
  d.ntasks = pvm_spawn(SLAVE_NAME, (char**)0, 0, "", d.nreq, d.tid);
  if(d.ntasks <= 0) {
    cerr << prog << ": Error spawning slaves.\n";
    cerr << "  Error codes of failed spawns are:\n";
    for(i=0; i<d.nreq; i++) {
      cerr << "    slave "; cerr.width(3);
      cerr << i << ": " << d.tid[i] << "\n";
    }
    pvm_exit();
    return 1;
  }
  else if(d.ntasks < d.nreq) {
    cerr << prog << ": Spawned only "<<d.ntasks<<" of "<<d.nreq<<"\n";
    cerr << "  Error codes of failed spawns are:\n";
    for(i=0; i<d.nreq; i++) {
      cerr << "    slave "; cerr.width(3); 
      cerr << i << ": " << d.tid[i] << "\n";
    }
  }
  else {
    cerr << prog << ": Spawned " << d.nreq << " slave processes...\n";
  }
  
  return 0;
}
Example #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();

}