Sie sind auf Seite 1von 4

Denny Hermawanto 2011

MPICH2 Parallel Computing using Code::Blocks C++ IDE


Here is the installation procedure of MPICH2 parallel computing library on CodeBlock
C++ IDE:

1. Download and install MPICH2 library from


http://www.mcs.anl.gov/research/projects/mpich2/

2. Don’t forget to add MPICH2 PATH to your user environment variable.

2. Open your CodeBlock C++ IDE

3. Point to "Settings" menu and select "Compiler and debugger"

4. Go to "Linker settings" tab, in the Link Library box click "Add".


From the pop-up windows browse to MPICH lib directory and select mpi.lib
then click OK to return to compiler setting window.
Denny Hermawanto 2011

5. Go to "Search Directories" tab. In the "Compiler" option click Add and point to your
MPICH2 include folder path. Usually, it located in C:\Program Files\MPICH2\include
Denny Hermawanto 2011

6. Now you can test your MPICH based program.

7. Create new project (File->New->Project->Console Application)

8. In the main.cpp write this code:

#include <iostream>
#include "mpi.h"
#include <string>

using namespace std;

int main(int argc, char *argv[])


{
int my_rank;
int size;
MPI_Init(&argc, &argv); /*START MPI */

/*DETERMINE RANK OF THIS PROCESSOR*/


MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

/*DETERMINE TOTAL NUMBER OF PROCESSORS*/


MPI_Comm_size(MPI_COMM_WORLD, &size);

printf("Hello world! I'm rank (processor number) %d of %d processor \n",


my_rank, size);

MPI_Finalize(); /* EXIT MPI */

return 0;
}

9. Build the code (Ctrl-F9) and your executable program result will be in folder
bin/Debug of your project folder.

To run your parallel program, you must launch it using mpiexec.exe if you use Windows
Operating System. Follow these steps:

1. Open console and change directory to the executable file in your project path. For
example, my program is located in this folder:
E:\My Documents\C++ Project\MPI\bin\Debug
Denny Hermawanto 2011

2. Suppose you want to execute your parallel program named MPI.exe using 2 nodes
locally (in your computer only), the script to execute program will look like this:
E:\My Documents\C++ Project\MPI\bin\Debug>mpiexec -n 2 -localonly MPI

13. Then the correct output will be like this:


Hello world! I'm rank (processor number) 0 of 2 processor
Hello world! I'm rank (processor number) 1 of 2 processor

14. Then you are ready to code using MPICH2 using CodeBlocks C++ IDE...

Happy parallel computing!!! :)

Das könnte Ihnen auch gefallen