2013-02-06 47 views
4

這個問題是涉及到這樣一個問題:MPI and D: Linker OptionsMPI爲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; 
} 

01編譯2353496819369

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。那麼我錯過了什麼?

+0

Sooo ...當我離開它時它還在工作嗎?我確實接受拉請求! – 0b1100110

+0

我還在測試.​​..迄今爲止這個簡單的例子wroks,但更復雜的東西不,所以我想弄清楚爲什麼... – steffen

+0

如果它很容易,反正拉,讓我看看。也許我會發現它。 (如果不是不用擔心,我會在某個時候更新) – 0b1100110

回答

6

在Open MPI中C通信器句柄是指向真正的通信器結構的指針。 MPI_COMM_WORLD是一個指向預先創建的世界通信器結構的指針,而不是您定義它的NULL指針。這就是爲什麼開放MPI呼叫中止對MPI_COMM_RANK - 這相當於C.

調用 MPI_Comm_rank(NULL, &rank)

如果你看一看的mpi.dline 808,你會注意到MPI_COMM_WORLD已經被定義爲:

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

所以你的代碼應該工作,如果你刪除你重新定義的行MPI_COMM_WORLD

+0

衛生署!我把那與mpi.d的另一個版本編譯時忘了刪除它!謝謝。 – steffen

3

你沒有鑄造string[]char***沒錯。你應該這樣做,而不是:

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

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

下面是它如何工作的:

  • 地圖toStringz每個args元素。

  • 因爲地圖返回範圍,所以我們使用array來排列它。

  • 獲取數組指針。

+0

有一個括號缺失。在地圖之前? – steffen

+0

修正了它,謝謝。 – Robik

+0

好的,謝謝你指出。不過遺憾的是它並沒有解決問題... :( – steffen