1 C -*- Mode: Fortran; -*-
3 C (C) 2003 by Argonne National Laboratory.
4 C See COPYRIGHT in top-level directory.
11 parameter (maxn=10,maxm=15)
12 integer fullsizes(2), subsizes(2), starts(2)
13 integer fullarr(maxn,maxm),subarr(maxn-3,maxm-4)
15 integer newtype, size, rank, ans
18 call mtest_init( ierr )
19 call mpi_comm_size( MPI_COMM_WORLD, size, ierr )
20 call mpi_comm_rank( MPI_COMM_WORLD, rank, ierr )
22 C Create a Fortran-style subarray
25 subsizes(1) = maxn - 3
26 subsizes(2) = maxm - 4
27 C starts are from zero, even in Fortran
30 C In Fortran 90 notation, the original array is
31 C integer a(maxn,maxm)
33 C a(1+1:(maxn-3) +(1+1)-1,2+1:(maxm-4)+(2+1)-1)
34 C i.e., a (start:(len + start - 1),...)
35 call mpi_type_create_subarray( 2, fullsizes, subsizes, starts,
36 & MPI_ORDER_FORTRAN, MPI_INTEGER, newtype, ierr )
37 call mpi_type_commit( newtype, ierr )
42 fullarr(i,j) = (i-1) + (j-1) * maxn
50 ssize = subsizes(1)*subsizes(2)
51 call mpi_sendrecv( fullarr, 1, newtype, rank, 0,
52 & subarr, ssize, MPI_INTEGER, rank, 0,
53 & MPI_COMM_WORLD, MPI_STATUS_IGNORE, ierr )
58 ans = (i+starts(1)-1) + (j+starts(2)-1) * maxn
59 if (subarr(i,j) .ne. ans) then
61 if (errs .le. 10) then
62 print *, rank, 'subarr(',i,',',j,') = ', subarr(i,j)
68 call mpi_type_free( newtype, ierr )
70 call mtest_finalize( errs )
71 call mpi_finalize( ierr )