0
我試圖建立具有一個主站和一個從PVM的代碼,(我的工作在CentOS 5.5 OS)爲什麼奴隸沒有在PVM(並行虛擬機)的工作
當我運行一個命令aimk master1 slave1
,它有望給以下的輸出: -
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)
但它顯示
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
爲什麼它給這個錯誤?爲什麼奴隸不工作? 我的代碼如下,幫我解決這個問題。
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);
}
好的,我嘗試你的指示,之後我會回覆你。 – devsda 2013-02-22 12:57:42
在運行Linux的x86上,架構名稱很可能是'LINUX'。 – 2013-02-22 13:05:55
在我的系統中,它是LINUX64。 – devsda 2013-02-22 13:13:04