5

I install MS-MPI

I like to code in sublime text specially C/C++

I run code in cmd using gcc/g++

How can I compile and run MPI codes from cmd

I don't like visual studio

So, is there any way i can compile and run my C/C++ MPI codes with MS-MPI in cmd

I know there is a question in title : Compile C++ MPI Code on Windows

but there's no clear answer or comment. that's why i am re-asking now

SHAH MD IMRAN HOSSAIN
  • 2,558
  • 2
  • 25
  • 44

2 Answers2

3

1.Download MS-MPI SDK and Redist installers and install them. The download link can be found at our homepage https://msdn.microsoft.com/en-us/library/bb524831.aspx

2.After installation you can verify that the MS-MPI environment variables have been set (you will want to use these env vars in Visual Studio) 3.Open up Visual Studio and create a new Visual C++ Win32 Console Application project. Let’s name it MPIHelloWorld and use default settings.

4.Setup the include directories so that the compiler can find the MS-MPI header files. Note that we will be building for 64 bits so we will point the include directory to $(MSMPI_INC);$(MSMPI_INC)\x64. If you will be building for 32 bits please use $(MSMPI_INC);$(MSMPI_INC)\x86

5.Setup the linker lib (notice I add msmpi.lib to the additional dependencies and also add $(MSMPI_LIB64) to the Additional Library Directories). Note that we will be building for 64 bits so we will point the Additional Library Directories to $(MSMPI_LIB64). If you will be building for 32 bits please use $(MSMPI_LIB32)If you see these error messages below it is most likely you're building for 32 bits yet specifying 64 bits linking libraries.

LNK1120: 5 unresolved externals LNK2019: unresolved external symbol _MPI_Comm_rank@8 referenced in function _main LNK2019: unresolved external symbol _MPI_Finalize@0 referenced in function _main LNK2019: unresolved external symbol _MPI_Init@8 referenced in function _main LNK2019: unresolved external symbol _MPI_Recv@28 referenced in function _main LNK2019: unresolved external symbol _MPI_Send@24 referenced in function _main 6.Code and build a simple Hello World program 7.Test run the program on the command line 8.I recommend that i use HPC Pack to run MPI across machines. However, you can still run jobs across different machines without HPC Pack, wherein you would need to install MS-MPI on all the machines and start SMPD daemon on each machine using the command smpd –d. Make sure you add the necessary firewall rules for your application. To launch the MPIHelloWorld.exe application with 2 processes, 1 on hostA and 1 on hostB, you can use the following command mpiexec -hosts 2 hostA 1 hostB 1 -wdir \hostA\c$\SomeDirectory MPIHelloWorld.exe

Alternatively, you can use the command line to compile and link your program (replacing steps 1-6 above). Note that I have added “C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64” to my path environment variable so that cl.exe and link.exe are available.

To compile your program into .obj files: cl /I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include" /I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include\x64" /I. /I"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include" /I"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include" /c MPIHelloWorld.cpp

Linking the .obj files: link /machine:x64 /out:MpiHelloWorld.exe /dynamicbase "msmpi.lib" /libpath:"C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\amd64" /LIBPATH:"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64" MPIHelloWorld.obj

imnain
  • 69
  • 5
0

But i personally recommend you to code using visual studio you get more benefits in compare to another if you are coding in c/c++ or any othr language and i also want to suggest you first off, VS 2008 is quite powerful and probably one of the best IDEs for C++ programming (at least with a supporting plugin such as Visual Assist X).

Beware, however, that C++ is a hard language to get right for the compilers and that the default warning level is quite lenient to boot. So it will tolerate bad/wrong code quite often. It is always advisable to check the code on other compilers as well – at the very least in g++ with high warning level in strict mode.

Also setting the warning level higher in Visual Studio is encouraged.

imnain
  • 69
  • 5