1

我有一个使用 MPI 进行并行工作的现有 Fortran 代码。我有兴趣添加一些 PETSc 求解器(特别是 KSP),但是当包含相关的 .h 或 .h90 文件(petsc、petscsys、petscksp 等)时,我遇到了与共享相同名称的变量的问题MPI 的那些。

IE:

  error #6405: The same named entity from different modules and/or program units cannot be referenced.   [MPI_DOUBLE_PRECISION]
  error #6405: The same named entity from different modules and/or program units cannot be referenced.   [MPI_SUM]
  error #6405: The same named entity from different modules and/or program units cannot be referenced.   [MPI_COMM_WORLD]
and so on.

(使用 ics/composer_xe_2011_sp1.6.233 和 ics/impi/4.0.3.008 和 petsc 3.6.0,也尝试过旧的 petsc 版本 3.5.4)

所有这些在 MPI 和 PETSc 中都同样定义——有没有办法解决这个冲突并同时使用两者?

我会指出,我不想用 PETSc 调用替换 MPI 调用,因为代码应该有一个独立于 PETSc 运行的选项。

至于最少的代码,清理庞大的代码显然是一个问题,所以我做了以下简单的例子,其中包括相关部分:

program mpitest


implicit none
use mpi

! Try any of the following:
!!!#include "petsc.h"
!!!#include "petsc.h90"
!!!#include "petscsys.h"
! etc'


integer :: ierr, error
integer :: ni=256, nj=192, nk=256
integer :: i,j,k

real, allocatable :: phi(:,:,:)


integer :: mp_rank, mp_size
real :: sum_phi,max_div,max_div_final,sum_div_final,sum_div


  call mpi_init(ierr)
  call mpi_comm_rank(mpi_comm_world,mp_rank,ierr)
  call mpi_comm_size(mpi_comm_world,mp_size,ierr)




allocate(phi(nj,nk,0:ni/mp_size+1))

        sum_phi = 0.0
        do i=1,ni/mp_size
           do k=1,nk
              do j=1,nj
                 sum_phi = sum_phi + phi(j,k,i)
              enddo
           enddo
        enddo


sum_phi = sum_phi / real(ni/mp_size*nk*nj)
        call mpi_allreduce(sum_div,sum_div_final,1,mpi_double_precision,mpi_sum, &
             mpi_comm_world,ierr)
        call mpi_allreduce(max_div,max_div_final,1,mpi_double_precision,mpi_max, &
             mpi_comm_world,ierr)


call mpi_finalize(error)

deallocate(phi)


WRITE(*,*) 'Done'

end program mpitest

这在包含 PETSc 标头时直接发生,并且在删除包含时消失。

4

1 回答 1

1

好的,所以找到了答案:

PETSc 不太喜欢 Fortran,因此,它的功能与使用 C/C++ 的方式不同,并且使用不同的定义。对于 C/C++,可以使用其中的头文件/include/petscXXX.h,一切都会好起来的,而且层次结构已经包含了相关的 .h 文件(即包含 petscksp.h 将包含 petscsys.h、petscvec.h 等)。

不在 FORTRAN 中。

首先也是最重要的,对于 FORTRAN,需要在其中包含标头/include/petsc/finclude/petscXXXdef.h(如果 PETSc 使用该标志编译,则为 .h90)。请注意,这些文件位于不同的包含文件夹中,并且是 petscxxx def .h。

然后“使用 petscXXX”将与 MPI 一起工作而不会发生冲突。

于 2017-05-11T20:15:35.633 回答