Building an MPI program with Managed Build(Eclipse 下怎么创建简单的MPI hello world 程序)

本文档介绍了如何在Eclipse环境中使用Managed Build创建MPI项目,包括设置包含路径、指定mpicc工具链以及本地运行MPI程序的方法。首先,通过新建Managed Make C Project创建MPI项目,然后手动或使用PLDT(并行语言开发工具)设置项目信息,添加MPI头文件路径和库路径,最后将编译器和链接器设置为mpicc。
摘要由CSDN通过智能技术生成

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.


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值