xref: /phasta/svLS/COMMU.f (revision cc72a73fd2b79f4dd0a850fa4af718cd73554811)
1!     This software is Copyright (c) 2012-2015 The Regents of the
2!     University of California. All Rights Reserved.
3!
4!     Permission to copy and modify this software and its documentation
5!     for educational, research and non-profit purposes, without fee,
6!     and without a written agreement is hereby granted, provided that
7!     the above copyright notice, this paragraph and the following three
8!     paragraphs appear in all copies.
9!
10!     Permission to make commercial use of this software may be obtained
11!     by contacting:
12!
13!     Technology Transfer Office
14!     9500 Gilman Drive, Mail Code 0910
15!     University of California
16!     La Jolla, CA 92093-0910
17!     (858) 534-5815
18!     invent@ucsd.edu
19!
20!     This software program and documentation are copyrighted by The
21!     Regents of the University of California. The software program and
22!     documentation are supplied "as is", without any accompanying
23!     services from The Regents. The Regents does not warrant that the
24!     operation of the program will be uninterrupted or error-free. The
25!     end-user understands that the program was developed for research
26!     purposes and is advised not to rely exclusively on the program for
27!     any reason.
28!
29!     IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY
30!     PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
31!     DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS
32!     SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
33!     CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34!     THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
35!     WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
36!     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
37!     SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
38!     UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE
39!     MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
40
41      SUBROUTINE svLS_COMMU_CREATE(commu, commi)
42
43      INCLUDE "svLS_STD.h"
44
45      TYPE(svLS_commuType), INTENT(INOUT) :: commu
46      INTEGER, INTENT(IN) :: commi
47
48      INTEGER ierr
49      INTEGER comm
50
51      IF (commu%foC) THEN
52         PRINT *, "COMMU is not free"
53         PRINT *, "You may use svLS_COMMU_FREE to free this structure"
54      END IF
55
56      commu%foC  = .TRUE.
57      commu%comm = commi
58
59      comm       = commi
60
61      CALL MPI_COMM_RANK(comm, commu%task, ierr)
62      CALL MPI_COMM_SIZE(comm, commu%nTasks, ierr)
63
64      CALL MPI_ALLREDUCE(commu%task, commu%master, 1, mpint, MPI_MIN,
65     2   comm, ierr)
66
67      IF (commu%master .NE. 0) THEN
68         PRINT *, "master is not zero"
69         CALL MPI_FINALIZE(comm, ierr)
70         STOP
71      END IF
72
73      commu%masF  = .FALSE.
74      commu%tF    = commu%task + 1
75      IF (commu%task .EQ. commu%master) THEN
76         commu%masF = .TRUE.
77      END IF
78
79      RETURN
80      END SUBROUTINE svLS_COMMU_CREATE
81
82!====================================================================
83
84      SUBROUTINE svLS_COMMU_FREE(commu)
85
86      INCLUDE "svLS_STD.h"
87
88      TYPE(svLS_commuType), INTENT(INOUT) :: commu
89
90      IF (.NOT.commu%foC) THEN
91         PRINT *, 'Cannot free commu'
92         PRINT *, 'It is not created yet'
93         STOP
94      END IF
95      commu%foC  = .FALSE.
96
97      RETURN
98      END SUBROUTINE svLS_COMMU_FREE
99