|
Packit Service |
c5cf8c |
C -*- Mode: Fortran; -*-
|
|
Packit Service |
c5cf8c |
C
|
|
Packit Service |
c5cf8c |
C (C) 2003 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
C See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
C
|
|
Packit Service |
c5cf8c |
subroutine query_fn( extrastate, status, ierr )
|
|
Packit Service |
c5cf8c |
implicit none
|
|
Packit Service |
c5cf8c |
include 'mpif.h'
|
|
Packit Service |
c5cf8c |
integer status(MPI_STATUS_SIZE), ierr
|
|
Packit Service |
c5cf8c |
include 'attr1aints.h'
|
|
Packit Service |
c5cf8c |
C
|
|
Packit Service |
c5cf8c |
C set a default status
|
|
Packit Service |
c5cf8c |
status(MPI_SOURCE) = MPI_UNDEFINED
|
|
Packit Service |
c5cf8c |
status(MPI_TAG) = MPI_UNDEFINED
|
|
Packit Service |
c5cf8c |
call mpi_status_set_cancelled( status, .false., ierr)
|
|
Packit Service |
c5cf8c |
call mpi_status_set_elements( status, MPI_BYTE, 0, ierr )
|
|
Packit Service |
c5cf8c |
ierr = MPI_SUCCESS
|
|
Packit Service |
c5cf8c |
end
|
|
Packit Service |
c5cf8c |
C
|
|
Packit Service |
c5cf8c |
subroutine free_fn( extrastate, ierr )
|
|
Packit Service |
c5cf8c |
implicit none
|
|
Packit Service |
c5cf8c |
include 'mpif.h'
|
|
Packit Service |
c5cf8c |
integer value, ierr
|
|
Packit Service |
c5cf8c |
include 'attr1aints.h'
|
|
Packit Service |
c5cf8c |
integer freefncall
|
|
Packit Service |
c5cf8c |
common /fnccalls/ freefncall
|
|
Packit Service |
c5cf8c |
C
|
|
Packit Service |
c5cf8c |
C For testing purposes, the following print can be used to check whether
|
|
Packit Service |
c5cf8c |
C the free_fn is called
|
|
Packit Service |
c5cf8c |
C print *, 'Free_fn called'
|
|
Packit Service |
c5cf8c |
C
|
|
Packit Service |
c5cf8c |
extrastate = extrastate - 1
|
|
Packit Service |
c5cf8c |
C The value returned by the free function is the error code
|
|
Packit Service |
c5cf8c |
C returned by the wait/test function
|
|
Packit Service |
c5cf8c |
ierr = MPI_SUCCESS
|
|
Packit Service |
c5cf8c |
end
|
|
Packit Service |
c5cf8c |
C
|
|
Packit Service |
c5cf8c |
subroutine cancel_fn( extrastate, complete, ierr )
|
|
Packit Service |
c5cf8c |
implicit none
|
|
Packit Service |
c5cf8c |
include 'mpif.h'
|
|
Packit Service |
c5cf8c |
integer ierr
|
|
Packit Service |
c5cf8c |
logical complete
|
|
Packit Service |
c5cf8c |
include 'attr1aints.h'
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
ierr = MPI_SUCCESS
|
|
Packit Service |
c5cf8c |
end
|
|
Packit Service |
c5cf8c |
C
|
|
Packit Service |
c5cf8c |
C
|
|
Packit Service |
c5cf8c |
C This is a very simple test of generalized requests. Normally, the
|
|
Packit Service |
c5cf8c |
C MPI_Grequest_complete function would be called from another routine,
|
|
Packit Service |
c5cf8c |
C often running in a separate thread. This simple code allows us to
|
|
Packit Service |
c5cf8c |
C check that requests can be created, tested, and waited on in the
|
|
Packit Service |
c5cf8c |
C case where the request is complete before the wait is called.
|
|
Packit Service |
c5cf8c |
C
|
|
Packit Service |
c5cf8c |
C Note that MPI did *not* define a routine that can be called within
|
|
Packit Service |
c5cf8c |
C test or wait to advance the state of a generalized request.
|
|
Packit Service |
c5cf8c |
C Most uses of generalized requests will need to use a separate thread.
|
|
Packit Service |
c5cf8c |
C
|
|
Packit Service |
c5cf8c |
program main
|
|
Packit Service |
c5cf8c |
implicit none
|
|
Packit Service |
c5cf8c |
include 'mpif.h'
|
|
Packit Service |
c5cf8c |
integer errs, ierr
|
|
Packit Service |
c5cf8c |
logical flag
|
|
Packit Service |
c5cf8c |
integer status(MPI_STATUS_SIZE)
|
|
Packit Service |
c5cf8c |
integer request
|
|
Packit Service |
c5cf8c |
external query_fn, free_fn, cancel_fn
|
|
Packit Service |
c5cf8c |
include 'attr1aints.h'
|
|
Packit Service |
c5cf8c |
integer freefncall
|
|
Packit Service |
c5cf8c |
common /fnccalls/ freefncall
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
errs = 0
|
|
Packit Service |
c5cf8c |
freefncall = 0
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
call MTest_Init( ierr )
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
extrastate = 0
|
|
Packit Service |
c5cf8c |
call mpi_grequest_start( query_fn, free_fn, cancel_fn,
|
|
Packit Service |
c5cf8c |
& extrastate, request, ierr )
|
|
Packit Service |
c5cf8c |
call mpi_test( request, flag, status, ierr )
|
|
Packit Service |
c5cf8c |
if (flag) then
|
|
Packit Service |
c5cf8c |
errs = errs + 1
|
|
Packit Service |
c5cf8c |
print *, 'Generalized request marked as complete'
|
|
Packit Service |
c5cf8c |
endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
call mpi_grequest_complete( request, ierr )
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
call MPI_Wait( request, status, ierr )
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
extrastate = 1
|
|
Packit Service |
c5cf8c |
call mpi_grequest_start( query_fn, free_fn, cancel_fn,
|
|
Packit Service |
c5cf8c |
& extrastate, request, ierr )
|
|
Packit Service |
c5cf8c |
call mpi_grequest_complete( request, ierr )
|
|
Packit Service |
c5cf8c |
call mpi_wait( request, MPI_STATUS_IGNORE, ierr )
|
|
Packit Service |
c5cf8c |
C
|
|
Packit Service |
c5cf8c |
C The following routine may prevent an optimizing compiler from
|
|
Packit Service |
c5cf8c |
C just remembering that extrastate was set in grequest_start
|
|
Packit Service |
c5cf8c |
call dummyupdate(extrastate)
|
|
Packit Service |
c5cf8c |
if (extrastate .ne. 0) then
|
|
Packit Service |
c5cf8c |
errs = errs + 1
|
|
Packit Service |
c5cf8c |
if (freefncall .eq. 0) then
|
|
Packit Service |
c5cf8c |
print *, 'Free routine not called'
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
print *, 'Free routine did not update extra_data'
|
|
Packit Service |
c5cf8c |
print *, 'extrastate = ', extrastate
|
|
Packit Service |
c5cf8c |
endif
|
|
Packit Service |
c5cf8c |
endif
|
|
Packit Service |
c5cf8c |
C
|
|
Packit Service |
c5cf8c |
call MTest_Finalize( errs )
|
|
Packit Service |
c5cf8c |
end
|
|
Packit Service |
c5cf8c |
C
|