OpenMPI: error: ‘MPI’ has not been declared

3.6k views Asked by At

Always get the following errors while running the OpenMPI command "mpicxx hello_cxx.cc -o hello"

hello_cxx.cc: In function ‘int main(int, char**)’: 
hello_cxx.cc:25:5: error: ‘MPI’ has not been declared
     MPI::Init();
     ^~~ hello_cxx.cc:26:12: error: ‘MPI’ has not been declared
     rank = MPI::COMM_WORLD.Get_rank();
            ^~~ hello_cxx.cc:27:12: error: ‘MPI’ has not been declared
     size = MPI::COMM_WORLD.Get_size();
            ^~~ hello_cxx.cc:31:5: error: ‘MPI’ has not been declared
     MPI::Finalize();
     ^~~
2

There are 2 answers

0
Gilles Gouaillardet On

Your application is using MPI C++ bindings. Keep in mind C++ bindings have been removed from the MPI standard.

From an Open MPI point of view, C++ bindings are still here, but they are no more built be default since Open MPI 2.0.0.

So if you are using Open MPI 2.0.0 or later, you first need to make sure C++ bindings were built. If not, you need to rebuild Open MPI, and configure with the --enable-mpi-cxx option.

On the long term, you should really move away from MPI C++ bindings. You can either use plain C bindings, or explore alternate C++ bindings such as the popular Boost:MPI library.

0
Zihao wang On

I also meet the problem,but I don't have root privileges. As the before answer mentioned , Open MPI 2.0.0 has changed the build mode.So you just need to change the grammar.

I meet the error:

error: ‘MPI’ has not been declared

mpifile = MPI::FILE_NULL;

From the openmp 2.0 api:

http://mpi-forum.org/docs/mpi-2.0/mpi-20-html/node217.htm#Node217

I find the new error handle is MPI_FILE_NULL.I change it directly in my code and then it works.

The next link is about the Deprecated since MPI-2.2:

http://mpi-forum.org/docs/mpi-2.2/mpi22-report/node328.htm#Node328