how to run mpi under codeblocks

2
http://www.blog.kubiak.co.uk/post/44 Page 1 of 2 Oct 25, 2013 12:13:56AM MDT How to run MPI under CodeBlocks ? kubiak.co.uk MPI in CodeBlocks Codeblocks is great application development platform for serial code, however when it came to Fluid Dynamic you realize that serial code, executed on a single processor is very slow, one of the solution is to use openMP especially for multicore processor, but to do some serious computation you need MPI (Message Passing Interface). Only then, you can run you code on hundreds of processors and your application really take-off. Unfortunately Codeblocks (my favourite open source IDE) don’t support MPI programs. Hopefully, when this is an open source you can solve the problem by your self. Here is my solution to run console MPI code from Codeblocks: First you need to compile you mpi code and link it to mpi library: Under Windows you need to configure: In Project/Build options/Linker settings/Add mpi (under linux add m or lm) In Search directories/Compiler/Add C:\Program Files\MPICH2\include In Search directories/Linker/Add C:\Program Files\MPICH2\lib In linux you need to compile the code using mpicc go to Setting/Compiler and Debugger… and create a copy of GNU GCC Compiler with new name GNU GCC Compiler MPI. Go to Toolchain executables and replace the gcc and g++ with mpicc and mpicxx. Next step is to change you MPI project building setting to use new compiler setting. This should compile your parallel code. Now we need to start the executable using mpiexec or mpirun. Our console program on windows is executed by cb_console_runner.exe and there is no support for other host program if your project is console application (most of parallel programs are). A few simple modification in cb_console_runner.exe allow to define argument. -mpi Argument this must be define in Codeblocks menu in Project -> Set programs’ arguments? -mpi <path to mpiexec> -n <number of processes> example: -mpi C:/Progra~1/MPICH2/bin/mpiexec -n 8 or (for linux)

Upload: lolo406

Post on 20-Oct-2015

205 views

Category:

Documents


13 download

TRANSCRIPT

  • http://www.blog.kubiak.co.uk/post/44

    Page 1 of 2 Oct 25, 2013 12:13:56AM MDT

    How to run MPI under CodeBlocks ? kubiak.co.uk

    MPI in CodeBlocks

    Codeblocks is great application development platform for serial code, however when it came to FluidDynamic you realize that serial code, executed on a single processor is very slow, one of the solution is touse openMP especially for multicore processor, but to do some serious computation you need MPI(Message Passing Interface). Only then, you can run you code on hundreds of processors and yourapplication really take-off.

    Unfortunately Codeblocks (my favourite open source IDE) dont support MPI programs. Hopefully, whenthis is an open source you can solve the problem by your self.

    Here is my solution to run console MPI code from Codeblocks:

    First you need to compile you mpi code and link it to mpi library:

    Under Windows you need to configure:

    In Project/Build options/Linker settings/Add mpi (under linux add m or lm)

    In Search directories/Compiler/Add C:\Program Files\MPICH2\include

    In Search directories/Linker/Add C:\Program Files\MPICH2\lib

    In linux you need to compile the code using mpicc go to Setting/Compiler and Debugger and create acopy of GNU GCC Compiler with new name GNU GCC Compiler MPI. Go to Toolchain executables andreplace the gcc and g++ with mpicc and mpicxx. Next step is to change you MPI project building setting touse new compiler setting.

    This should compile your parallel code.

    Now we need to start the executable using mpiexec or mpirun.

    Our console program on windows is executed by cb_console_runner.exe and there is no support for otherhost program if your project is console application (most of parallel programs are). A few simplemodification in cb_console_runner.exe allow to define argument.-mpi

    Argument this must be define in Codeblocks menu in Project -> Set programs arguments?

    -mpi -n

    example:

    -mpi C:/Progra~1/MPICH2/bin/mpiexec -n 8

    or (for linux)

  • http://www.blog.kubiak.co.uk/post/44

    Page 2 of 2 Oct 25, 2013 12:13:56AM MDT

    - mpi /usr/bin/mpiexec -n 8

    You can download source code (main.cpp) and executable for windows and linux of cb_console_runnerhere:

    http://blog.kubiak.co.uk/download/cb_console_runner.zip

    Codeblocks project for hello world application in mpi is included (under linux make sure to create GNUGCC Compiler MPI with mpicc and mpicxx, for details see text above).

    Thanks for reading and good luck with MPI, you will need it.