Reputation: 86
I am in the process of learning MPI in fortran, and so I've been writing a bunch of small functions that do simple tasks in MPI to get a good handle on it. However, halfway through, i began getting this error when trying to compile
$ mpif90 example.f90 -o example.out
example.f90:108:17:
108 | implicit none
| 1
Error: IMPLICIT NONE statement at (1) cannot follow attribute declaration statement at (2)
which doesn't even show me where (2) is so I don't know whats causing the error. But when I commented out implicit none
, it compiled fine and ran correctly. Any ideas as to what is happening here?
Code:
program send_vec
include 'mpif.h'
implicit none
integer :: process_rank, cluster_size, ierror, message_item
integer :: i
integer, dimension(:), allocatable :: buffer_vector
allocate(buffer_vector(1:10))
call MPI_INIT(ierror)
call MPI_COMM_SIZE(MPI_COMM_WORLD, cluster_size, ierror)
call MPI_COMM_RANK(MPI_COMM_WORLD, process_rank, ierror)
if ( process_rank == 0 ) then
do i = 1, 10
buffer_vector(i) = i
end do
write (*,*) "sent:", buffer_vector
call MPI_SEND(buffer_vector, 10, MPI_INT, 1, 1, MPI_COMM_WORLD, ierror)
else if (process_rank == 1) then
call MPI_RECV(buffer_vector, 10, MPI_INT, 0, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE, ierror)
write (*,*) "recieved:", buffer_vector
end if
call MPI_FINALIZE(ierror)
end program send_vec
Also this is mpif90 -v
mpifort for MPICH version 3.4.1
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.2.0-7ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-ZPT0kp/gcc-11-11.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-ZPT0kp/gcc-11-11.2.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (Ubuntu 11.2.0-7ubuntu2)
Upvotes: 0
Views: 536
Reputation: 8395
implicit none
must appear before include 'mpif.h'
That being said, this is very error prone, and you should at least use
program send_vec
use mpi
implicit none
...
(note the implicit none
is after the use mpi
line)
Ideally, you would
program send_vec
use mpi_f08
implicit none
...
but that will likely require you to modernize your code
(for example, a datatype has its own type (e.g. Type(MPI_Datatype)
instead of INTEGER
)
Upvotes: 2