MPI并行程序设计 —— C 和 fortran 环境搭建 openmpi 示例程序
2023-12-29 17:40:55
1.安装环境
wget https://download.open-mpi.org/release/open-mpi/v4.1/openmpi-4.1.6.tar.g
tar zxf openmpi-4.1.6.tar.gz
cd openmpi-4.1.6/
其中 configure 选项 --prefix=/.../ 需要使用绝对路径,例如:
./configure --prefix=/home/hipper/ex_openmpi/local/ 2>&1 | tee config.out
make -j all 2>&1 | tee make.out
make install 2>&1 | tee install.out
2.配置编译运行环境
?
export PATH=/home/hipper/ex_openmpi/local/bin:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/hipper/ex_openmpi/local/lib
cd examples
make
mpirun -np 7 hello_c
效果图:
3. 练习测试环境
3.1 C语言测试
#include "mpi.h"
#include <stdio.h>
#include <math.h>
void main(argc,argv)
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();
}
编译:
gcc hello_ompi.c -I ../local/include/ -L ../local/lib/ -lmpi
执行:
../local/bin/mpirun -np 18 ./a.out
cpu有18个物理核心
效果:
3.2 fortran 语言测试
源代码:每行开始TAB键
program main
include 'mpif.h'
character * (MPI_MAX_PROCESSOR_NAME) processor_name
integer myid, numprocs, namelen, rc,ierr
call MPI_INIT( ierr )
call MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
call MPI_GET_PROCESSOR_NAME(processor_name, namelen, ierr)
write(*,10) myid,numprocs,processor_name
10 FORMAT('Hello World! Process ',I2,' of ',I1,' on ', 20A)
call MPI_FINALIZE(rc)
end
编译:
gfortran hello_ompi.f -I../local/include/ -L../local/lib/ -lmpi_mpifh -lgfortran
运行:
$ ../local/bin/mpirun -np 7 ./a.out
效果图:
3.3 看一下机器名称最长可以占多少个字节
256个字节
效果:
文章来源:https://blog.csdn.net/eloudy/article/details/135293911
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!