Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
56b76b7e88a98f2723be19175fa6b9e6a2ecce42
[simgrid.git] / teshsuite / smpi / mpich3-test / f90 / util / mtestf90.f90
1 ! This file created from test/mpi/f77/util/mtestf.f with f77tof90
2 ! -*- Mode: Fortran; -*- 
3 !
4 !  (C) 2003 by Argonne National Laboratory.
5 !      See COPYRIGHT in top-level directory.
6 !
7         subroutine MTest_Init( ierr )
8 !       Place the include first so that we can automatically create a
9 !       Fortran 90 version that uses the mpi module instead.  If
10 !       the module is in a different place, the compiler can complain
11 !       about out-of-order statements
12         use mpi
13         integer ierr
14         logical flag
15         logical dbgflag
16         integer wrank
17         common /mtest/ dbgflag, wrank
18
19         call MPI_Initialized( flag, ierr )
20         if (.not. flag) then
21            call MPI_Init( ierr )
22         endif
23
24         dbgflag = .false.
25         call MPI_Comm_rank( MPI_COMM_WORLD, wrank, ierr )
26         end
27 !
28         subroutine MTest_Finalize( errs )
29         use mpi
30         integer errs
31         integer rank, toterrs, ierr
32         
33         call MPI_Comm_rank( MPI_COMM_WORLD, rank, ierr )
34
35         call MPI_Allreduce( errs, toterrs, 1, MPI_INTEGER, MPI_SUM,  &
36       &        MPI_COMM_WORLD, ierr ) 
37         
38         if (rank .eq. 0) then
39            if (toterrs .gt. 0) then 
40                 print *, " Found ", toterrs, " errors"
41            else
42                 print *, " No Errors"
43            endif
44         endif
45         end
46 !
47 ! A simple get intracomm for now
48         logical function MTestGetIntracomm( comm, min_size, qsmaller )
49         use mpi
50         integer ierr
51         integer comm, min_size, size, rank
52         logical qsmaller
53         integer myindex
54         save myindex
55         data myindex /0/
56
57         comm = MPI_COMM_NULL
58         if (myindex .eq. 0) then
59            comm = MPI_COMM_WORLD
60         else if (myindex .eq. 1) then
61            call mpi_comm_dup( MPI_COMM_WORLD, comm, ierr )
62         else if (myindex .eq. 2) then
63            call mpi_comm_size( MPI_COMM_WORLD, size, ierr )
64            call mpi_comm_rank( MPI_COMM_WORLD, rank, ierr )
65            call mpi_comm_split( MPI_COMM_WORLD, 0, size - rank, comm,  &
66       &                                 ierr )
67         else
68            if (min_size .eq. 1 .and. myindex .eq. 3) then
69               comm = MPI_COMM_SELF
70            endif
71         endif
72         myindex = mod( myindex, 4 ) + 1
73         MTestGetIntracomm = comm .ne. MPI_COMM_NULL
74         end
75 !
76         subroutine MTestFreeComm( comm )
77         use mpi
78         integer comm, ierr
79         if (comm .ne. MPI_COMM_WORLD .and. &
80       &      comm .ne. MPI_COMM_SELF  .and. &
81       &      comm .ne. MPI_COMM_NULL) then
82            call mpi_comm_free( comm, ierr )
83         endif
84         end
85 !
86         subroutine MTestPrintError( errcode )
87         use mpi
88         integer errcode
89         integer errclass, slen, ierr
90         character*(MPI_MAX_ERROR_STRING) string
91
92         call MPI_Error_class( errcode, errclass, ierr )
93         call MPI_Error_string( errcode, string, slen, ierr )
94         print *, "Error class ", errclass, "(", string(1:slen), ")"
95         end
96 !
97         subroutine MTestPrintErrorMsg( msg, errcode )
98         use mpi
99         character*(*) msg
100         integer errcode
101         integer errclass, slen, ierr
102         character*(MPI_MAX_ERROR_STRING) string
103
104         call MPI_Error_class( errcode, errclass, ierr )
105         call MPI_Error_string( errcode, string, slen, ierr )
106         print *, msg, ": Error class ", errclass, " &
107       &       (", string(1:slen), ")" 
108         end