Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Revert "remove useless (?) common block in fortran code as flang7 has problems compil...
[simgrid.git] / teshsuite / smpi / mpich3-test / f77 / util / mtestf.f
1 C -*- Mode: Fortran; -*- 
2 C
3 C  (C) 2003 by Argonne National Laboratory.
4 C      See COPYRIGHT in top-level directory.
5 C
6         subroutine MTest_Init( ierr )
7 C       Place the include first so that we can automatically create a
8 C       Fortran 90 version that uses the mpi module instead.  If
9 C       the module is in a different place, the compiler can complain
10 C       about out-of-order statements
11         implicit none
12         include 'mpif.h'
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 C
28         subroutine MTest_Finalize( errs )
29         implicit none
30         include 'mpif.h'
31         integer errs
32         integer rank, toterrs, ierr
33         
34         call MPI_Comm_rank( MPI_COMM_WORLD, rank, ierr )
35
36         call MPI_Allreduce( errs, toterrs, 1, MPI_INTEGER, MPI_SUM, 
37      *        MPI_COMM_WORLD, ierr ) 
38         
39         if (rank .eq. 0) then
40            if (toterrs .gt. 0) then 
41                 print *, " Found ", toterrs, " errors"
42            else
43                 print *, " No Errors"
44            endif
45         endif
46         end
47 C
48 C A simple get intracomm for now
49         logical function MTestGetIntracomm( comm, min_size, qsmaller )
50         implicit none
51         include 'mpif.h'
52         integer ierr
53         integer comm, min_size, size, rank
54         logical qsmaller
55         integer myindex
56         save myindex
57         data myindex /0/
58
59         if (.false.) then
60            qsmaller = qsmaller
61         endif
62         comm = MPI_COMM_NULL
63         if (myindex .eq. 0) then
64            comm = MPI_COMM_WORLD
65         else if (myindex .eq. 1) then
66            call mpi_comm_dup( MPI_COMM_WORLD, comm, ierr )
67         else if (myindex .eq. 2) then
68            call mpi_comm_size( MPI_COMM_WORLD, size, ierr )
69            call mpi_comm_rank( MPI_COMM_WORLD, rank, ierr )
70            call mpi_comm_split( MPI_COMM_WORLD, 0, size - rank, comm, 
71      &                                 ierr )
72         else
73            if (min_size .eq. 1 .and. myindex .eq. 3) then
74               comm = MPI_COMM_SELF
75            endif
76         endif
77         myindex = mod( myindex, 4 ) + 1
78         MTestGetIntracomm = comm .ne. MPI_COMM_NULL
79         end
80 C
81         subroutine MTestFreeComm( comm )
82         implicit none
83         include 'mpif.h'
84         integer comm, ierr
85         if (comm .ne. MPI_COMM_WORLD .and.
86      &      comm .ne. MPI_COMM_SELF  .and.
87      &      comm .ne. MPI_COMM_NULL) then
88            call mpi_comm_free( comm, ierr )
89         endif
90         end
91 C
92         subroutine MTestPrintError( errcode )
93         implicit none
94         include 'mpif.h'
95         integer errcode
96         integer errclass, slen, ierr
97         character*(MPI_MAX_ERROR_STRING) string
98
99         call MPI_Error_class( errcode, errclass, ierr )
100         call MPI_Error_string( errcode, string, slen, ierr )
101         print *, "Error class ", errclass, "(", string(1:slen), ")"
102         end
103 C
104         subroutine MTestPrintErrorMsg( msg, errcode )
105         implicit none
106         include 'mpif.h'
107         character*(*) msg
108         integer errcode
109         integer errclass, slen, ierr
110         character*(MPI_MAX_ERROR_STRING) string
111
112         call MPI_Error_class( errcode, errclass, ierr )
113         call MPI_Error_string( errcode, string, slen, ierr )
114         print *, msg, ": Error class ", errclass, "
115      $       (", string(1:slen), ")" 
116         end