Blame test/mpi/f90/spawn/connaccf90.f90

Packit Service c5cf8c
! This file created from f77/spawn/connaccf.f with f77tof90
Packit Service c5cf8c
! -*- Mode: Fortran; -*- 
Packit Service c5cf8c
!
Packit Service c5cf8c
!  (C) 2003 by Argonne National Laboratory.
Packit Service c5cf8c
!      See COPYRIGHT in top-level directory.
Packit Service c5cf8c
!
Packit Service c5cf8c
      program main
Packit Service c5cf8c
      use mpi
Packit Service c5cf8c
      integer size, rank, ierr, errs, eclass
Packit Service c5cf8c
      integer color, comm, intercomm
Packit Service c5cf8c
      integer s1, s2
Packit Service c5cf8c
      character*(MPI_MAX_PORT_NAME) portname
Packit Service c5cf8c
Packit Service c5cf8c
      errs = 0
Packit Service c5cf8c
      call mtest_init( ierr )
Packit Service c5cf8c
Packit Service c5cf8c
      call mpi_comm_size( MPI_COMM_WORLD, size, ierr )
Packit Service c5cf8c
      call mpi_comm_rank( MPI_COMM_WORLD, rank, ierr )
Packit Service c5cf8c
      if (size .lt. 2) then
Packit Service c5cf8c
         print *, 'This example must have at least 2 processes'
Packit Service c5cf8c
         call mpi_abort( MPI_COMM_WORLD, 1, ierr )
Packit Service c5cf8c
      endif
Packit Service c5cf8c
!
Packit Service c5cf8c
! Part of this test is to ensure that lookups cleanly fail when
Packit Service c5cf8c
! a name is not present.  This code is used to ensure that the
Packit Service c5cf8c
! name is not in use  before the test.
Packit Service c5cf8c
! The MPI Standard (10.4.4 Name Publishing) requires that a process that
Packit Service c5cf8c
! has published a name unpublish it before it exits.  
Packit Service c5cf8c
! This code attempts to lookup the name that we want to use as the
Packit Service c5cf8c
! service name for this example.  If it is found (it should not be, but
Packit Service c5cf8c
! might if an MPI program with this service name exits without unpublishing
Packit Service c5cf8c
! the servicename, and the runtime that provides the name publishing
Packit Service c5cf8c
! leaves the servicename in use.  This block of code should not be necessary
Packit Service c5cf8c
! in a robust MPI implementation, but should not cause problems for a correct.
Packit Service c5cf8c
!
Packit Service c5cf8c
      call mpi_barrier( MPI_COMM_WORLD, ierr )
Packit Service c5cf8c
      call mpi_comm_set_errhandler( MPI_COMM_WORLD, MPI_ERRORS_RETURN,  &
Packit Service c5cf8c
      &     ierr )
Packit Service c5cf8c
      call mpi_lookup_name( "fservtest", MPI_INFO_NULL, portname, ierr )
Packit Service c5cf8c
      if (ierr .eq. MPI_SUCCESS) then
Packit Service c5cf8c
          call mpi_unpublish_name( "fservtest", MPI_INFO_NULL, portname,  &
Packit Service c5cf8c
      &        ierr )
Packit Service c5cf8c
      endif
Packit Service c5cf8c
      call mpi_barrier( MPI_COMM_WORLD, ierr )
Packit Service c5cf8c
! Ignore errors from unpublish_name (such as name-not-found)      
Packit Service c5cf8c
      call mpi_comm_set_errhandler( MPI_COMM_WORLD,  &
Packit Service c5cf8c
      &     MPI_ERRORS_ARE_FATAL, ierr )
Packit Service c5cf8c
!
Packit Service c5cf8c
! The server (accept) side is rank < size/2 and the client (connect)
Packit Service c5cf8c
! side is rank >= size/2
Packit Service c5cf8c
      color = 0
Packit Service c5cf8c
      if (rank .ge. size/2) color = 1
Packit Service c5cf8c
      call mpi_comm_split( MPI_COMM_WORLD, color, rank, comm, ierr )
Packit Service c5cf8c
!
Packit Service c5cf8c
      if (rank .lt. size/2) then
Packit Service c5cf8c
!        Server
Packit Service c5cf8c
         call mpi_barrier( MPI_COMM_WORLD, ierr )
Packit Service c5cf8c
         if (rank .eq. 0) then
Packit Service c5cf8c
             call mpi_open_port( MPI_INFO_NULL, portname, ierr )
Packit Service c5cf8c
             call mpi_publish_name( "fservtest", MPI_INFO_NULL,  &
Packit Service c5cf8c
      &            portname, ierr )
Packit Service c5cf8c
         endif
Packit Service c5cf8c
         call mpi_barrier( MPI_COMM_WORLD, ierr )
Packit Service c5cf8c
         call mpi_comm_accept( portname, MPI_INFO_NULL, 0, comm,  &
Packit Service c5cf8c
      &                         intercomm, ierr )
Packit Service c5cf8c
Packit Service c5cf8c
         if (rank .eq. 0) then 
Packit Service c5cf8c
            call mpi_close_port( portname, ierr )
Packit Service c5cf8c
            call mpi_unpublish_name( "fservtest", MPI_INFO_NULL, &
Packit Service c5cf8c
      &            portname, ierr )
Packit Service c5cf8c
         endif
Packit Service c5cf8c
Packit Service c5cf8c
      else
Packit Service c5cf8c
!        Client
Packit Service c5cf8c
         call mpi_comm_set_errhandler( MPI_COMM_WORLD,MPI_ERRORS_RETURN,  &
Packit Service c5cf8c
      &                                 ierr )
Packit Service c5cf8c
         ierr = MPI_SUCCESS
Packit Service c5cf8c
         call mpi_lookup_name( "fservtest", MPI_INFO_NULL,  &
Packit Service c5cf8c
      &                         portname, ierr )
Packit Service c5cf8c
         if (ierr .eq. MPI_SUCCESS) then
Packit Service c5cf8c
            errs = errs + 1
Packit Service c5cf8c
            print *, 'lookup name returned a value before published'
Packit Service c5cf8c
         else
Packit Service c5cf8c
            call mpi_error_class( ierr, eclass, ierr )
Packit Service c5cf8c
            if (eclass .ne. MPI_ERR_NAME) then
Packit Service c5cf8c
               errs = errs + 1
Packit Service c5cf8c
               print *, ' Wrong error class, is ', eclass, ' must be ', &
Packit Service c5cf8c
      &          MPI_ERR_NAME
Packit Service c5cf8c
!              See the MPI-2 Standard, 5.4.4
Packit Service c5cf8c
            endif
Packit Service c5cf8c
         endif
Packit Service c5cf8c
         call mpi_comm_set_errhandler( MPI_COMM_WORLD,  &
Packit Service c5cf8c
      &            MPI_ERRORS_ARE_FATAL, ierr )
Packit Service c5cf8c
         call mpi_barrier( MPI_COMM_WORLD, ierr )
Packit Service c5cf8c
         call mpi_barrier( MPI_COMM_WORLD, ierr )
Packit Service c5cf8c
         call mpi_lookup_name( "fservtest", MPI_INFO_NULL,  &
Packit Service c5cf8c
      &                         portname, ierr )
Packit Service c5cf8c
!        This should not happen (ERRORS_ARE_FATAL), but just in case...
Packit Service c5cf8c
         if (ierr .ne. MPI_SUCCESS) then
Packit Service c5cf8c
            errs = errs + 1
Packit Service c5cf8c
            print *, ' Major error: errors_are_fatal set but returned'
Packit Service c5cf8c
            print *, ' non MPI_SUCCESS value.  Details:'
Packit Service c5cf8c
            call MTestPrintErrorMsg( ' Unable to lookup fservtest port',  &
Packit Service c5cf8c
      &                               ierr )
Packit Service c5cf8c
!           Unable to continue without a valid port
Packit Service c5cf8c
            call mpi_abort( MPI_COMM_WORLD, 1, ierr )
Packit Service c5cf8c
         endif
Packit Service c5cf8c
         call mpi_comm_connect( portname, MPI_INFO_NULL, 0, comm,  &
Packit Service c5cf8c
      &                          intercomm, ierr )
Packit Service c5cf8c
      endif
Packit Service c5cf8c
!
Packit Service c5cf8c
! Check that this is an acceptable intercomm
Packit Service c5cf8c
      call mpi_comm_size( intercomm, s1, ierr )
Packit Service c5cf8c
      call mpi_comm_remote_size( intercomm, s2, ierr )
Packit Service c5cf8c
      if (s1 + s2 .ne. size) then
Packit Service c5cf8c
         errs = errs + 1
Packit Service c5cf8c
         print *, ' Wrong size for intercomm = ', s1+s2
Packit Service c5cf8c
      endif
Packit Service c5cf8c
Packit Service c5cf8c
      call mpi_comm_free(comm, ierr)
Packit Service c5cf8c
! Everyone can now abandon the new intercomm      
Packit Service c5cf8c
      call mpi_comm_disconnect( intercomm, ierr )
Packit Service c5cf8c
Packit Service c5cf8c
      call mtest_finalize( errs )
Packit Service c5cf8c
Packit Service c5cf8c
      end