一、简介

通过安装MPICH构建MPI编程环境,从而进行并行程序的开发。MPICH是MPI(Message-Passing Interface)的一个应用实现,支持最新的MPI-2接口标准,是用于并行运算的工具。

 

二、安装配置

 

三、程序示例

//hello.c
#include "mpi.h"
#include <stdio.h>
#include <math.h>

int main (int argc, char **argv)
{
    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);
    fprintf (stderr, "Hello World! Process %d of %d on %s\n", myid, numprocs, processor_name);
    MPI_Finalize ();
    return 0;
}

编译

mpicc -o hello hello.c

运行

Hello World! Process 1 of 4 on jack-laptop
Hello World! Process 3 of 4 on jack-laptop
Hello World! Process 2 of 4 on jack-laptop
Hello World! Process 0 of 4 on jack-laptop

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-15
  • 2022-12-23
  • 2022-01-17
  • 2022-01-20
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
相关资源
相似解决方案