Mpi 程序无法在 Windows 上的 Vscode 中运行

问题描述 投票:0回答:1

我试图运行一些mpi程序,我从官方网站下载了.exe和.msi文件。

安装后,我尝试运行示例代码,但没有成功。

一开始报错信息说找不到mpi.h。我尝试在包含路径中添加 mpi.h 所在的路径,错误消失了。

但是还有一些错误我找不到解决的方法。

这是我的配置:

tasks.json:

 "tasks": [
            {
                "type": "cppbuild",
                "label": "C/C++: gcc.exe build active file",
                "command": "D:\\mingw64\\bin\\gcc.exe",
                "args": [
                    "-fdiagnostics-color=always",
                    "-g",
                    "${file}",
                    "-I",
                    "${MSMPI_INC}",
                    "-L",
                    "${MSMPI_LIB64}",
                    "-lmsmpi",
                    "-o",
                    "${fileDirname}\\${fileBasenameNoExtension}.exe"
                ],
                "options": {
                    "cwd": "${fileDirname}"
                },
                "problemMatcher": [
                    "$gcc"
                ],
                "group": {
                    "kind": "build",
                    "isDefault": true
                },
                "detail": "Task generated by Debugger."
            }
        ],
        "version": "2.0.0"
    }

c_cpp_属性:

{
        "configurations": [
            {
                "name": "Win32",
                "includePath": [
                    "${workspaceFolder}/**",
                    "D:\\Program Files (x86)\\Microsoft SDKs\\MPI\\Include"
                ],
                "defines": [
                    "_DEBUG",
                    "UNICODE",
                    "_UNICODE"
                ],
                "compilerPath": "D:\\mingw64\\bin\\gcc.exe",
                "cStandard": "c17",
                "cppStandard": "gnu++14",
                "intelliSenseMode": "windows-gcc-x64"
            }
        ],
        "version": 4
    }

演示代码:

#include <iostream>
#include <mpi.h>
#include <stdint.h>
using namespace std;

int main(int argc, char* argv[]) {
  cout << "hello" << endl;
  int myid, numprocs;
  int namelen;
  char processor_name[MPI_MAX_PROCESSOR_NAME];
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &myid);
  MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
  MPI_Get_processor_name(processor_name, &namelen);
  cout << "Hello World! Process" << myid << "of" << numprocs << " on " << processor_name << endl;
  MPI_Finalize();
  return 0;
}

输出:

[Running] cd "d:\BuildYourOwnX\AAPP\" && g++ demo.cpp -o demo -fopenmp -l msmpi -L "D:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64" -I "D:\Program Files (x86)\Microsoft SDKs\MPI\Include" && mpiexec -n 4 demo
'mpiexec' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���

[Done] exited with code=1 in 0.979 seconds
c visual-studio-code mpi
1个回答
0
投票

我刚刚发现“运行代码”和“运行c/c++文件”之间的区别。这是解释。在此处输入链接描述

© www.soinside.com 2019 - 2024. All rights reserved.