Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[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         integer myindex
19         common /grr/ myindex
20
21         call MPI_Initialized( flag, ierr )
22         if (.not. flag) then
23            call MPI_Init( ierr )
24         endif
25
26         dbgflag = .false.
27         myindex = 0
28         call MPI_Comm_rank( MPI_COMM_WORLD, wrank, ierr )
29         end
30 C
31         subroutine MTest_Finalize( errs )
32         implicit none
33         include 'mpif.h'
34         integer errs
35         integer rank, toterrs, ierr
36         
37         call MPI_Comm_rank( MPI_COMM_WORLD, rank, ierr )
38
39         call MPI_Allreduce( errs, toterrs, 1, MPI_INTEGER, MPI_SUM, 
40      *        MPI_COMM_WORLD, ierr ) 
41         
42         if (rank .eq. 0) then
43            if (toterrs .gt. 0) then 
44                 print *, " Found ", toterrs, " errors"
45            else
46                 print *, " No Errors"
47            endif
48         endif
49         end
50 C
51 C A simple get intracomm for now
52         logical function MTestGetIntracomm( comm, min_size, qsmaller )
53         implicit none
54         include 'mpif.h'
55         integer ierr
56         integer comm, min_size, size, rank
57         logical qsmaller
58         integer myindex
59         common /grr/ myindex 
60
61         comm = MPI_COMM_NULL
62         if (myindex .eq. 0) then
63            comm = MPI_COMM_WORLD
64         else if (myindex .eq. 1) then
65            call mpi_comm_dup( MPI_COMM_WORLD, comm, ierr )
66         else if (myindex .eq. 2) then
67            call mpi_comm_size( MPI_COMM_WORLD, size, ierr )
68            call mpi_comm_rank( MPI_COMM_WORLD, rank, ierr )
69            call mpi_comm_split( MPI_COMM_WORLD, 0, size - rank, comm, 
70      &                                 ierr )
71         else
72            if (min_size .eq. 1 .and. myindex .eq. 3) then
73               comm = MPI_COMM_SELF
74            endif
75         endif
76         myindex = mod( myindex, 4 ) + 1
77         MTestGetIntracomm = comm .ne. MPI_COMM_NULL
78         qsmaller=.true.
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