MPI-CUDA-C++ Programing using MPI ,CUDA calls and C++


I wrote a simple program in C++ using file extension as .cu and used MPI libraries.
My program is as follows;

using namespace std;

int main(int argc, char *argv)
int MyRank, NumberOfProcessors, Root = 0;

    MPI::Init(argc, argv);
    NumberOfProcessors = MPI::COMM_WORLD.Get_size();
    MyRank = MPI::COMM_WORLD.Get_rank();

    if(MyRank == Root)
            cout<<"My Rank is ..";




When i am compiling i am getting following error.

I am compiling with the following command
nvcc -I/usr/local/mpich2-1.0.7/include -L/usr/local/mpich2-1.0.7/lib -lmpich -DMPICH_IGNORE_CXX_SEEK --host-compilation=C++ -o Sample_Program

And the error is
/tmp/tmpxft_00001609_00000000-11_Sample_Programm_C++.o: In function main': tmpxft_00001609_00000000-10_Sample_Programm_C++.ii:(.text+0x12f): undefined reference to MPI::Init(int&, char**&)’
tmpxft_00001609_00000000-10_Sample_Programm_C++.ii:(.text+0x134): undefined reference to MPI::COMM_WORLD' tmpxft_00001609_00000000-10_Sample_Programm_C++.ii:(.text+0x141): undefined reference to MPI::COMM_WORLD’
tmpxft_00001609_00000000-10_Sample_Programm_C++.ii:(.text+0x165): undefined reference to `MPI::Finalize()’

Can anyone tell me what is the problem??

Please use code tags next time!

Did u used the commands right, i mean, did you compiled this with NVCC, cause there’s AFAIK no need!

Thank you for your quick reply

I am compiling using the following command

nvcc -I/usr/local/mpich2-1.0.7/include -L/usr/local/mpich2-1.0.7/lib -lmpich -DMPICH_IGNORE_CXX_SEEK --host-compilation=C++ -o Sample_Program

Please see the command and tell me if any changes hev to be made.

Why don’t you use the default makefile delivered by NVidia SDK?

There you can include the namespaces/libraries!

Your need to link the C++ support library. Add -lmpichcxx. And read the MPICH documentation next time. This has absolutely nothing to do with CUDA.

Sorry for my ignorance. I dont know about NVIDIA SDK.

Till now i was writing programs in cuda, calling MPI libraries. Which is the mixed programing.

Then i thought can we write C++ also. They say that CUDA is extension of C. Will it support C++ also??

Thats why i wrote this simple program to see whether we can compile it or not.

I have used same flags expect the --host-compilation=C++ to compile the program CUDA which calls the MPI .

Then i surfed the net and got that we have to include the flag to compile C++.

I have got the above mentioned error.

Now can you guide me??

Thank you very much.
Its working after including that library.