Building an MPI program with Managed Build(Eclipse 下怎麼創建簡單的MPI hello world 程序)

Topics include:

Create an MPI Project

To create a new MPI project in C using the managed build facility,Select File -> New -> Project ... The New Project dialog opens.
Select C -> Managed Make C Project.

Note: for automatic setup of MPI project information,see the PLDT's MPI Project setup informationin the PTP PLDT (Parallel Language Development Tools) help.If you have set up the MPI project information this way, you can check a single box on the additional wizard page entitled "MPI Project Settings,"skip the restof this section and proceed to launch the parallel program.

If you don't have the PLDT installed, you must set up the projectinformation manually, as follows.


Click Next.
Type the name of your project, e.g. MyCProject

Click Finish.

A dialog prompts you to switch to the C/C++ Perspective. Hit OK.The C/C++ Perspective appears.

Your new project is shown in the C/C++ Projects view.

Now create a source file.Click File -> New -> Source File.
Type a name for the source file, e.g. "test.c"

Click Finish.

A new editor appears, in which you can enter your program.

Since this is a managed build project, Eclipse creates a makefileand tries to build with the new file. Since the file is empty,you will see errors in the Problems view, and in the Console view.

Enter a program in the editor.(If you have the PTP PLDT installed, a sample program is available in the PTP MPI tools help, available as: testMPI.c)

A sample "hello world" type MPI program is also a goodfirst test program:

#include<mpi.h>
#include<stdio.h>
int main(int argc, char *argv[])
{
int npes, myrank;
int namelen;
char processor_name[MPI_MAX_PROCESSOR_NAME];
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&npes);
MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
MPI_Get_processor_name(processor_name,&namelen);
printf("Hello , I am rank %d of %d on %s \n",myrank, npes,processor_name);
MPI_Finalize();
return 0;
}

Save your program. The program will be compiled automatically bythe managed build system.

You may see several errors, if you haven't set up theMPI information for your project.The first error may be that an include file isn't found.

(If you hover the mouse cursor over the red "X"you will see the reason for the error)

Include Paths

In order to locate needed include files, bring up the Project Properties on this C/C++ project.
To bring up the Project Properties dialog,activate the context menu on the Project, and select "Properties."

The project properties window is displayed for this C project.Select "C/C++ Build" on the left, and under "Configuration settings" on the "Tool Settings" tab, select "Directories" under "GCC Compiler."This lists the Include paths used to build the project, which are nowempty.

To add an include path, click the add button for Include Paths.

Then enter or browse to find the location of the MPI includes, andselect "OK."

Now you also need to add the path to the library: Under GCC Linker,Libraries, select the add button for "Libraries (-l)"


Then select the add button for "Library Search Path (-L)" and enter the path to the lib directory. Select 'OK'

Now select "OK" in the project properties dialog to close this dialog.Now your project should rebuild without errors relating to findingthe include files.

Specifying the mpicc toolchain

Now specify the build/link command.Again in Project properties, C/C++ build page, Tool Settings tab,click on "GCC C compiler"and change the default "gcc" value to "mpicc"(or whatever the build command is for your MPI environment).

Then do the same for the "GCC C Linker."

Now proceed to launch the parallel program.


發佈了25 篇原創文章 · 獲贊 3 · 訪問量 23萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章