I am trying to build a code of PVM which have one master and one slave, (I am working on centOS 5.5 OS)
when I run a command aimk master1 slave1
, it is expected to give below output:-
Spawning 3 worker tasks ... SUCCESSFUL
I got 100.000000 from 1; (expecting 100.000000)
I got 200.000000 from 0; (expecting 200.000000)
I got 300.000000 from 2; (expecting 300.000000)
But it shows
pvm> [1:t80002] EOF
[1:t80001] Spawning 6 worker tasks.....
[1:t80001] Trouble spawning slaves. Aborting.Error codes are:
[1:t80001] TID 3 -7
[1:t80001] TID 4 -7
[1:t80001] TID 5 -7
[1:t80001] libpvm [t80005] : pvm_mcast() : Bad parameter
[1:t80003] EOF
[1:t80004] EOF
Why it gives this error? why slaves are not working? My codes are below, Help me in this problem.
Master1.c
static char rcsid[] =
"$Id: master1.c,v 1.4 1997/07/09 13:25:09 pvmsrc Exp $";
#include <stdio.h>
#include "pvm3.h"
#define SLAVENAME "slave1"
main()
{
int mytid; /* my task id */
int tids[32]; /* slave task ids */
int n, nproc, numt, i, who, msgtype, nhost, narch;
float data[100], result[32];
struct pvmhostinfo *hostp;
/* enroll in pvm */
mytid = pvm_mytid();
/* Set number of slaves to start */
pvm_config( &nhost, &narch, &hostp );
nproc = nhost * 3;
if( nproc > 32 ) nproc = 32 ;
printf("Spawning %d worker tasks ... " , nproc);
/* start up slave tasks */
numt=pvm_spawn(SLAVENAME, (char**)0, 0, "", nproc, tids);
if( numt < nproc ){
printf("\n Trouble spawning slaves. Aborting. Error codes are:\n");
for( i=numt ; i<nproc ; i++ ) {
printf("TID %d %d\n",i,tids[i]);
}
for( i=0 ; i<numt ; i++ ){
pvm_kill( tids[i] );
}
pvm_exit();
exit(1);
}
printf("SUCCESSFUL\n");
/* Begin User Program */
n = 100;
/* initialize_data( data, n ); */
for( i=0 ; i<n ; i++ ){
data[i] = 1.0;
}
/* Broadcast initial data to slave tasks */
pvm_initsend(PvmDataDefault);
pvm_pkint(&nproc, 1, 1);
pvm_pkint(tids, nproc, 1);
pvm_pkint(&n, 1, 1);
pvm_pkfloat(data, n, 1);
pvm_mcast(tids, nproc, 0);
/* Wait for results from slaves */
msgtype = 5;
for( i=0 ; i<nproc ; i++ ){
pvm_recv( -1, msgtype );
pvm_upkint( &who, 1, 1 );
pvm_upkfloat( &result[who], 1, 1 );
printf("I got %f from %d; ",result[who],who);
if (who == 0)
printf( "(expecting %f)\n", (nproc - 1) * 100.0);
else
printf( "(expecting %f)\n", (2 * who - 1) * 100.0);
}
/* Program Finished exit PVM before stopping */
pvm_exit();
}
slave1.c
static char rcsid[] =
"$Id: slave1.c,v 1.2 1997/07/09 13:25:18 pvmsrc Exp $";
#include <stdio.h>
#include "pvm3.h"
main()
{
int mytid; /* my task id */
int tids[32]; /* task ids */
int n, me, i, nproc, master, msgtype;
float data[100], result;
float work();
/* enroll in pvm */
mytid = pvm_mytid();
/* Receive data from master */
msgtype = 0;
pvm_recv( -1, msgtype );
pvm_upkint(&nproc, 1, 1);
pvm_upkint(tids, nproc, 1);
pvm_upkint(&n, 1, 1);
pvm_upkfloat(data, n, 1);
/* Determine which slave I am (0 -- nproc-1) */
for( i=0; i<nproc ; i++ )
if( mytid == tids[i] ){ me = i; break; }
/* Do calculations with data */
result = work( me, n, data, tids, nproc );
/* Send result to master */
pvm_initsend( PvmDataDefault );
pvm_pkint( &me, 1, 1 );
pvm_pkfloat( &result, 1, 1 );
msgtype = 5;
master = pvm_parent();
pvm_send( master, msgtype );
/* Program finished. Exit PVM before stopping */
pvm_exit();
}
float
work(me, n, data, tids, nproc )
/* Simple example: slaves exchange data with left neighbor (wrapping) */
int me, n, *tids, nproc;
float *data;
{
int i, dest;
float psum = 0.0;
float sum = 0.0;
for( i=0 ; i<n ; i++ ){
sum += me * data[i];
}
/* illustrate node-to-node communication */
pvm_initsend( PvmDataDefault );
pvm_pkfloat( &sum, 1, 1 );
dest = me+1;
if( dest == nproc ) dest = 0;
pvm_send( tids[dest], 22 );
pvm_recv( -1, 22 );
pvm_upkfloat( &psum, 1, 1 );
return( sum+psum );
}
Obviously PVM is not finding your slaves' executable. Examine this portion of the output:
All task IDs are
-7
, which isPvmNoFile
. Ensure thatSLAVENAME
(slave1
in your case) is either an absolute file path (which it's not in your case) or is the name of an executable file, located in the PVM search path. By default the PVM search path is:where
$HOME
is your user's home directory path and$PVM_ARCH
is the name of the PVM architecture.