D语言的MPI

D语言的MPI,mpi,d,Mpi,D,这个问题与这个问题有关: 我正试图让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 **

这个问题与这个问题有关:

我正试图让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

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。那么我遗漏了什么呢?

您没有将
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返回range,所以我们使用
    array
    来获取它的数组

  • 获取数组指针


在Open MPI C中,通信器句柄是指向真实通信器结构的指针<代码>MPI_COMM_WORLD是指向预创建的WORLD communicator结构的指针,而不是您定义的空指针。这就是为什么Open MPI在调用
MPI\u COMM\u RANK
时中止的原因-这相当于在C中调用
MPI\u COMM\u RANK(NULL,&RANK)

如果查看
mpi.d
,您会注意到
mpi\u COMM\u WORLD
已经定义为:

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

因此,如果删除重新定义
MPI\u COMM\u WORLD

缺少括号的行,代码应该可以工作。在地图之前?好的,谢谢你指出这一点。但不幸的是,这并不能解决问题……:(Doh!我把它放在另一个版本的mpi.d上编译,但忘了删除它!谢谢。Sooo…它从我放在那里的时候就开始工作了吗?我确实接受拉取请求!我还在测试…到目前为止,这个简单的例子是正确的,但更复杂的东西不是,所以我试图找出原因…如果你觉得简单,无论如何拉取一个l哦。也许我能发现它。(如果不是的话,别担心。我会在某个时候更新的。)平,也许吧?有更新给我吗?@0b1100110:你可能已经注意到,我已经有一段时间没做这个了;)无论如何,我想拉一下,看看有没有下午我能玩它。我会给你发封电子邮件
MPI_COMM_WORLD      = cast(void*) &(ompi_mpi_comm_world),