PVM: sample aplication

Makefile: instruction file for compiling the application: Makefile  Makefile

Remember to invoke SETUP PVM first.


    PVMINC=$(PVM_ROOT)/include
    PVMLIB=$(PVM_ROOT)/lib/$(PVM_ARCH)
    
    all:	$(PVM_HOME)/master $(PVM_HOME)/slave
    
    run:
    	$(PVM_HOME)/master
    
    $(PVM_HOME)/master:	master.c def.h
    	cc -g master.c -o $(PVM_HOME)/master -L$(PVMLIB) -I$(PVMINC) -lpvm3 -lgpvm3
    
    $(PVM_HOME)/slave:	slave.c def.h
    	cc -g slave.c -o $(PVM_HOME)/slave -L$(PVMLIB) -I$(PVMINC) -lpvm3 -lgpvm3
    
    clean:
    	rm $(PVM_HOME)/master $(PVM_HOME)/slave
    	rm -f *.o
    

common definitions: header file to be included in both master and slave source code: def.h    SOURCE


    #include <stdio.h>
    #include <pvm3.h>
    
    #define SLAVENAME "slave"
    #define SLAVENUM   10
    
    #define NAMESIZE   64
    
    #define MSG_MSTR 1
    #define MSG_SLV  2
    

master task: source code of the master program: master.c    SOURCE

compile with: make


    #include "def.h"
    
    main()
    {
    	int mytid;
    	int tids[SLAVENUM];		/* slave task ids */
    	char slave_name[NAMESIZE];
    	int nproc, i, who;
    
    	mytid=pvm_mytid();
    
    	nproc=pvm_spawn(SLAVENAME, NULL, PvmTaskDefault, "", SLAVENUM, tids);
    
    	for( i=0 ; i<nproc ; i++ )
    	{
    		pvm_initsend(PvmDataDefault);
    		pvm_pkint(&mytid, 1, 1);
    		pvm_pkint(&i, 1, 1);
    	   	pvm_send(tids[i], MSG_MSTR);
    	}
    
    	for( i=0 ; i<nproc ; i++ )
    	{
    		pvm_recv( -1, MSG_SLV );
    		pvm_upkint(&who, 1, 1 );
    		pvm_upkstr(slave_name );
    		printf("%d: %s\n",who, slave_name);
    	}
    
    	pvm_exit();
    }
    

slave task: source code of the slave program you have to write by yourself


Mch 19.05.1997