Beispiel #1
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);
  }
Beispiel #2
0
static void
find_tree_manager(const int my_tid, int &tm_tid)
{
   struct pvmtaskinfo *taskp = 0;
   int ntask = 0;
   pvm_tasks(0, &ntask, &taskp);
   int * tids = new int[ntask];
   int i, k;
   
   for (i = 0, k = 0; i < ntask; ++i) {
      if (taskp[i].ti_ptid != 0)
	 continue; // has a parent, can't be the TM
      if (taskp[i].ti_tid == my_tid)
	 continue; // self
      // Otherwise it could be the TM (might be a console...)
      tids[k++] = taskp[i].ti_tid;
   }

   if (tm_tid != 0) {
      // Check that the given tid is among the candidates
      for (i = 0; i < k; ++i)
	 if (tids[i] == tm_tid)
	    break;
      if (i == k)
	 stop("No TM candidate has the given tid... Aborting.\n");
   } else {
      // Broadcast a query to the candidates
      pvm_initsend(PvmDataRaw);
      pvm_mcast(tids, k, BCP_ARE_YOU_TREEMANAGER);
      // Wait for an answer
      struct timeval tout = {15, 0};
      int bufid = pvm_trecv(-1, BCP_I_AM_TREEMANAGER, &tout);
      if (bufid == 0)
	 stop("No TM candidates replied within 30 seconds... Aborting.\n");
      int bytes = 0, msgtag = 0;
      pvm_bufinfo(bufid, &bytes, &msgtag, &tm_tid);
   }

   delete[] tids;
}
Beispiel #3
0
int
Establish(ArgStruct *p)
{
    /* Task information for the entire parallel machine (if trans) */
    int                     tasks_status;
    struct pvmtaskinfo      *taskp;
    int                     ntasks;

        /* Received buffer (if receiver)  */
    int buffer_id;

    /*
    If we are the transmitting side, go find the other one and send
    it a message containing our tid. If we are the receiving side,
    just wait for a message.
    */
    if (p->tr) {
#ifdef DEBUG
	printf("this is the transmitter\n");
#endif
	tasks_status = pvm_tasks( 0, &ntasks, &taskp );
	if (ntasks != 2) {
	    printf("Error, too many processes in parallel machine \n");
	    printf("Start a clean machine.  n=%d\n", ntasks);
	    exit(-1);
	}

	/* Since there are two tasks, one is ours the other is the receiver */
	p->prot.othertid = -1;
	if (taskp[0].ti_tid == p->prot.mytid) {
	    p->prot.othertid = taskp[1].ti_tid;
	}
	if (taskp[1].ti_tid == p->prot.mytid) {
	    p->prot.othertid = taskp[0].ti_tid;
	}
	if (p->prot.othertid == -1) {
	    printf("Error, cannot find other (receiving) task \n");
	    printf("Id's:  %d %d  \n",taskp[0].ti_tid,taskp[1].ti_tid);
	}

	/* Send the receiver a message.  Tell pvm to keep the channel open */

#ifdef DEBUG
	printf("The receiver tid is %d \n",p->prot.othertid);
#endif
	pvm_setopt( PvmRoute, PvmRouteDirect );
	pvm_initsend( PVMDATA );
	pvm_pkint( &p->prot.mytid, 1, 1 );
	pvm_send( p->prot.othertid, 1 );
    } else {
#ifdef DEBUG
	printf("This is the receiver \n");
#endif

	/* Receive any message from any task */
	buffer_id = pvm_recv(-1, -1);

	if (buffer_id < 0) {
	    printf("Error on receive in receiver\n");
	    exit(-1);
	}
	pvm_upkint( &p->prot.othertid, 1, 1 );
    }
}
Beispiel #4
0
int main(int argc, char* argv[])
{
  // Timeout for Message Receive
  struct timeval tmout;
  tmout.tv_usec=100;
  tmout.tv_sec=0;
  
  // Size for Data Packets  
  int data_size;

  // Numer of running tasks
  int curcount;

  // Check if all data sent
  bool finished;

  // TID of host to send data
  int slave_tid;

  // Data Buffer for outgoing messages
  int buff;

  // Read the frequency list
  read_freq_list(FREQ_LIST_FILE);

  // Total number of Data Elements
  int data_count=freq_count;

  // Current possition in the array
  int current_data=0;

  // Store master-id in PVM
  {
    int master_id=pvm_mytid();
    pvm_delete((char *) "master",0);
    pvm_insert((char *)"master",0,master_id);
    // Parameters for Spawn
    char *params[2]={(char *) "1", NULL};
    char *slave=(char *) "matcher_slave";
    int tids[HOST_COUNT];
    int spawncount=pvm_spawn(slave,params,PvmTaskDefault,NULL,HOST_COUNT,tids);
  }

  // Get number of current tasks
  pvm_tasks(0,&curcount,NULL);
  
  finished=false;
  do
    {
      // Check for error
      if (pvm_probe(-1,MSG_SLAVE_ERROR))
	{
	  char error[32];
	  int err_no=0;
	  pvm_recv(-1,MSG_SLAVE_ERROR);
	  pvm_upkint(&slave_tid,1,1);
	  pvm_upkint(&err_no,1,1);
	  printf("Fehler in Slave %d Code %d\n",slave_tid,err_no);
	}
      // Send Data or End-Of-Data
      else if(pvm_trecv(-1,MSG_SLAVE_READY,&tmout)>0)
	{
	  pvm_upkint(&slave_tid,1,1);		
	  // No more data
	  if (finished)
	    {
	      pvm_initsend(PvmDataDefault);
	      pvm_send(slave_tid,MSG_MASTER_EOD);
	    }
	  // Send data packet
	  else
	    {
	      buff=pvm_initsend(PvmDataDefault);

	      if (data_count>=PACK_SIZE)
		data_size=PACK_SIZE;
	      else
		data_size=data_count;
	      data_count-=data_size;
	      pvm_pkint(&data_size,1,1);
	      for(int ct=0;ct<data_size;ct++)
		{
		  // Store the data in the buffer
		  if (current_data<=freq_count)
		    {
		      pvm_pkstr(freq_list[current_data]->word.getValue());
		      pvm_pkulong(&(freq_list[current_data]->count),1,1);
		      current_data++;
		    }
		}
	      pvm_initsend(PvmDataDefault);
	      pvm_send(slave_tid,MSG_MASTER_DATA);
	      printf("Send %d sets of %d to %d\n",data_size,data_count,slave_tid);
	      if (data_count==0) 
		finished=true;
	    }
	}
      // Receive Result
      else if (pvm_probe(-1,MSG_SLAVE_RESULT))
	{
	  if (pvm_trecv(-1,MSG_SLAVE_RESULT,&tmout)>0)
	    {
	      pvm_upkint(&slave_tid,1,1);
	      // Number of elements
	      pvm_upkint(&data_size,1,1);	    
	      for (int ct=0;ct<data_size;ct++)
		{
		  unsigned long res1=0;
		  unsigned long res2=0;
		  // Read the result data
		  /* to fill */
		  // pvm_upkulong(&res1,1,1);
		  // pvm_upkulong(&res2,1,1);
		  // printf("Result %llu\n",(unsigned long long int)res2*ULONG_MAX+res1);
		}
	      PvmDataDefault
	      pvm_send(slave_tid,MSG_MASTER_EXIT);
	    }
	}
      pvm_tasks(0,&curcount,NULL);
    }
  while(curcount>2);
  pvm_exit();
  return 0;
}