myid,ierr)callMPI_COMM_SIZE(MPI_COMM_WORLD,numprocs,ierr)callMPI_GET_PROCESSOR_NAME(processor_name,namelen,ierr)write(*,10)myid,numprocs,processor_name10FORMAT('Hello World! Process ',I2,' of ',I1,' on ',20A)call
integer :: rank, size, ierr, i integer, parameter :: n = 100 real :: local_sum, global_sum real, allocatable :: a(:) call MPI_Init(ierr) call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr) call MPI_Comm_size(MPI_COMM_WORLD, size, ierr) allocate(a(n)) a = 1.0 ! 每个进程计算...
call MPI_Finalize(ierr) end program mpi_sum 代码解释 MPI并行化: 使用 use mpi 引入MPI库,并通过 MPI_Init, MPI_Comm_rank, MPI_Comm_size, MPI_Allreduce, MPI_Finalize 等MPI函数实现分布式并行计算。局部求和: 每个进程计算数组 a 的局部和。全局归约: 使用 MPI_Allreduce 函数将所有进程的局部和归约...
mpi_init 初始化,必须调用,首先调用,调用一次 mpicommsize 组内通信因子进程数 mpi_rank 在指定通信因子中的进程号(0~进程数-1),一个进程在不同通信因子中进程号可能不同 mpisend 发送缓冲区的count个datatype数据类型的数据发送到目的进程 mpireceive 从指定的source接收信息,接收消息的元素个数不能超过count mp...
在Fortran代码中使用MPI进行并行计算,通常需要遵循以下步骤: 引入MPI库:在程序开始时,使用include 'mpif.h'或use mpi语句引入MPI库。 初始化MPI环境:使用MPI_Init函数初始化MPI环境。 获取进程信息:使用MPI_Comm_rank和MPI_Comm_size函数获取当前进程的排名和总进程数。 执行并行计算:根据进程排名和总进程数分配计算...
MPI_COMM_SIZE(COMM,np,ierr)获得总进程数np 为 integer 型变量,返回COMM通讯子中进程总数。ierr ,程序正确运行时返回 0 。 MPI_GET_ProcESSOR_NAME(processor_name,namelength,ierr)获得运行本进程的机器的机器名和机器名长度。processor_name 为 character 型变量,返回运行本进程的机器名。namelength 为 integer...
my_id ==> NO. this processcallMPI_COMM_SIZE (MPI_COMM_WORLD, num_procs, ierr)!num_procs ==> number of processwrite(*,'('Hello World',1x,i2,a,i2)') my_id,'/',num_procscallMPI_FINALIZE ( ierr )endprogram 并行程序的编译...
call mpi_comm_size( mpi_comm_world, numProcs, ierr ) ! 获取通信域包含的进程数if( myid .eq.0)thenmessage="Hello, Processor " do iid=1, numProcs-1write(message(18:19),"(I2)") iid call mpi_send( message,len(message), mpi_character, iid,666, mpi_comm_world, ierr ) ! 消息发送 ...
Gatherv:收集不同长度的数据块,num_n,displs,lev_n由root进程给出CALLMPI_Gatherv(lev,num,mpi_integer4,lev_n,num_n,displs,mpi_integer4,root,MPI_COMM_WORLD,ierr)IF(OnMonitor)PRINT*,'Gatherv lev result=',lev_n!---!4.0释放空间及结束MPI并行环境!---DEALLOCATE(lev)IF(OnMonitor)DEALLOCATE(num_...
integer :: ierr, rank, size, i, n, local_n real, allocatable :: a(:), local_a(:) real :: local_sum, total_sum call MPI_Init(ierr) call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr) call MPI_Comm_size(MPI_COMM_WORLD, size, ierr) ...