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 INTEGER STATUS (MPI_STATUS_SIZE)
112
113! Loop on send and Recv : NSPMD*NSPMD communications
114! Since there is not collective asynchronous communication
115! with msmpi.
116
117 ALLOCATE(my_struct%TAB(stab),stat=ierror)
118 ALLOCATE(my_struct%BUFFER_TAB(stab,nspmd),stat=ierror)
119 ALLOCATE(my_struct%BUFFER_VAL(nspmd) ,stat=ierror)
120 ALLOCATE(my_struct%RQ_SEND_VAL(nspmd),stat=ierror)
121 ALLOCATE(my_struct%RQ_RECV_VAL(nspmd),stat=ierror)
122 ALLOCATE(my_struct%RQ_SEND_TAB(nspmd),stat=ierror)
123 ALLOCATE(my_struct%RQ_RECV_TAB(nspmd),stat=ierror)
124
125 my_struct%LENGTH_TAB = stab
126 my_struct%VAL = val
127 my_struct%TAB(1:stab) = tab(1:stab)
128 my_struct%BUFFER_VAL(ispmd+1) = val
129 my_struct%BUFFER_TAB(1:stab,ispmd+1) = tab(1:stab)
130
131
132 DO p = 1, nspmd
133 IF( p /= ispmd +1 ) THEN
134 msgtyp = 17000
135 CALL mpi_irecv(
136 1 my_struct%BUFFER_VAL(p) ,1,real,it_spmd(p),msgtyp,
137 2 spmd_comm_world,my_struct%RQ_RECV_VAL(p),ierror)
138
139 msgtyp = 17001
140 CALL mpi_irecv(
141 1 my_struct%BUFFER_TAB(1,p),my_struct%LENGTH_TAB,mpi_integer,it_spmd(p),msgtyp,
142 2 spmd_comm_world,my_struct%RQ_RECV_TAB(p),ierror)
143 ENDIF
144 ENDDO
145 DO p = 1, nspmd
146 IF( p /= ispmd +1 ) THEN
147 msgtyp = 17000
148 CALL mpi_isend(
149 1 my_struct%VAL ,1,real,it_spmd(p),msgtyp,
150 2 spmd_comm_world,my_struct%RQ_SEND_VAL(p),ierror)
151
152 msgtyp = 17001
153 CALL mpi_isend(
154 1 my_struct%TAB,my_struct%LENGTH_TAB,mpi_integer,it_spmd(p),msgtyp,
155 2 spmd_comm_world,my_struct%RQ_SEND_TAB(p),ierror)
156 ENDIF
157 ENDDO
158
159#endif
160 RETURN
161 END SUBROUTINE mpi_min_real_begin
162
163!||====================================================================
164!|| mpi_min_real_end ../engine/share/modules/mpi_tools_mod.F
165!||--- called by ------------------------------------------------------
166!|| resol ../engine/source/engine/resol.F
167!||--- calls -----------------------------------------------------
168!||--- uses -----------------------------------------------------
169!|| message_mod ../engine/share/message_module/message_mod.F
170!|| spmd_comm_world_mod ../engine/source/mpi/spmd_comm_world.F90
171!||====================================================================
172 SUBROUTINE mpi_min_real_end(VAL,TAB,STAB,MY_STRUCT)
173C-----------------------------------------------
174C M o d u l e s
175C-----------------------------------------------
176 USE message_mod
177C-----------------------------------------------
178C I m p l i c i t T y p e s
179C-----------------------------------------------
180 USE spmd_comm_world_mod, ONLY : spmd_comm_world
181#include "implicit_f.inc"
182#include "r4r8_p.inc"
183C-----------------------------------------------
184C M e s s a g e P a s s i n g
185C-----------------------------------------------
186#include "spmd.inc"
187C-----------------------------------------------
188C C o m m o n B l o c k s
189C-----------------------------------------------
190#include "com01_c.inc"
191#include "com04_c.inc"
192#include "scr02_c.inc"
193#include "scr18_c.inc"
194#include "task_c.inc"
195#include "units_c.inc"
196#include "warn_c.inc"
197#include "timeri_c.inc"
198C-----------------------------------------------
199C D u m m y A r g u m e n t s
200C-----------------------------------------------
201 my_real, INTENT(INOUT) :: val ! value to be minimized
202 INTEGER, INTENT(IN) :: STAB !size of integer tab
203 INTEGER, INTENT(INOUT) :: TAB(STAB) !Tab of integer to send
204 TYPE(mpi_min_real_struct), INTENT(INOUT) :: MY_STRUCT
205C-----------------------------------------------
206C L o c a l V a r i a b l e s
207C-----------------------------------------------
208 INTEGER P,PMIN,IERROR
209 INTEGER MSGTYP
210#ifdef MPI
211 INTEGER STATUS (MPI_STATUS_SIZE)
212
213 ! WAIT SEND & RECV
214 DO p=1,nspmd
215 IF(ispmd + 1 /= p) THEN
216 CALL mpi_wait(my_struct%RQ_SEND_VAL(p),status,ierror)
217 CALL mpi_wait(my_struct%RQ_SEND_TAB(p),status,ierror)
218 CALL mpi_wait(my_struct%RQ_RECV_VAL(p),status,ierror)
219 CALL mpi_wait(my_struct%RQ_RECV_TAB(p),status,ierror)
220 ENDIF
221 ENDDO
222
223
224 ! Find the minimum value of VAL and the processor that has it
225 pmin = 1
226 val = my_struct%BUFFER_VAL(1)
227 DO p=2,nspmd
228 IF(val > my_struct%BUFFER_VAL(p)) THEN
229 val = my_struct%BUFFER_VAL(p)
230 pmin = p
231 ENDIF
232 ENDDO
233
234 ! TAB <- TAB of the processor that has the mini. value of VAL
235 tab(1:stab) = my_struct%BUFFER_TAB(1:stab,pmin)
236
237 DEALLOCATE(my_struct%TAB)
238 DEALLOCATE(my_struct%BUFFER_TAB)
239 DEALLOCATE(my_struct%BUFFER_VAL )
240 DEALLOCATE(my_struct%RQ_SEND_VAL)
241 DEALLOCATE(my_struct%RQ_RECV_VAL)
242 DEALLOCATE(my_struct%RQ_SEND_TAB)
243 DEALLOCATE(my_struct%RQ_RECV_TAB)
244
245#endif
246 RETURN
247 END SUBROUTINE mpi_min_real_end
248
249
250
251 END MODULE mpi_tools_mod
252
#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)