next up previous
Next: Design issues Up: Implementation and Design Previous: Implementation and Design

API definition

At the farmer end:

  1. int pvm_farm_init (char *farm_name);

    The routine pvm_farm_init() creates a process farm with a name specified by the argument farm_name. In an application, the farm name is unique (i.e., the user should not invoke this routine twice with the same name). Multiple farms can be used with a separate farm names. This name is used by the worker task to enroll in a farm. Returns OK or ERROR or PvmFarmNamePresent.

    	e.g.,
    	pvm_farm_init("Farmer1");
    
  2. int pvm_get_worker_class_id (char *farm_name, char *worker_class_name);

    The routine pvm_get_worker_class_id() returns the identifier that represents a worker class named worker_class_name associated with the farm named farm_name. This is used by the farmer to uniquely identify a particular worker class. Returns ERROR on error or a positive integer id. This identifier is used by subsequent farmer calls to send data packets to this worker class or to receive replies from the worker class. This call blocks till the worker class is created by a worker task.

    	e.g.,
    	id = pvm_get_worker_class_id("Farmer1", "WC1");
    	if (id == ERROR)
    	{
    		printf("Error in getting worker class id\n");
    		pvm_exit();
    		exit(1);
    	}
    

  3. int pvm_send_work_packet(int id);

    The routine pvm_send_work_packet() sends the message to one worker task associated with the worker class whose identifier is specified by id. The data should be packed in a buffer (the active send buffer) created by pvm_initsend() or pvm_mkbuf(); PvmDataDefault is used to create the buffer so that XDR encoding can be done for communication between dissimilar hosts (little endian and big endian hosts). Returns OK or ERROR.

    	e.g.,
    	int id, data, bufid; 
    	id = pvm_get_worker_class_id("Farmer1","WC1");
    	bufid = pvm_mkbuf(PvmDataDefault); /* pvm call creates buffer */
    	pvm_setsbuf(bufid); /* sets this as the active send buffer
    		This is also the default action taken */
    	data = 500; /* gets data ready for packing in the buffer */
    	pvm_pkint(&data, 1, 1); /* packs one int data item, stride = 1 */
    	/* calls to pack the data */
    	pvm_send_work_packet(id, 34);
    	pvm_freebuf(bufid); /* frees the buffer */
    

  4. int bufid = pvm_recv_reply_packet(id);

    This blocking receive reply packet routine will wait until has arrived from the worker class specified by the identifier id. This call places the message in a new active receive buffer that is created. The previous active receive buffer is cleared unless it has been saved explicitly with a pvm_setrbuf() call.

    	e.g.,	
    	pvm_recv_reply_packet(id);
    

  5. int pvm_farm_terminate(char *farm_name);

    This routine shuts down a farm and frees the worker tasks in the worker classes associated with the farm whose name is specified by farm_name. The worker tasks waiting on a receive are sent a message that the farm has terminated. After executing this call, a new farm with the same name may be created. Returns OK or ERROR or PvmNoSuchFarm or PvmNotFarmOwner.

    	e.g.,
    	pvm_farm_terminate("Farmer1");
    

  6. int pvm_start_farmd(void);

    This routine starts the pvmfarmd daemon which is responsible for farming related calls. This daemon can be started manually from the pvm shell or by using this call. This should be called only once in the entire application. Returns OK or ERROR.

    	e.g.,
    	pvm_start_farmd(); /* starts the daemon.*/
    
  7. int pvm_stop_farmd(void);

    This routine sends a message to the pvmfarmd to terminate itself. This should also be called by only one task in the application. This should be done by the farmer task after it has terminated the farm. Returns OK or ERROR.

    	e.g.,
    	pvm_stops_farmd(); /* stops the daemon.*/
    

    At the worker end:

  8. int pvm_init_worker_class(char *farm_name, char *worker_class_name);

    The pvm_init_worker_class() routine creates (if it already doesn't exist) a worker class named worker_class_name and enrolls the calling task in the worker class. This worker class is associated with the farmer task specified by farm_name. This call blocks till a farm is created (in case the farmer has not created the farm). Returns OK or ERROR.

    	e.g.,
    	pvm_init_worker_class("Farmer1", "WC1");
    
  9. int bufid = pvm_recv_work_packet(void);

    The pvm_recv_work_packet() routine waits until a message arrives from the farmer task. A worker task can be associated with at most one farmer (and a worker class) at a time. The previous active receive buffer is cleared unless it has been saved with a pvm_setrbuf() call. This call returns bufid or PvmFarmTerminated if the farmer has executed a farm_terminate() call. When PvmFarmHasTerminated is returned, the worker task is free to do any other activity not associated with the current farm.

    	e.g.,
    	buffer_id = pvm_recv_reply_packet();
    	/* All unpacking routines */
    

  10. int pvm_send_reply_packet(void);

    This routine sends a reply packet which has been packed into the active send buffer, to the farmer task. Returns OK or ERROR.

    	e.g.,
    	/* initialise the buffer for sending */
    	int bufid,data;
    	bufid = pvm_mkbuf(PvmDataDefault); /* makes a new buffer */
    	pvm_setsbuf(bufid); /* done by default - sets this 
    		as the active send buffer used by pvm_send_reply_packet() */
    	data = 5; /* some reply packet */
    	pvm_pkint(&data, 1, 1); /* packs the integer into the buffer */
    	pvm_send_reply_packet(); /* sends the buffer to the farmer */
    	pvm_freebuf(bufid);
    
  11. int pvm_leave_farm(void);

    This routine is called by the worker task to disassociate itself from the farm in which it is currently enrolled. This call removes the task related information of this task from the worker class information repository maintained by the central pvmfarmd daemon (farm daemon). After this call is executed, the calling worker task no longer receives work packets from the farmer. The worker can enroll in any farm subsequently, by calling the pvm_init_worker_class() routine. This allows for the worker process to migrate from one farm to another dynamically at runtime. Returns OK or ERROR.

    	e.g.,
    	pvm_leave_farm(); /* leaves the farm */
    



next up previous
Next: Design issues Up: Implementation and Design Previous: Implementation and Design



Sameer Shende