0

我正在尝试构建一个具有一个主机和一个从机的 PVM 代码,(我正在使用 centOS 5.5 操作系统)

当我运行命令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

为什么会出现此错误?为什么奴隶不工作?我的代码如下,帮助我解决这个问题。

大师1.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 );
}
4

1 回答 1

0

显然 PVM 没有找到你的从属的可执行文件。检查这部分输出:

[1:t80001] TID 3 -7
[1:t80001] TID 4 -7
[1:t80001] TID 5 -7

所有任务 ID 都是-7,即PvmNoFile。确保SLAVENAME(slave1在您的情况下) 是绝对文件路径(在您的情况下不是)或者是位于 PVM 搜索路径中的可执行文件的名称。默认情况下,PVM 搜索路径为:

$HOME/pvm3/bin/$PVM_ARCH/

其中$HOME是用户的主目录路径,$PVM_ARCH是 PVM 架构的名称。

于 2013-02-22T12:54:58.533 回答