VSCODE第一个MPI程序,配置以及helloworld

首先,你需要几个东西:

第一步:

新建文件夹VSCODEFORCPP
新建main.cpp文件

#include "mpi.h"
#include <stdio.h>
int main(int argc, char *argv[])
{
    int rank, nprocs;

    MPI_Init(&argc,&argv);
    MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
    MPI_Comm_rank(MPI_COMM_WORLD,&rank);
    printf("Hello, world.  I am %d of %d\n", rank, nprocs);fflush(stdout);
    MPI_Finalize();
    //printf("hello!");
    return 0;
}

第二步:

配置C++环境:
三个配置文件其实可以自动生成,详情请见MacOS安装vs code并且配置C/C++环境2020最新版
在这里插入图片描述
在.vscode文件夹中新建并修改:

  1. 文件c_cpp_properties.json
{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++98",
            "intelliSenseMode": "macos-clang-x64"
        }
    ],
    "version": 4
}
  1. 文件launch.json
{  
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(lldb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "输入程序名称,例如 ${workspaceFolder}/a.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb"
        }
    ]
}
  1. 文件tasks.json
{
    "version": "2.0.0",
    "tasks": [
      {
        "label": "Build with Clang",
        "type": "shell",
        "command": "clang++",
        "args": [
          "${file}",
                "-std=c++11",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}.out",
                "-g",
                "--debug"
        ],
        "group": {
          "kind": "build",
          "isDefault": true
        }
      }
    ]
  }

第三步:

mpicc main.cpp -o main.o
mpirun -n 4 main.o

得出结果:
在这里插入图片描述

参考:
mac中用brew配置mpi环境
mac中从源代码安装mpi

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值