gpt4 book ai didi

fortran - MPI 状态 FORTRAN

转载 作者:行者123 更新时间:2023-12-01 12:45:39 25 4
gpt4 key购买 nike

我有这段代码,但我收到了这个错误。

我尝试声明状态为

整数::状态

但这改变了我在 MPI_SENDRECV 之后的排名值(即所有处理器的排名 = 0)

PROGRAM testsendrecv
IMPLICIT NONE

INTEGER :: i, k, nx, nz
INTEGER :: ierror, comm, p, rank, npr, prev
INTEGER :: status(MPI_STATUS_SIZE)
REAL(KIND = 8), ALLOCATABLE :: A(:,:), B(:), C(:)

include 'mpif.h'

nx = 5
nz = 5

ALLOCATE(A(nx,nz), B(nx))

CALL MPI_INIT(ierror)
comm = MPI_COMM_WORLD
!Get rank
CALL MPI_COMM_RANK(comm, rank, ierror)
!Get number of processors
CALL MPI_COMM_SIZE(comm, p, ierror)

A(:,:) = rank

IF(rank==0) THEN
prev = p-1
ELSE
prev = rank-1
END IF


CALL MPI_SENDRECV(A(:,1), nx, MPI_DOUBLE_PRECISION, MOD(rank+1,p), 1, &
B(:), nx, MPI_DOUBLE_PRECISION, prev, 1, comm, status, ierror)

WRITE(*,*) rank
WRITE(*,*) B(1)

CALL MPI_FINALIZE(ierror)

END PROGRAM testsendrecv

上面的代码给我以下错误

bash-4.1$ mpif90 testsendr.f90
mpif.h:79.35:
Included at testsendr.f90:9:

PARAMETER (MPI_STATUS_SIZE=5)
1
Error: VARIABLE attribute of 'mpi_status_size' conflicts with PARAMETER attribute at (1)
mpif.h:80.33:
Included at testsendr.f90:9:

INTEGER MPI_STATUS_IGNORE(MPI_STATUS_SIZE)
1
Error: Variable 'mpi_status_size' cannot appear in the expression at (1)
mpif.h:80.49:
Included at testsendr.f90:9:

INTEGER MPI_STATUS_IGNORE(MPI_STATUS_SIZE)
1
Error: The module or main program array 'mpi_status_ignore' at (1) must have constant shape
mpif.h:81.35:
Included at testsendr.f90:9:

INTEGER MPI_STATUSES_IGNORE(MPI_STATUS_SIZE,1)
1
Error: Variable 'mpi_status_size' cannot appear in the expression at (1)
mpif.h:81.53:
Included at testsendr.f90:9:

INTEGER MPI_STATUSES_IGNORE(MPI_STATUS_SIZE,1)
1
Error: The module or main program array 'mpi_statuses_ignore' at (1) must have constant shape
testsendr.f90:6.20:

INTEGER :: status(MPI_STATUS_SIZE)
1
Error: Variable 'mpi_status_size' cannot appear in the expression at (1)
testsendr.f90:6.36:

INTEGER :: status(MPI_STATUS_SIZE)
1
Error: The module or main program array 'status' at (1) must have constant shape

任何想法。这是一个非常简单的程序。

谢谢

最佳答案

我认为您的问题是由程序中的语句顺序错误引起的。行前

include mpif.h

您已经在行中声明了一个变量,该变量使用该文件中定义的常量之一

INTEGER :: status(MPI_STATUS_SIZE)

要么将 include 语句移动到紧跟在 IMPLICIT NONE 之后,或者更好的是,完全删除 include 并在 USE MPI 之前插入隐式声明并梳理修改后代码的链接。

关于fortran - MPI 状态 FORTRAN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16270474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com