#include <mpi.h>
#include <stdio.h>
int main(int argc, char** argv) {
// Initialize the MPI environment
MPI_Init(NULL, NULL);
// Get the number of processes
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
// Get the rank of the 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);
// Print off a hello world message
printf("Hello world from processor %s, rank %d"
" out of %d processors\n",
processor_name, world_rank, world_size);
// Finalize the MPI environment.
MPI_Finalize();
}
MPI Hello World
最新推荐文章于 2025-07-26 10:10:50 发布
本文介绍了一个简单的MPI程序实例,展示了如何使用MPI初始化环境、获取进程数量、获取进程排名、获取处理器名称并打印消息,最后终止MPI环境。这些基本操作对于初学者理解MPI的工作原理至关重要。
177

被折叠的 条评论
为什么被折叠?



