MPI基本的例子不工作 [英] MPI basic example doesn't work

查看:559
本文介绍了MPI基本的例子不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解什么是由下面的例子的意思是:

I am trying to understand what was meant by the example below:

#include "mpi.h"
#include <stdio.h>

int main(int argc, char *argv[]) {
  int numtasks, rank, dest, source, rc, count, tag = 1;
  char inmsg, outmsg = 'x';
  MPI_Status Stat;

  MPI_Init(&argc, &argv);
  MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);

  if (rank == 0) {
    dest = 1;
    source = 1;
    rc = MPI_Send(&outmsg, 1, MPI_CHAR, dest, tag, MPI_COMM_WORLD);
    rc = MPI_Recv(&inmsg, 1, MPI_CHAR, source, tag, MPI_COMM_WORLD, &Stat);
  } else if (rank == 1) {
    dest = 0;
    source = 0;
    rc = MPI_Recv(&inmsg, 1, MPI_CHAR, source, tag, MPI_COMM_WORLD, &Stat);
    rc = MPI_Send(&outmsg, 1, MPI_CHAR, dest, tag, MPI_COMM_WORLD);
  }

  rc = MPI_Get_count(&Stat, MPI_CHAR, &count);
  printf("Task %d: Received %d char(s) from task %d with tag %d \n",
         rank, count, Stat.MPI_SOURCE, Stat.MPI_TAG);

  MPI_Finalize();
}

https://computing.llnl.gov/tutorials/mpi/实际上从这里复制一>

Essentially copied from here: https://computing.llnl.gov/tutorials/mpi/

编译如下:

$ mpicc -o ./mpi_test ./mpi_test.c

像这样运行:

$ ./mpi_test 

给出了这样的错误:

Gives this error:

Fatal error in MPI_Send: Invalid rank, error stack:
MPI_Send(171): MPI_Send(buf=0x7fff787b4d93, count=1, MPI_CHAR, dest=1, tag=1, MPI_COMM_WORLD) failed
MPI_Send(97).: Invalid rank has value 1 but must be nonnegative and less than 1

说实话,我不明白为什么例子应该摆在首位工作过。你能告诉我吗?是例如错误的,或者是错误预期?也许我的设置是错误的?

To be honest, I don't understand why the example should have worked in the first place. Can you please enlighten me? Is the example wrong, or is the error expected? Perhaps my setup is wrong?

PS。用gcc 4.7在Fedora 18 AMD64编译

PS. Compiled with gcc 4.7 on Fedora 18 amd64

推荐答案

您在使用运行程序的mpirun 如下:

You have to run your program using mpirun as follows:

mpirun -np 2 mpi_test

这篇关于MPI基本的例子不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆