c - 如何让 MPI 在多核上运行?
问题描述
我是 MPI 和一般并行编程的新手,所以这对你们中的一些人来说可能太明显了。
我想使用我所有的内核运行一个简单的 hello world 程序。
我目前安装并配置了 MPICH3,如下所示(我知道本教程是关于 MPICH2 的,但这是我找到的最接近的)。
我复制了这段代码:
#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();
}
我试着像这样编译它mpicc mpi_implementation.c
。到目前为止,一切都很好。问题是,当我使用它运行它时,mpiexec -np 4 ./a.out
我得到以下输出:
Hello world from processor grodeBase, rank 0 out of 1 processors
Hello world from processor grodeBase, rank 0 out of 1 processors
Hello world from processor grodeBase, rank 0 out of 1 processors
Hello world from processor grodeBase, rank 0 out of 1 processors
实际上这是对的,因为我只有一个处理器,但我的意思是在许多内核上运行程序,我不知道该怎么做。它会自动发生而我只是没有看到吗?有什么办法可以确保我所有的核心都被使用了吗?而且,我怎样才能具体提到其中之一?
PS如果您需要任何进一步的信息,请告诉我。
解决方案
推荐阅读
- c++ - 使用函数 decimal 仅将输入的小数返回为 double C++
- spring-boot - 如何在 Spring 应用程序中修改有效负载响应数据?
- android - Flutter - Crashlytics 仍在 Firebase 中加载
- flutter - 颤振中的showDialog在iOS的发布版本中不起作用
- python - 使用 plotly 绘制曲面图
- swift - SwiftUI 在 NavigationView 中添加个人警报视图,后退按钮不适用于 Xcode 12 iOS14
- python - 训练具有可变输入大小的 keras 模型
- rust - Rust 中 f64 的最大值
- r - 如何将二维密度图映射到照片上
- javascript - 未捕获的语法错误:丢失;在for循环初始化程序之后,但我看不到它在哪里丢失