I have the following example
#include <iostream>
#include <mpi.h>
int main(int argc, char** argv){
int process_Rank, size_Of_Cluster;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size_Of_Cluster);
MPI_Comm_rank(MPI_COMM_WORLD, &process_Rank);
for(int i = 0; i < size_Of_Cluster; i++){
if(i == process_Rank){
std::cout << "Hello World from process " << process_Rank<< " of " <<
size_Of_Cluster << std::endl;
}
MPI_Barrier(MPI_COMM_WORLD);
}
MPI_Finalize();
return 0;
}
When I execute <some_dir>/mpic++ parallel_ex.cpp
it runs fine.
However, if I execute
<some_dir>/mpic++ -show
I am getting:
g++ -Wl,-Bsymbolic-functions -Wl,-z,relro -I/usr/include/x86_64-linux-gnu/mpich -L/usr/lib/x86_64-linux-gnu -lmpichcxx -lmpich
and now If I compile like this
g++ -Wl,-Bsymbolic-functions -Wl,-z,relro -I/usr/include/x86_64-linux-gnu/mpich -L/usr/lib/x86_64-linux-gnu -lmpichcxx -lmpich parallel_ex.cpp
I am getting:
parallel_ex.cpp:(.text+0x31): undefined reference to `MPI_Init' /usr/bin/ld: parallel_ex.cpp:(.text+0x42): undefined reference to `MPI_Comm_size' /usr/bin/ld: parallel_ex.cpp:(.text+0x53): undefined reference to `MPI_Comm_rank' /usr/bin/ld: parallel_ex.cpp:(.text+0xcb): undefined reference to `MPI_Barrier' /usr/bin/ld: parallel_ex.cpp:(.text+0xd6): undefined reference to `MPI_Finalize' collect2: error: ld returned 1 exit status
Why is this happening? It doesn't make sense, does it?