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
?
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
效果图:
#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个物理核心
效果:
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
效果图: