【问题标题】:MPI for the D programming languageD 编程语言的 MPI
【发布时间】:2013-02-06 14:47:57
【问题描述】:

这个问题和这个问题有关:MPI and D: Linker Options

我正在尝试让 MPI 从 D 中工作。在网上可以找到几篇帖子,但我发现没有一个确实有效...所以这是我到目前为止所做的:

我从这里https://github.com/1100110/OpenMPI/blob/master/mpi.d 获取了 mpi.d 并设置了一个最小程序:

import mpi;
import std.stdio;

void* MPI_COMM_WORLD = cast(void*)0;

int main(string[] args)
{

  int rank, size;
  int argc = cast(int)args.length;
  char *** argv = cast(char***)&args;


  MPI_Init (&argc, argv);   /* starts MPI */
  MPI_Comm_rank (MPI_COMM_WORLD, &rank);    /* get current process id */
  MPI_Comm_size (MPI_COMM_WORLD, &size);    /* get number of processes */
  writefln( "Hello world from process %d of %d", rank, size );
  MPI_Finalize();

  return 0;
}

我用

编译
dmd test_mpi.d -L-L/usr/lib/openmpi -L-lmpi -L-ldl -L-lhwloc

gdc test_mpi.d -pthread -L/usr/lib/openmpi -lmpi -ldl -lhwloc -o test_mpi

并运行

mpirun -n 2 ./test_mpi

这是我得到的错误:

[box:1871] *** An error occurred in MPI_Comm_rank
[box:1871] *** on communicator MPI_COMM_WORLD
[box:1871] *** MPI_ERR_COMM: invalid communicator
[box:1871] *** MPI_ERRORS_ARE_FATAL: your MPI job will now abort
--------------------------------------------------------------------------
mpirun has exited due to process rank 0 with PID 1870 on
node bermuda-iii exiting improperly. There are two reasons this could occur:

1. this process did not call "init" before exiting, but others in
the job did. This can cause a job to hang indefinitely while it waits
for all processes to call "init". By rule, if one process calls "init",
then ALL processes must call "init" prior to termination.

2. this process called "init", but exited without calling "finalize".
By rule, all processes that call "init" MUST call "finalize" prior to
exiting or it will be considered an "abnormal termination"

This may have caused other processes in the application to be
terminated by signals sent by mpirun (as reported here).
--------------------------------------------------------------------------
[box:01869] 1 more process has sent help message help-mpi-errors.txt / mpi_errors_are_fatal
[box:01869] Set MCA parameter "orte_base_help_aggregate" to 0 to see all help / error messages

显然我确实调用了 MPI_Init 和 MPI_Finalize。那我错过了什么?

【问题讨论】:

  • Sooo... 从我把它放在那里的时候它还在工作吗?我接受拉取请求!
  • 我仍在测试......到目前为止,这个简单的例子可以正常工作,但更复杂的东西却没有,所以我试图找出原因......
  • 如果你觉得容易的话,随便拉,让我看看。也许我能发现它。 (如果不是,请不要担心。我会在某个时候更新。)
  • ping,也许?有更新给我吗?
  • @0b1100110:你可能已经注意到了,我有一段时间没有做这个了;)不管怎样,我想看看有没有一个下午我会玩它。我会给你发一封电子邮件

标签: mpi d


【解决方案1】:

在 Open MPI C 中,通信器句柄是指向实际通信器结构的指针。 MPI_COMM_WORLD 是指向预先创建的世界通信器结构的指针,而不是您定义的 NULL 指针。这就是 Open MPI 在调用 MPI_COMM_RANK 时中止的原因——它相当于在 C 中调用 MPI_Comm_rank(NULL, &rank)

如果查看mpi.d 中的line 808,您会注意到MPI_COMM_WORLD 已经定义为:

MPI_COMM_WORLD      = cast(void*) &(ompi_mpi_comm_world),

因此,如果您删除重新定义 MPI_COMM_WORLD 的行,您的代码应该可以工作。

【讨论】:

  • 噢!我把它和另一个版本的 mpi.d 一起编译却忘了删除它!谢谢。
【解决方案2】:

您没有将string[] 转换为char*** 对。你应该这样做:

import std.string, std.algorithm, std.array;

char** argv = cast(char**)map!(toStringz)(args).array.ptr;
MPI_Init (&argc, &argv);

它是这样工作的:

  • 在每个 args 元素上映射 toStringz

  • 因为map返回范围,所以我们使用array来拥有它的数组。

  • 获取数组指针。

【讨论】:

  • 缺少括号。在地图之前?
  • 好的,感谢您指出这一点。但不幸的是它不能解决问题...... :(
猜你喜欢
  • 2010-11-15
  • 1970-01-01
  • 2015-09-08
  • 1970-01-01
  • 1970-01-01
  • 2014-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多