这个问题与这个问题有关:MPI和D:链接器选项
我试图让MPI从D工作.网上有几个帖子,但我找不到的确实有效...所以这就是我到目前为止所做的:
我从这里获取了mpi.d https://github.com/1100110/OpenMPI/blob/master/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;
}
Run Code Online (Sandbox Code Playgroud)
我编译
dmd test_mpi.d -L-L/usr/lib/openmpi -L-lmpi -L-ldl -L-lhwloc
Run Code Online (Sandbox Code Playgroud)
要么
gdc test_mpi.d -pthread -L/usr/lib/openmpi -lmpi -ldl -lhwloc -o test_mpi
Run Code Online (Sandbox Code Playgroud)
并运行
mpirun -n 2 ./test_mpi
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
[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
Run Code Online (Sandbox Code Playgroud)
显然我会调用MPI_Init和MPI_Finalize.那我错过了什么?
在Open MPI C中,通信器句柄是指向真实通信器结构的指针.MPI_COMM_WORLD是指定预先创建的世界通信器结构的指针,而不是定义它时的NULL指针.这就是Open MPI在调用中中止的原因MPI_COMM_RANK- 它相当于MPI_Comm_rank(NULL, &rank)在C中调用.
如果你看看行808的mpi.d,你会发现MPI_COMM_WORLD已经被定义为:
MPI_COMM_WORLD = cast(void*) &(ompi_mpi_comm_world),
Run Code Online (Sandbox Code Playgroud)
因此,如果删除重新定义的行,则代码应该有效MPI_COMM_WORLD.
| 归档时间: |
|
| 查看次数: |
1061 次 |
| 最近记录: |