文章

Windows下安装 MSMPI

下载安装包及环境变量设置

下载安装msmpi以及msmpisdkMSMPI github releases。注意安装路径不要有空格及中文。

命令行设置:

1
set MSMPI

输出信息如下图所示:

MSMPI环境变量设置

建立第一个测试程序

hello_mpi

1
2
3
4
5
6
7
find_package(MPI REQUIRED)

# list(APPEND myMPI_INC_DIR $ENV{MSMPI_INC})
# list(APPEND myMPI_LIBS $ENV{MSMPI_LIB64})
message(STATUS "MPI_FOUND=${MPI_FOUND}")
message(STATUS "MPI_CXX_INCLUDE_DIRS=${MPI_CXX_INCLUDE_DIRS}")
message(STATUS "MPI_LIBRARIES=${MPI_LIBRARIES}")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <mpi.h>
#include <stdio.h>

int main(int argc, char** argv) {
  // Initialize the MPI environment
  MPI_Init(&argc, &argv);

  // Get the number of processes ssociated with the communicator
  int world_size{};
  MPI_Comm_size(MPI_COMM_WORLD, &world_size);

  // Get the rank of the calling process
  int world_rank{};
  MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);

  // Get the name of the processor
  char processor_name[MPI_MAX_PROCESSOR_NAME]{};
  int name_len;
  MPI_Get_processor_name(processor_name, &name_len);

  printf("Hello world from process %s with rank %d out of %d processors\n", processor_name, world_rank, world_size);

  // Finalize: Any resources allocated for MPI can be freed
  MPI_Finalize();
}

教程参考

本文由作者按照 CC BY 4.0 进行授权