OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
mpi_tools_mod.F
Go to the documentation of this file.
1Copyright> OpenRadioss
2Copyright> Copyright (C) 1986-2025 Altair Engineering Inc.
3Copyright>
4Copyright> This program is free software: you can redistribute it and/or modify
5Copyright> it under the terms of the GNU Affero General Public License as published by
6Copyright> the Free Software Foundation, either version 3 of the License, or
7Copyright> (at your option) any later version.
8Copyright>
9Copyright> This program is distributed in the hope that it will be useful,
10Copyright> but WITHOUT ANY WARRANTY; without even the implied warranty of
11Copyright> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12Copyright> GNU Affero General Public License for more details.
13Copyright>
14Copyright> You should have received a copy of the GNU Affero General Public License
15Copyright> along with this program. If not, see <https://www.gnu.org/licenses/>.
16Copyright>
17Copyright>
18Copyright> Commercial Alternative: Altair Radioss Software
19Copyright>
20Copyright> As an alternative to this open-source version, Altair also offers Altair Radioss
21Copyright> software under a commercial license. Contact Altair to discuss further if the
22Copyright> commercial version may interest you: https://www.altair.com/radioss/.
23!||====================================================================
24!|| mpi_tools_mod ../engine/share/modules/mpi_tools_mod.F
25!||--- called by ------------------------------------------------------
26!|| resol ../engine/source/engine/resol.F
27!||====================================================================
29C-----------------------------------------------
30C m y _ r e a l
31C-----------------------------------------------
32#include "my_real.inc"
33C-----------------------------------------------
34C D e r i v e d T y p e D e f i n i t i o n s
35C-----------------------------------------------
37 my_real :: val
38 INTEGER, DIMENSION(:), POINTER :: tab
39 INTEGER :: length_tab
40 INTEGER, DIMENSION(:,:), POINTER :: buffer_tab
41 my_real, DIMENSION(:), POINTER :: buffer_val
42 INTEGER, DIMENSION(:), POINTER :: rq_send_val
43 INTEGER, DIMENSION(:), POINTER :: rq_send_tab
44 INTEGER, DIMENSION(:), POINTER :: rq_recv_val
45 INTEGER, DIMENSION(:), POINTER :: rq_recv_tab
46 END TYPE mpi_min_real_struct
47
48 CONTAINS
49
50C
51C Find the minimum value over all processor
52C - Asynchronous MPI communications: these routines are relevant only
53C for cases where a lot of computations is done between the two calls.
54C
55C TAB = ISPMD
56C VAL = ...
57C CALL MPI_MIN_REAL_BEGIN(VAL,TAB,1,MY_STRUCT)
58C ! a lot of computations
59C CALL MPI_MIN_REAL_END(VAL2,TAB2,1,MY_STRUCT)
60C ! VAL2 is the min of VAL over the processors
61C ! TAB2 is the TAB of the processor that has the minimum value of VAL
62
63!||====================================================================
64!|| mpi_min_real_begin ../engine/share/modules/mpi_tools_mod.F
65!||--- called by ------------------------------------------------------
66!|| resol ../engine/source/engine/resol.F
67!||--- calls -----------------------------------------------------
68!||--- uses -----------------------------------------------------
69!|| message_mod ../engine/share/message_module/message_mod.F
70!|| spmd_comm_world_mod ../engine/source/mpi/spmd_comm_world.F90
71!||====================================================================
72 SUBROUTINE mpi_min_real_begin(VAL,TAB,STAB,MY_STRUCT)
73C-----------------------------------------------
74C M o d u l e s
75C-----------------------------------------------
76 USE message_mod
77C-----------------------------------------------
78C I m p l i c i t T y p e s
79C-----------------------------------------------
80 USE spmd_comm_world_mod, ONLY : spmd_comm_world
81#include "implicit_f.inc"
82#include "r4r8_p.inc"
83C-----------------------------------------------
84C M e s s a g e P a s s i n g
85C-----------------------------------------------
86#include "spmd.inc"
87C-----------------------------------------------
88C C o m m o n B l o c k s
89C-----------------------------------------------
90#include "com01_c.inc"
91#include "com04_c.inc"
92#include "scr02_c.inc"
93#include "scr18_c.inc"
94#include "task_c.inc"
95#include "units_c.inc"
96#include "warn_c.inc"
97#include "timeri_c.inc"
98C-----------------------------------------------
99C D u m m y A r g u m e n t s
100C-----------------------------------------------
101 my_real, INTENT(IN) :: val ! value to be minimized
102 INTEGER, INTENT(IN) :: STAB !size of integer tab
103 INTEGER, INTENT(IN) :: TAB(STAB) !Tab of integer to send
104 TYPE(mpi_min_real_struct), INTENT(INOUT) :: MY_STRUCT
105C-----------------------------------------------
106C L o c a l V a r i a b l e s
107C-----------------------------------------------
108 INTEGER P,IERROR
109 INTEGER MSGTYP
110#ifdef MPI
111
112! Loop on send and Recv : NSPMD*NSPMD communications
113! Since there is not collective asynchronous communication
114! with msmpi.
115
116 ALLOCATE(my_struct%TAB(stab),stat=ierror)
117 ALLOCATE(my_struct%BUFFER_TAB(stab,nspmd),stat=ierror)
118 ALLOCATE(my_struct%BUFFER_VAL(nspmd) ,stat=ierror)
119 ALLOCATE(my_struct%RQ_SEND_VAL(nspmd),stat=ierror)
120 ALLOCATE(my_struct%RQ_RECV_VAL(nspmd),stat=ierror)
121 ALLOCATE(my_struct%RQ_SEND_TAB(nspmd),stat=ierror)
122 ALLOCATE(my_struct%RQ_RECV_TAB(nspmd),stat=ierror)
123
124 my_struct%LENGTH_TAB = stab
125 my_struct%VAL = val
126 my_struct%TAB(1:stab) = tab(1:stab)
127 my_struct%BUFFER_VAL(ispmd+1) = val
128 my_struct%BUFFER_TAB(1:stab,ispmd+1) = tab(1:stab)
129
130
131 DO p = 1, nspmd
132 IF( p /= ispmd +1 ) THEN
133 msgtyp = 17000
134 CALL mpi_irecv(
135 1 my_struct%BUFFER_VAL(p) ,1,real,it_spmd(p),msgtyp,
136 2 spmd_comm_world,my_struct%RQ_RECV_VAL(p),ierror)
137
138 msgtyp = 17001
139 CALL mpi_irecv(
140 1 my_struct%BUFFER_TAB(1,p),my_struct%LENGTH_TAB,mpi_integer,it_spmd(p),msgtyp,
141 2 spmd_comm_world,my_struct%RQ_RECV_TAB(p),ierror)
142 ENDIF
143 ENDDO
144 DO p = 1, nspmd
145 IF( p /= ispmd +1 ) THEN
146 msgtyp = 17000
147 CALL mpi_isend(
148 1 my_struct%VAL ,1,real,it_spmd(p),msgtyp,
149 2 spmd_comm_world,my_struct%RQ_SEND_VAL(p),ierror)
150
151 msgtyp = 17001
152 CALL mpi_isend(
153 1 my_struct%TAB,my_struct%LENGTH_TAB,mpi_integer,it_spmd(p),msgtyp,
154 2 spmd_comm_world,my_struct%RQ_SEND_TAB(p),ierror)
155 ENDIF
156 ENDDO
157
158#endif
159 RETURN
160 END SUBROUTINE mpi_min_real_begin
161
162!||====================================================================
163!|| mpi_min_real_end ../engine/share/modules/mpi_tools_mod.F
164!||--- called by ------------------------------------------------------
165!|| resol ../engine/source/engine/resol.F
166!||--- calls -----------------------------------------------------
167!||--- uses -----------------------------------------------------
168!|| message_mod ../engine/share/message_module/message_mod.F
169!|| spmd_comm_world_mod ../engine/source/mpi/spmd_comm_world.F90
170!||====================================================================
171 SUBROUTINE mpi_min_real_end(VAL,TAB,STAB,MY_STRUCT)
172C-----------------------------------------------
173C M o d u l e s
174C-----------------------------------------------
175 USE message_mod
176C-----------------------------------------------
177C I m p l i c i t T y p e s
178C-----------------------------------------------
179 USE spmd_comm_world_mod, ONLY : spmd_comm_world
180#include "implicit_f.inc"
181#include "r4r8_p.inc"
182C-----------------------------------------------
183C M e s s a g e P a s s i n g
184C-----------------------------------------------
185#include "spmd.inc"
186C-----------------------------------------------
187C C o m m o n B l o c k s
188C-----------------------------------------------
189#include "com01_c.inc"
190#include "com04_c.inc"
191#include "scr02_c.inc"
192#include "scr18_c.inc"
193#include "task_c.inc"
194#include "units_c.inc"
195#include "warn_c.inc"
196#include "timeri_c.inc"
197C-----------------------------------------------
198C D u m m y A r g u m e n t s
199C-----------------------------------------------
200 my_real, INTENT(INOUT) :: val ! value to be minimized
201 INTEGER, INTENT(IN) :: STAB !size of integer tab
202 INTEGER, INTENT(INOUT) :: TAB(STAB) !Tab of integer to send
203 TYPE(mpi_min_real_struct), INTENT(INOUT) :: MY_STRUCT
204C-----------------------------------------------
205C L o c a l V a r i a b l e s
206C-----------------------------------------------
207 INTEGER P,PMIN,IERROR
208#ifdef MPI
209 INTEGER STATUS (MPI_STATUS_SIZE)
210
211 ! WAIT SEND & RECV
212 DO p=1,nspmd
213 IF(ispmd + 1 /= p) THEN
214 CALL mpi_wait(my_struct%RQ_SEND_VAL(p),status,ierror)
215 CALL mpi_wait(my_struct%RQ_SEND_TAB(p),status,ierror)
216 CALL mpi_wait(my_struct%RQ_RECV_VAL(p),status,ierror)
217 CALL mpi_wait(my_struct%RQ_RECV_TAB(p),status,ierror)
218 ENDIF
219 ENDDO
220
221
222 ! Find the minimum value of VAL and the processor that has it
223 pmin = 1
224 val = my_struct%BUFFER_VAL(1)
225 DO p=2,nspmd
226 IF(val > my_struct%BUFFER_VAL(p)) THEN
227 val = my_struct%BUFFER_VAL(p)
228 pmin = p
229 ENDIF
230 ENDDO
231
232 ! TAB <- TAB of the processor that has the mini. value of VAL
233 tab(1:stab) = my_struct%BUFFER_TAB(1:stab,pmin)
234
235 DEALLOCATE(my_struct%TAB)
236 DEALLOCATE(my_struct%BUFFER_TAB)
237 DEALLOCATE(my_struct%BUFFER_VAL )
238 DEALLOCATE(my_struct%RQ_SEND_VAL)
239 DEALLOCATE(my_struct%RQ_RECV_VAL)
240 DEALLOCATE(my_struct%RQ_SEND_TAB)
241 DEALLOCATE(my_struct%RQ_RECV_TAB)
242
243#endif
244 RETURN
245 END SUBROUTINE mpi_min_real_end
246
247
248
249 END MODULE mpi_tools_mod
250
#define my_real
Definition cppsort.cpp:32
subroutine mpi_isend(buf, cnt, datatype, dest, tag, comm, ireq, ierr)
Definition mpi.f:382
subroutine mpi_wait(ireq, status, ierr)
Definition mpi.f:525
subroutine mpi_irecv(buf, cnt, datatype, source, tag, comm, ireq, ierr)
Definition mpi.f:372
subroutine mpi_min_real_end(val, tab, stab, my_struct)
subroutine mpi_min_real_begin(val, tab, stab, my_struct)