问题
I'm trying to use MPI with the D programming language. D fully supports the C ABI and can link with and call any C code. I've done the obvious stuff and translated the MPI header to D. I then translated a test program from Wikipedia to D. I compiled it with the following command:
dmd test.d -L-lmpistubs
It works when I just run ./test
, and prints:
0: We have 1 processors
However, when I run with mpiexec -n 8 test
, it prints nothing. My understanding is that MPI executables require a bunch of weird linking options, which is why tools like mpicc
exist to automate the process. However, this doesn't help me if I'm trying to use MPI in D. I assume it's because I'm not using the right linker options. Can someone please tell me what mpicc
does and how I can make DMD do the same thing?
Edit: I've found the answer using mpicc -showme
. This shows what commands mpicc
forwards to gcc
. However, I also realized I did the header file translation wrong. Next question: How do to it right.
回答1:
mpicc is common name of different scripts and even programs.
Some of them have option like -echo
, -show
, -compile-info
, -link-info
or -showme
or environment option to show what is actually called.
Try to check what is it actually with
file -k `which mpicc`
If it is script, it can be written in sh, bash, perl, python. You can easily view it and find correct option. If it is an program, try to run
strings `which mpicc`
Sometimes strings
can extract option names and/or environment variables which controls the work of script.
Also, most of mpicc check CC env variable to get name of compiler. You can write a script or a program which will just print its arguments and set CC env to this program.
来源:https://stackoverflow.com/questions/6944691/mpi-and-d-linker-options