1

並列作業に MPI を使用する既存の Fortran コードがあります。いくつかの PETSc ソルバー (特に KSP) を追加することに興味がありますが、関連する .h または .h90 ファイル (petsc、petcsys、petscksp など) を含めると、同じ名前を共有する変数で問題が発生します。 MPIのもの。

すなわち:

  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