Blame test/mpi/f90/topo/cartcrf90.f90

Packit Service c5cf8c
! This file created from f77/topo/cartcrf.f with f77tof90
Packit Service c5cf8c
! -*- Mode: Fortran; -*- 
Packit Service c5cf8c
!
Packit Service c5cf8c
!  (C) 2004 by Argonne National Laboratory.
Packit Service c5cf8c
!      See COPYRIGHT in top-level directory.
Packit Service c5cf8c
!
Packit Service c5cf8c
! Test various combinations of periodic and non-periodic Cartesian 
Packit Service c5cf8c
! communicators
Packit Service c5cf8c
!
Packit Service c5cf8c
      program main
Packit Service c5cf8c
      use mpi
Packit Service c5cf8c
      integer errs, ierr
Packit Service c5cf8c
      integer ndims, nperiods, i, size
Packit Service c5cf8c
      integer comm, source, dest, newcomm
Packit Service c5cf8c
      integer maxdims
Packit Service c5cf8c
      parameter (maxdims=7)
Packit Service c5cf8c
      logical periods(maxdims), outperiods(maxdims)
Packit Service c5cf8c
      integer dims(maxdims), outdims(maxdims)
Packit Service c5cf8c
      integer outcoords(maxdims)
Packit Service c5cf8c
Packit Service c5cf8c
      errs = 0
Packit Service c5cf8c
      call mtest_init( ierr )
Packit Service c5cf8c
Packit Service c5cf8c
!
Packit Service c5cf8c
!     For upto 6 dimensions, test with periodicity in 0 through all
Packit Service c5cf8c
!     dimensions.  The test is computed by both:
Packit Service c5cf8c
!         get info about the created communicator
Packit Service c5cf8c
!         apply cart shift
Packit Service c5cf8c
!     Note that a dimension can have size one, so that these tests
Packit Service c5cf8c
!     can work with small numbers (even 1) of processes
Packit Service c5cf8c
!
Packit Service c5cf8c
      comm = MPI_COMM_WORLD
Packit Service c5cf8c
      call mpi_comm_size( comm, size, ierr )
Packit Service c5cf8c
      do ndims = 1, 6
Packit Service c5cf8c
         do nperiods = 0, ndims
Packit Service c5cf8c
            do i=1,ndims
Packit Service c5cf8c
               periods(i) = .false.
Packit Service c5cf8c
               dims(i)    = 0
Packit Service c5cf8c
            enddo
Packit Service c5cf8c
            do i=1,nperiods
Packit Service c5cf8c
               periods(i) = .true.
Packit Service c5cf8c
            enddo
Packit Service c5cf8c
Packit Service c5cf8c
            call mpi_dims_create( size, ndims, dims, ierr )
Packit Service c5cf8c
            call mpi_cart_create( comm, ndims, dims, periods, .false., &
Packit Service c5cf8c
      &           newcomm, ierr )
Packit Service c5cf8c
Packit Service c5cf8c
            if (newcomm .ne. MPI_COMM_NULL) then
Packit Service c5cf8c
               call mpi_cart_get( newcomm, maxdims, outdims, outperiods, &
Packit Service c5cf8c
      &              outcoords, ierr )
Packit Service c5cf8c
!               print *, 'Coords = '
Packit Service c5cf8c
               do i=1, ndims
Packit Service c5cf8c
!                  print *, i, '(', outcoords(i), ')'
Packit Service c5cf8c
                  if (periods(i) .neqv. outperiods(i)) then
Packit Service c5cf8c
                     errs = errs + 1
Packit Service c5cf8c
                     print *, ' Wrong value for periods ', i
Packit Service c5cf8c
                     print *, ' ndims = ', ndims
Packit Service c5cf8c
                  endif
Packit Service c5cf8c
               enddo
Packit Service c5cf8c
Packit Service c5cf8c
               do i=1, ndims
Packit Service c5cf8c
                  call mpi_cart_shift( newcomm, i-1, 1, source, dest, &
Packit Service c5cf8c
      &                 ierr )
Packit Service c5cf8c
                  if (outcoords(i) .eq. outdims(i)-1) then
Packit Service c5cf8c
                     if (periods(i)) then
Packit Service c5cf8c
                        if (dest .eq. MPI_PROC_NULL) then
Packit Service c5cf8c
                           errs = errs + 1
Packit Service c5cf8c
                           print *, 'Expected rank, got proc_null'
Packit Service c5cf8c
                        endif
Packit Service c5cf8c
                     else
Packit Service c5cf8c
                        if (dest .ne. MPI_PROC_NULL) then
Packit Service c5cf8c
                           errs = errs + 1
Packit Service c5cf8c
                           print *, 'Expected procnull, got ', dest
Packit Service c5cf8c
                        endif
Packit Service c5cf8c
                     endif
Packit Service c5cf8c
                  endif
Packit Service c5cf8c
                  
Packit Service c5cf8c
                  call mpi_cart_shift( newcomm, i-1, -1, source, dest, &
Packit Service c5cf8c
      &                 ierr )
Packit Service c5cf8c
                  if (outcoords(i) .eq. 0) then
Packit Service c5cf8c
                     if (periods(i)) then
Packit Service c5cf8c
                        if (dest .eq. MPI_PROC_NULL) then
Packit Service c5cf8c
                           errs = errs + 1
Packit Service c5cf8c
                           print *, 'Expected rank, got proc_null'
Packit Service c5cf8c
                        endif
Packit Service c5cf8c
                     else
Packit Service c5cf8c
                        if (dest .ne. MPI_PROC_NULL) then
Packit Service c5cf8c
                           errs = errs + 1
Packit Service c5cf8c
                           print *, 'Expected procnull, got ', dest
Packit Service c5cf8c
                        endif
Packit Service c5cf8c
                     endif
Packit Service c5cf8c
                  endif
Packit Service c5cf8c
               enddo
Packit Service c5cf8c
               call mpi_comm_free( newcomm, ierr )
Packit Service c5cf8c
            endif
Packit Service c5cf8c
            
Packit Service c5cf8c
         enddo
Packit Service c5cf8c
      enddo
Packit Service c5cf8c
      
Packit Service c5cf8c
      call mtest_finalize( errs )
Packit Service c5cf8c
      end