mpirun无法找到指定的可执行文件

时间:2014-12-18 05:30:11

标签: c++ mpi

我在使用OpenMPI编译此代码时遇到问题。由于我对使用OpenMPI的概念有点新,如果有人能够在这里给我一个提示,那就太好了。 编译工作正常,但如果我运行代码,我收到此消息:

mpirun was unable to find the specified executable file, and therefore
did not launch the job.  This error was first reported for process
rank 0; it may have occurred for other processes as well.

NOTE: A common cause for this error is misspelling a mpirun command
      line parameter option (remember that mpirun interprets the first
      unrecognized command line token as the executable).  

我正在编译:

mpic++ matmult.cpp -o matmult

并运行:

mpirun -n 2 matmult

...这是使用过的代码:

#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#define MASTER 0
#define FROM_MASTER 1
#define FROM_WORKER 2

// ---------------------------------------------------------------------------
// allocate space for empty matrix A[row][col]
// access to matrix elements possible with:
// - A[row][col]
// - A[0][row*col]

float **alloc_mat(int row, int col)
{
    float **A1, *A2;

    A1 = (float **)calloc(row, sizeof(float *));        // pointer on rows
    A2 = (float *)calloc(row*col, sizeof(float));    // all matrix elements
    for (int i = 0; i < row; i++)
        A1[i] = A2 + i*col;

    return A1;
}

// ---------------------------------------------------------------------------
// random initialisation of matrix with values [0..9]

   void init_mat(float **A, int row, int col)
   {
       for (int i = 0; i < row*col; i++)
            A[0][i] = (float)(rand() % 10);
   }

    // ---------------------------------------------------------------------------
    // DEBUG FUNCTION: printout of all matrix elements

   void print_mat(float **A, int row, int col, char *tag)
   {
    int i, j;

    printf("Matrix %s:\n", tag);
    for (i = 0; i < row; i++)
    {
        for (j = 0; j < col; j++) 
            printf("%6.1f   ", A[i][j]);
        printf("\n"); 
    }
}

// ---------------------------------------------------------------------------

int main(int argc, char *argv[]) {   
    int numtasks;
    int taskid;
    int numworkers;
    int source;
    int dest;
    int mtype;
    int rows;
    int averow, extra, offset;
    double starttime, endtime;
    float **A, **B, **C;    // matrices
    int d1, d2, d3;         // dimensions of matrices
    int i, j, k, rc;            // loop variables


    MPI_Status status;
    MPI_Init(&argc,&argv);
    MPI_Comm_rank(MPI_COMM_WORLD,&taskid);
    MPI_Comm_size(MPI_COMM_WORLD,&numtasks);

    if (argc != 4) {
        printf ("Matrix multiplication: C = A x B\n");
        printf ("Usage: %s <NumRowA> <NumColA> <NumColB>\n", argv[0]); 
        return 0;
    }

    if (numtasks < 2 ) {
    printf("Need at least two MPI tasks. Quitting...\n");
    MPI_Abort(MPI_COMM_WORLD,rc);
    exit(1);
    }

     /* read user input */
    d1 = atoi(argv[1]);     // rows of A and C  d1
    d2 = atoi(argv[2]);     // cols of A and rows of B  d2
    d3 = atoi(argv[3]);     // cols of B and C d3

    printf("Matrix sizes C[%d][%d] = A[%d][%d] x B[%d][%d]\n", d1, d3, d1, d2, d2, d3);

    /* prepare matrices */
    A = alloc_mat(d1, d2);
    init_mat(A, d1, d2); 
    B = alloc_mat(d2, d3);
    init_mat(B, d2, d3);
    C = alloc_mat(d1, d3);


     /* Code für den Manager */
    if (taskid == MASTER) {
        /*printf("matrix multiplikation withMPI\n");
        printf("initializing arrays ...\n");
            for (i=0; i<d1; i++) 
                for (j=0; j<d2; j++) 
                A[i][j]=i+j;


            for (i=0; i<d2; i++) 
                for (j=0; j<d3; j++) 
                B[i][j]=i*j;*/



             /* Matrizen versenden */
            averow = d1/numworkers;
            extra = d1%numworkers;
            offset = 0;
            mtype = FROM_MASTER;

            starttime=MPI_Wtime();

            for (dest=1;dest<=numworkers;dest++) {
                rows = (dest <= extra) ? averow+1 :averow;
                printf("Sending %drows to task %doffset=%d\n",rows,dest,offset);
                MPI_Send(&offset, 1, MPI_INT,dest,mtype, MPI_COMM_WORLD);
                MPI_Send(&rows, 1, MPI_INT,dest,mtype, MPI_COMM_WORLD);
                MPI_Send(&A[offset][0],rows*d2, MPI_DOUBLE,dest,mtype, MPI_COMM_WORLD);
                MPI_Send(&B, d2*d3, MPI_DOUBLE,dest,mtype, MPI_COMM_WORLD);
                offset =offset+rows;
            }

             /* Ergebnisse empfangen */
             mtype = FROM_WORKER;

            for (i=1; i<=numworkers; i++) {
                source = i;
                MPI_Recv(&offset, 1, MPI_INT,source,mtype, MPI_COMM_WORLD, &status);
                MPI_Recv(&rows, 1, MPI_INT,source,mtype, MPI_COMM_WORLD, &status);
                MPI_Recv(&C[offset][0],rows*d3, 
                MPI_DOUBLE,source,mtype,MPI_COMM_WORLD,&status);
                printf("Received results from task %d\n",source);
            }

            endtime=MPI_Wtime();
            printf("\nIt took %fseconds.\n",endtime-starttime);
     }       

    /* Code für die Arbeiter */

    if (taskid > MASTER) {
        mtype = FROM_MASTER;

        MPI_Recv(&offset, 1, MPI_INT, MASTER,mtype, MPI_COMM_WORLD, &status);
        MPI_Recv(&d1, 1, MPI_INT, MASTER,mtype, MPI_COMM_WORLD, &status);
        MPI_Recv(&A,rows*d2, MPI_DOUBLE, MASTER,mtype, MPI_COMM_WORLD, &status);
        MPI_Recv(&B, d2*d3, MPI_DOUBLE, MASTER,mtype, MPI_COMM_WORLD, &status);

    /* print user instruction */


    // no initialisation of C, because it gets filled by matmult

    /* serial version of matmult */
        printf("Perform matrix multiplication...\n");
        for (i = 0; i < d1; i++)
            for (j = 0; j < d3; j++)
                for (k = 0; k < d2; k++)
                C[i][j] += A[i][k] * B[k][j];

        mtype = FROM_WORKER;
        MPI_Send(&offset, 1, MPI_INT, MASTER,mtype, MPI_COMM_WORLD);
        MPI_Send(&d1, 1, MPI_INT, MASTER,mtype, MPI_COMM_WORLD);
        MPI_Send(&C,rows*d3, MPI_DOUBLE, MASTER,mtype, MPI_COMM_WORLD);

    }

    MPI_Finalize();


    /* test output 
    print_mat(A, d1, d2, "A"); 
    print_mat(B, d2, d3, "B"); 
    print_mat(C, d1, d3, "C"); */

    printf ("\nDone.\n");


    //return 0;
}


正在运行的结果 mpirun matmult (默认设置,单个流程)

  由于进程等级为0,节点上的PID为77202,因此mpirun已退出   juliuss-mbp-3退出不当。这可能有三个原因   发生:

     
      
  1. 此过程未调用&#34; init&#34;在退出之前,但在其他人中   工作做了。这可能导致作业在等待时无限期挂起   对于所有进程调用&#34; init&#34;。按规则,如果一个进程调用   &#34; init&#34;然后所有进程必须调用&#34; init&#34;在终止之前。

  2.   
  3. 此过程名为&#34; init&#34;,但退出时未调用&#34;最终确定&#34;。按规则,所有调用&#34; init&#34;必须打电话   &#34;完成&#34;退出之前或将被视为异常   终止&#34;

  4.   
  5. 此过程称为&#34; MPI_Abort&#34;或&#34; orte_abort&#34;并且mca参数orte_create_session_dirs设置为false。在这种情况下,   运行时无法检测到中止调用是否异常   终止。因此,您将收到的唯一错误消息是此   一。这可能导致应用程序中的其他进程   由mpirun发送的信号终止(如此处所述)。您可以   通过在mpirun命令行上指定-quiet来避免此消息。

  6.   

1 个答案:

答案 0 :(得分:0)

次要问题(仍然很重要):

你的程序期望参数计数为4, ie。程序名+在中传递的3个参数,来自以下代码:

if (argc != 4) {
    printf ("Matrix multiplication: C = A x B\n");
    printf ("Usage: %s <NumRowA> <NumColA> <NumColB>\n", argv[0]); 
    return 0;
}

由于此条件返回0而未调用正确的MPI_Abort(...)MPI_Finalize(),因此您将收到mpi错误:

  由于进程排名为0,节点juliuss-mbp-3上的PID 77202退出不正确,mpirun已退出。

MPI_Abort(MPI_COMM_WORLD,rc);之前添加return 0我相信您的计划将一目了然。

if (argc != 4) {
    printf ("Matrix multiplication: C = A x B\n");
    printf ("Usage: %s <NumRowA> <NumColA> <NumColB>\n", argv[0]);
    MPI_Abort(MPI_COMM_WORLD,rc);
    return 0;
}


主要问题:

但是我们应该解决问题的主要原因,即:当您运行mpirun -np 2 matmultmpirun matmult时,需要将3个参数传递给您的程序。应该采用以下格式:

mpirun -np 2 matmult parameter1 parameter2 parameter3

mpirun matmult parameter1 parameter2 parameter3

从您的代码中,参数(参数)应为:

parameter1 = rows of A and C
parameter2 = cols of A and rows of B
parameter3 = cols of B and C

并且您的运行命令可能如下所示:

mpirun -np 2 matmult 2 2 2