Errors in 'hello world' C++ MPI program in Windows

Hello all,

I am a scientific programmer but very new to MPI. I am trying to make classic 'hello world' program on Windows OS, gcc with code::blocks IDE or VC++ compiler. The reason I am working with gcc is I am familiar with that and not with Visual Studio.

Here the program goes:


1
2
3
4
5
6
7
8
9
10
  #include <iostream>
#include <mpi.h>
using namespace std;

int main(int argc, char ** argv)
{
MPI_Init(&argc,&argv);
cout<<"Hello World!"<<endl;
MPI_Finalize();
}


Here is how I compiled the program

 
g++ -o file file.cpp -I "C:\Program Files\Microsoft HPC Pack 2008 R2\Inc" -L "C:\Program Files\Microsoft HPC Pack 2008 R2\Lib\amd64" -lmsmpi -O3


I tried hard to get some info and link, compile the program, however I get errors:

1
2
undefined reference to `MPI_Init@8
undefined reference to `MPI_Finalize@0


Should I use wrapper instead of g++?

It is frustrating experience in compiling after spending huge amount of time in searching and reading tutorials, especially most of them are for unix based OS. Not much on Windows with gcc; at least, I couldn't find that. So it is worth using gcc in this case or better to go for visual c++, at least there is good amount of information is available. Any help much appreciated.
First, definitely use the wrapper instead of g++. Its fine to use - it is just a wrapper after all, all it does is manipulate flags and link you to the correct MPI objects. If you still want to do it with G++, this makefile should work (note you still sort of need to use the wrapper here):
1
2
3
4
5
MPI_COMPILE_FLAGS = $(shell mpicc --showme:compile)
MPI_LINK_FLAGS = $(shell mpicc --showme:link)

all: file.cpp
        $(CXX) $(MPI_COMPILE_FLAGS) file.cpp $(MPI_LINK_FLAGS) -o file

You'll also need to run this in some kind of bash to get the shell command to work properly (can't remember off the top of my head the cmd variant / workaround). If you are using MinGW than MSYS should work just fine.

In general, though, until you understand what you are doing just do it the way you are supposed to - fiddle around with doing how you feel you should be doing it once you've actually worked out that you will be sticking around with it.
Last edited on
Thank you very much for your answer. However can you speak in Windows ? I searched a lot and almost everything is in Unix based os. I am getting real hard time even to get started with simple hello world program in windows.
Topic archived. No new replies allowed.