Fortran中的MPI子例程

时间:2014-07-03 15:49:42

标签: mpi fortran90 subroutine

我已经查看了我能找到的关于这个主题的所有帖子,但它们似乎没有解决我的问题。我很感谢任何输入/帮助/想法。所以这就是:

我有我的主程序(main.f90):

    program inv_main

    use mod_communication

    implicit none

    include 'mpif.h'   

    ...

    call MPI_INIT(ierr) 

    call MPI_COMM_RANK(MPI_COMM_WORLD,id,ierr)

    call MPI_COMM_SIZE(MPI_COMM_WORLD,nproc,ierr) 

    ...

    call SENDRECEIVE(id, nproc, ierr, VVNP, VVN)

    ...

    call MPI_FINALIZE(ierr) 
    end program inv_main  

这是包含子程序的模块(我知道allgather可能是一个更好的方法来做同样的事情,但我无法弄明白我的4D数组):

    Module mod_communication

    implicit none

    include 'mpif.h'

    integer, dimension(MPI_STATUS_SIZE) :: STATUS ! MPI

    CONTAINS

    Subroutine SENDRECEIVE(id, nproc, ierr, INPUT, OUTPUT )

    integer, intent (in) :: nproc, id, ierr 

    real (dp), intent(in) ::  INPUT(n,m) 

    real (dp), intent(out) :: OUTPUT(n,m,nty,nty)

    integer :: sndr

    IF (id .eq. 0) THEN

    OUTPUT(1:n,1:m,1,1)=INPUT 

    call MPI_RECV(INPUT,n*m,MPI_DOUBLE_PRECISION,MPI_ANY_SOURCE,MPI_ANY_TAG,MPI_COMM_WORLD,STATUS,ierr)
    sndr=STATUS(MPI_SOURCE)

    OUTPUT(1:n,1:m,int(sndr/nty)+1,sndr+1-nty*(int(sndr/nty))) = INPUT

    END IF


    IF (id .ne. 0) THEN 

    call MPI_SEND(INPUT,n*m,MPI_DOUBLE_PRECISION,0,id,MPI_COMM_WORLD,ierr)

    ENDIF

    call MPI_BARRIER(MPI_COMM_WORLD,ierr)

    call MPI_BCAST(OUTPUT,n*m*nty*nty,MPI_DOUBLE_PRECISION,0,MPI_COMM_WORLD,ierr)

    end Subroutine 

    end Module mod_communication

这是我在编译时收到的错误消息:

    use mod_communication
      2
    Error: Symbol 'mpi_displacement_current' at (1) conflicts with symbol from module  'mod_communication', use-associated at (2)
    mpif-mpi-io.h:71.36:
    Included at mpif-config.h:65:
    Included at mpif-common.h:70:
    Included at mpif.h:59:
    Included at main.f90:27:

    integer MPI_MAX_DATAREP_STRING
                                1
    main.f90:21.6:

    use mod_communication
     2
    Error: Symbol 'mpi_max_datarep_string' at (1) conflicts with symbol from module 'mod_communication', use-associated at (2)
    mpif-mpi-io.h:73.32:
    Included at mpif-config.h:65:
    Included at mpif-common.h:70:
    Included at mpif.h:59:
    Included at main.f90:27:

    parameter (MPI_FILE_NULL=0)

这些只是前两个错误,它继续这样......而且我找不到我的错误。另外,我必须使用" include' mpif.h'"而不是"使用mpi"因为机器我最终会运行它。如果我使用mpi编译它,但是在我自己的计算机上它会给我一个不同的错误,如下所示:

    mod_MPI.f90:93.41:

    call MPI_BARRIER(MPI_COMM_WORLD,ierr)
                                     1
    Error: There is no specific subroutine for the generic 'mpi_barrier' at (1)
    mod_MPI.f90:52.41:

1 个答案:

答案 0 :(得分:1)

你的主程序可能会(或者更确切地试图获得)mpif.h中所有内容的两个副本。通过include - 在模块中,您可以有效地使其所有内容模块化(变量,例程,参数,什么不是)。然后,在main中你use模块,然后使用 - 关联模块事物,并尝试include mpif.h并重新声明所有这些事情。

做@Jonathan Dursi的建议。