无法使用 MSMPI 和 GCC 编译程序

Cannot compile program with MSMPI and GCC

我正在尝试使用 gcc 在 C 中编译 MSMPI 程序。

这是我在代码中包含的内容:

#define MSMPI_NO_SAL

#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

我正在使用 Vscode 完成以下任务:

{
  "version": "2.0.0",
  "tasks": [{
    "type": "shell",
    "label": "C/C++: gcc.exe build active file",
    "command": "C:\MinGW\bin\gcc.exe",
    "args": ["-g", "${file}","-I","C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64","-I","C:\Program Files (x86)\Microsoft SDKs\MPI\Include",  "-o", "${fileDirname}\${fileBasenameNoExtension}.exe"],
    "options": {
      "cwd": "${workspaceFolder}"
    },
    "problemMatcher": ["$gcc"],
    "group": {
      "kind": "build",
      "isDefault": true
    }
  }]
}

但是,在尝试编译时,我的代码出现以下错误:

In file included from d:\Documents.Ecole\University\Undergrad\Fall 2020\COMP 428\ass1\pi_est_parallel.c:5:
C:\Program Files (x86)\Microsoft SDKs\MPI\Include/mpi.h:4617:5: error: unknown type name '_Out_writes_'; did you mean '_mpi_writes_'?
 4617 |     _Out_writes_(maxprocs) int array_of_errcodes[]
      |     ^~~~~~~~~~~~
      |     _mpi_writes_
C:\Program Files (x86)\Microsoft SDKs\MPI\Include/mpi.h:4629:5: error: unknown type name '_Out_writes_'; did you mean '_mpi_writes_'?
 4629 |     _Out_writes_(maxprocs) int array_of_errcodes[]
      |     ^~~~~~~~~~~~
      |     _mpi_writes_
The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command C:\MinGW\bin\gcc.exe -g 'd:\Documents.Ecole\University\Undergrad\Fall 2020\COMP 428\ass1\pi_est_parallel.c' -I 'C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64' -I 'C:\Program Files (x86)\Microsoft SDKs\MPI\Include' -o 'd:\Documents.Ecole\University\Undergrad\Fall 2020\COMP 428\ass1\pi_est_parallel.exe'" terminated with exit code: 1.
Terminal will be reused by tasks, press any key to close it.

我是不是在编译的时候忘了包含一些东西?

这是 Microsoft mpi.h 头文件中的一个已知问题:

该问题引用了 simple patch adding _Out_writes_ 来解决这个问题。您可以通过添加

在自己的代码中反映这一点
#define _Out_writes_(x)

如果您无法升级到最新版本,请在包含 mpi.h 之前。