如何使用 xcode 4 编译 openmpi 程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9388621/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:23:55  来源:igfitidea点击:

How do I compile openmpi programs using xcode 4?

xcodemacososx-lionparallel-processingopenmpi

提问by RNs_Ghost

I'm using lion and xcode 4.2. I installed openmpi using macports. It all installed successfully.

我正在使用 Lion 和 xcode 4.2。我使用 macports 安装了 openmpi。这一切都安装成功。

I cannot, however find a guide to tell me how/which libraries to include to compile an example (see below)

但是,我找不到指南来告诉我如何/包含哪些库来编译示例(见下文)

#include <mpi.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    int numprocs;
    int myid;
    MPI_Status stat; 

    /* all MPI programs start with MPI_Init */
    MPI_Init(&argc,&argv);     

    /* Comm_size tells us how many processes there are  */
    MPI_Comm_size(MPI_COMM_WORLD,&numprocs); 

    /* Comm_rank finds the rank of the process */
    MPI_Comm_rank(MPI_COMM_WORLD,&myid); 

    /* Print out a message */
    printf("Hello world, from process %d of %d\n", myid, numprocs);  

    /* MPI Programs end with MPI Finalize; this is a weak synchronization point */
    MPI_Finalize(); 

    return 0; 
} 

Xcode reports that mpi.h is missing.

Xcode 报告缺少 mpi.h。

采纳答案by Dhaivat Pandya

Open-mpi has a walkthrough to do exactly this. Here you go.

Open-mpi 有一个演练来做到这一点。给你

回答by BRabbit27

This is really easy. You can either follow the instructions in OpenMPI website or you could do the following (which will help you link any program with any other library).

这真的很容易。您可以按照 OpenMPI 网站中的说明进行操作,也可以执行以下操作(这将帮助您将任何程序与任何其他库链接)。

In the Navigator(left panel) select the project. In the Build settingssearch for Library Search Pathsand put the path where the MPI libraries are (/usr/local/lib)

导航器(左侧面板)中选择项目。在Build settings 中搜索Library Search Paths并放置 MPI 库所在的路径 (/usr/local/lib)

Then look for User Header Search Pathsand put the path where the MPI headers are (/usr/local/include)

然后查找User Header Search Paths并将路径放在 MPI 标头所在的位置 (/usr/local/include)

Finally, in the Build Phaseslook for Link Binary with Librariesclick on the plus sign (+), click on Add Other, press Cmd+Shift+Gand put the path where the libraries libmpi.1.dylib, libmpi_cxx.1.dylibare (/usr/local/lib) add both, build and run and it should work like a charm.

最后,在构建阶段寻找链接二进制与图书馆点击加号(+),点击添加其他的按CMD + Shift + G键,并把存放库文件的路径libmpi.1.dyliblibmpi_cxx.1.dylib是(在/ usr / local / lib目录)加两者,构建和运行,它应该像魅力一样工作。

A little bit late but probably this helps someone else.

有点晚了,但可能这对其他人有帮助。

回答by Dhaivat Pandya

You want to do 2 things:

你想做两件事:

1) Grab

1) 抢

libmpi.1.dylib

libmpi.1.dylib

libmpi_cxx.1.dylib

libmpi_cxx.1.dylib

and copy them in the project folder of your app

并将它们复制到您的应用程序的项目文件夹中

2) add to the HEADER_SEARCH_PATHS the location of your mph.h file (probably /usr/local/include)

2) 在 HEADER_SEARCH_PATHS 中添加 mph.h 文件的位置(可能是 /usr/local/include)

Also check if your $PATH has the path where you installed OpenMPI; failing in doing so will result in an error at compile time.

还要检查你的 $PATH 是否有你安装 OpenMPI 的路径;否则将导致编译时出错。

Good luck!

祝你好运!

回答by Bruce Dean

In addition to Dhaivat's link, there are some Open-MPI tutorials hereand here.

除了 Dhaivat 的链接,这里这里还有一些 Open-MPI 教程。