Branch data Line data Source code
1 : : !!****p* ABINIT/testTransposer
2 : : !! NAME
3 : : !! testTransposer
4 : : !!
5 : : !! FUNCTION
6 : : !! test the xgTransposer module with 8 MPI. No more no less.
7 : : !! It includes testing of complex and real numbers, and all2all and gatherv
8 : : !!
9 : : !! COPYRIGHT
10 : : !! Copyright (C) 1998-2026 ABINIT group (JB)
11 : : !! This file is distributed under the terms of the
12 : : !! GNU General Public License, see ~abinit/COPYING
13 : : !! or http://www.gnu.org/copyleft/gpl.txt .
14 : : !! For the initials of contributors, see ~abinit/doc/developers/contributors.txt .
15 : : !!
16 : : !! NOTES
17 : : !!
18 : : !! INPUTS
19 : : !! (main routine)
20 : : !!
21 : : !! OUTPUT
22 : : !! (main routine)
23 : : !!
24 : : !! SOURCE
25 : :
26 : : #if defined HAVE_CONFIG_H
27 : : #include "config.h"
28 : : #endif
29 : :
30 : : #include "abi_common.h"
31 : :
32 : 2 : program testTransposer
33 : 2 : use m_xg
34 : : use m_xgTransposer
35 : : use m_xmpi
36 : : use m_time
37 : : use defs_basis
38 : : use m_profiling_abi
39 : : use m_errors
40 : :
41 : : implicit none
42 : :
43 : : integer :: npw
44 : : integer :: nband
45 : : integer :: ncycle
46 : : integer :: i
47 : : integer :: ierr
48 : : double precision :: errmax
49 : : double precision :: walltime
50 : : double precision :: cputime
51 : : double precision :: maxt
52 : : integer :: nCpuCols, nCpuRows
53 : 2 : double precision, allocatable :: cg(:,:)
54 : 2 : double precision, allocatable :: cg0(:,:)
55 : 2 : double precision, allocatable :: gh(:,:)
56 : 2 : double precision, allocatable :: ghc(:,:)
57 : : character(len=40) :: names(8)
58 : :
59 : : double precision :: nflops, ftimes(2)
60 : : integer :: ncount
61 : : double precision :: times(2)
62 : :
63 : : type(xgBlock_t) :: xcgLinalg
64 : : type(xgBlock_t) :: xcgColsRows
65 : : type(xgBlock_t) :: xghLinalg
66 : : type(xgBlock_t) :: xghColsRows
67 : : type(xgBlock_t) :: xghcLinalg
68 : : type(xgBlock_t) :: xghcColsRows
69 : 2 : type(xgTransposer_t) :: xgTransposer
70 : :
71 : :
72 : 2 : names(1662-1661) = 'xgTransposer_transpose@ColsRows'
73 : 2 : names(1663-1661) = 'xgTransposer_transpose@Linalg '
74 : 2 : names(1664-1661) = 'xgTransposer_*@all2all '
75 : 2 : names(1665-1661) = 'xgTransposer_*@gatherv '
76 : 2 : names(1666-1661) = 'xgTransposer_@reorganize '
77 : 2 : names(1667-1661) = 'xgTransposer_*constructor '
78 : 2 : names(1668-1661) = 'xgTransposer_free '
79 : 2 : names(1669-1661) = 'xgTransposer_transpose '
80 : :
81 : 2 : call xmpi_init()
82 : :
83 : 2 : npw = 4000+2*xmpi_comm_rank(xmpi_world)
84 : 2 : nband = 2000
85 : 2 : ncycle = 20
86 [ - + ]: 2 : if ( xmpi_comm_size(xmpi_world) > 1 ) then
87 [ # # ]: 0 : if ( MOD(xmpi_comm_size(xmpi_world),10) == 0 ) then
88 : 0 : nCpuRows = 2
89 [ # # ]: 0 : else if ( MOD(xmpi_comm_size(xmpi_world),8) == 0 ) then
90 : 0 : nCpuRows = 4
91 [ # # ]: 0 : else if ( MOD(xmpi_comm_size(xmpi_world),6) == 0 ) then
92 : 0 : nCpuRows = 3
93 [ # # ]: 0 : else if ( MOD(xmpi_comm_size(xmpi_world),4) == 0 ) then
94 : 0 : nCpuRows = 2
95 : : else
96 : 0 : nCpuRows = 1
97 : : end if
98 : 0 : nCpuCols = xmpi_comm_size(xmpi_world)/nCpuRows
99 : : else
100 : 2 : nCpuRows = 1
101 : 2 : nCpuCols = 1
102 : : end if
103 : :
104 : 2 : std_out = 6+xmpi_comm_rank(xmpi_world)
105 : :
106 : 2 : write(std_out,*) " nCpuRows,nCpuCols",nCpuRows,nCpuCols
107 : :
108 : :
109 : : ! Initialize memory profiling if it is activated
110 : : ! if a full memocc.prc report is desired, set the argument of abimem_init to "2" instead of "0"
111 : : ! note that memocc.prc files can easily be multiple GB in size so don't use this option normally
112 : : #ifdef HAVE_MEM_PROFILING
113 : : call abimem_init(0)
114 : : #endif
115 : :
116 : 2 : call test1()
117 : :
118 : : ! nspinor = 1
119 : 2 : call test2(1)
120 : :
121 : : ! nspinor = 2
122 : 2 : call test2(2)
123 : :
124 : 2 : call xg_finalize()
125 : :
126 : :
127 : : ! Writes information on file about the memory before ending mpi module, if memory profiling is enabled
128 : 2 : call abinit_doctor("__testtransposer")
129 : :
130 : 2 : call xmpi_end()
131 : :
132 : : contains
133 : : !!***
134 : :
135 : : !!****f* testTransposer/test1
136 : : !!
137 : : !! NAME
138 : : !! test1
139 : : !!
140 : : !! FUNCTION
141 : : !!
142 : : !! INPUTS
143 : : !! (main routine)
144 : : !!
145 : : !! OUTPUT
146 : : !! (main routine)
147 : : !!
148 : : !! SOURCE
149 : 2 : subroutine test1()
150 [ + - - + : 2 : ABI_MALLOC(cg, (2,npw*nband))
- + - + -
+ - + -
+ ]
151 [ + - - + : 2 : ABI_MALLOC(cg0, (2,npw*nband))
- + - + -
+ - + -
+ ]
152 : :
153 : 2 : call random_number(cg)
154 [ + + + + ]: 48000002 : cg0(:,:) = cg(:,:)
155 : :
156 : 2 : call xgBlock_map(xcgLinalg,cg,SPACE_C,npw,nband,xmpi_world)
157 : :
158 : 2 : write(std_out,*) " Complex all2all"
159 : : call xgTransposer_constructor(xgTransposer,xcgLinalg,xcgColsRows,1,&
160 : 2 : STATE_LINALG,TRANS_ALL2ALL,xmpi_comm_null,xmpi_comm_null,ncpuCols,ncpuRows,0)
161 : 2 : call backAndForth()
162 : 2 : call xgTransposer_free(xgTransposer)
163 : 2 : call printTimes()
164 : :
165 : 2 : write(std_out,*) " Complex gatherv"
166 : : call xgTransposer_constructor(xgTransposer,xcgLinalg,xcgColsRows,1,&
167 : 2 : STATE_LINALG,TRANS_GATHER,xmpi_comm_null,xmpi_comm_null,ncpuCols,ncpuRows,0)
168 : 2 : call backAndForth()
169 : 2 : call xgTransposer_free(xgTransposer)
170 : 2 : call printTimes()
171 : :
172 : 2 : call xgBlock_map(xcgLinalg,cg,SPACE_CR,npw,nband,xmpi_world)
173 : :
174 : 2 : write(std_out,*) " Real all2all"
175 : : call xgTransposer_constructor(xgTransposer,xcgLinalg,xcgColsRows,1,&
176 : 2 : STATE_LINALG,TRANS_ALL2ALL,xmpi_comm_null,xmpi_comm_null,ncpuCols,ncpuRows,0)
177 : 2 : call backAndForth()
178 : 2 : call xgTransposer_free(xgTransposer)
179 : 2 : call printTimes()
180 : :
181 : 2 : write(std_out,*) " Real gatherv"
182 : : call xgTransposer_constructor(xgTransposer,xcgLinalg,xcgColsRows,1,&
183 : 2 : STATE_LINALG,TRANS_GATHER,xmpi_comm_null,xmpi_comm_null,ncpuCols,ncpuRows,0)
184 : 2 : call backAndForth()
185 : 2 : call xgTransposer_free(xgTransposer)
186 : 2 : call printTimes()
187 : :
188 : 2 : write(std_out,*) " Complex all2all (nspinor=2)"
189 : : call xgTransposer_constructor(xgTransposer,xcgLinalg,xcgColsRows,2,&
190 : 2 : STATE_LINALG,TRANS_ALL2ALL,xmpi_comm_null,xmpi_comm_null,ncpuCols,ncpuRows,0)
191 : 2 : call backAndForth()
192 : 2 : call xgTransposer_free(xgTransposer)
193 : 2 : call printTimes()
194 : :
195 : 2 : write(std_out,*) " Complex gatherv (nspinor=2)"
196 : : call xgTransposer_constructor(xgTransposer,xcgLinalg,xcgColsRows,2,&
197 : 2 : STATE_LINALG,TRANS_GATHER,xmpi_comm_null,xmpi_comm_null,ncpuCols,ncpuRows,0)
198 : 2 : call backAndForth()
199 : 2 : call xgTransposer_free(xgTransposer)
200 : 2 : call printTimes()
201 : :
202 : 2 : call xgBlock_map(xcgLinalg,cg,SPACE_CR,npw,nband,xmpi_world)
203 : :
204 : 2 : write(std_out,*) " Real all2all (nspinor=2)"
205 : : call xgTransposer_constructor(xgTransposer,xcgLinalg,xcgColsRows,2,&
206 : 2 : STATE_LINALG,TRANS_ALL2ALL,xmpi_comm_null,xmpi_comm_null,ncpuCols,ncpuRows,0)
207 : 2 : call backAndForth()
208 : 2 : call xgTransposer_free(xgTransposer)
209 : 2 : call printTimes()
210 : :
211 : 2 : write(std_out,*) " Real gatherv (nspinor=2)"
212 : : call xgTransposer_constructor(xgTransposer,xcgLinalg,xcgColsRows,2,&
213 : 2 : STATE_LINALG,TRANS_GATHER,xmpi_comm_null,xmpi_comm_null,ncpuCols,ncpuRows,0)
214 : 2 : call backAndForth()
215 : 2 : call xgTransposer_free(xgTransposer)
216 : 2 : call printTimes()
217 : :
218 [ - + ]: 2 : ABI_FREE(cg)
219 [ - + ]: 2 : ABI_FREE(cg0)
220 : 2 : end subroutine test1
221 : : !!***
222 : :
223 : : !!****f* testTransposer/test2
224 : : !!
225 : : !! NAME
226 : : !! test2
227 : : !!
228 : : !! FUNCTION
229 : : !!
230 : : !! INPUTS
231 : : !! (main routine)
232 : : !!
233 : : !! OUTPUT
234 : : !! (main routine)
235 : : !!
236 : : !! SOURCE
237 : 4 : subroutine test2(nspinor)
238 : : integer,intent(in) :: nspinor
239 : 4 : type(xgTransposer_t) :: xgTransposerGh
240 : 4 : type(xgTransposer_t) :: xgTransposerGhc
241 : : type(xg_t) :: dotLinalg
242 : : type(xg_t) :: dotColsRows
243 : : double precision :: maxdiff
244 : :
245 : 4 : write(std_out,*) "Allocation"
246 [ + - - + : 4 : ABI_MALLOC(cg,(2,npw*nband))
- + - + -
+ - + -
+ ]
247 [ + - - + : 4 : ABI_MALLOC(gh,(2,npw*nband))
- + - + -
+ - + -
+ ]
248 [ + - - + : 4 : ABI_MALLOC(ghc,(2,npw*nband))
- + - + -
+ - + -
+ ]
249 : :
250 : 4 : write(std_out,*) "Mapping"
251 : 4 : call xgBlock_map(xcgLinalg,cg,SPACE_C,npw,nband,xmpi_world)
252 : 4 : call xgBlock_map(xghLinalg,gh,SPACE_C,npw,nband,xmpi_world)
253 : 4 : call xgBlock_map(xghcLinalg,ghc,SPACE_C,npw,nband,xmpi_world)
254 : :
255 : 4 : write(std_out,*) "Transposer constructor : nspinor =",nspinor
256 : :
257 : : call xgTransposer_constructor(xgTransposer,xcgLinalg,xcgColsRows,nspinor,&
258 : 4 : STATE_LINALG,TRANS_ALL2ALL,xmpi_comm_null,xmpi_comm_null,ncpuCols,ncpuRows,0)
259 : 4 : call xgTransposer_copyConstructor(xgTransposerGh,xgTransposer,xghLinalg,xghColsRows,STATE_LINALG)
260 : 4 : call xgTransposer_copyConstructor(xgTransposerGhc,xgTransposer,xghcLinalg,xghcColsRows,STATE_LINALG)
261 : :
262 : 4 : write(std_out,*) "Init data"
263 : 4 : call random_number(cg)
264 : 4 : call random_number(gh)
265 : : !call initVectors()
266 : :
267 : 4 : write(std_out,*) "Linalg division"
268 : 4 : call xgBlock_colwiseDivision(xcgLinalg,xghLinalg,xghcLinalg)
269 : :
270 : 4 : write(std_out,*) "Linalg norm2"
271 : 4 : call xg_init(dotLinalg,SPACE_R,nband,1,xmpi_world)
272 : 4 : call xgBlock_colwiseNorm2(xghcLinalg,dotLinalg%self)
273 : : !call xgBlock_print(dotLinalg%self,std_out)
274 : :
275 : 4 : write(std_out,*) "Transposer transpose"
276 : 4 : call xgTransposer_transpose(xgTransposer,STATE_COLSROWS)
277 : 4 : call xgTransposer_transpose(xgTransposerGh,STATE_COLSROWS)
278 : 4 : call xgTransposer_transpose(xgTransposerGhc,STATE_COLSROWS)
279 : :
280 : 4 : write(std_out,*) "ColsRows divisions"
281 : 4 : call xgBlock_colwiseDivision(xcgColsRows,xghColsRows,xghcColsRows)
282 : :
283 : 4 : write(std_out,*) "Transposer transpose back"
284 : 4 : call xgTransposer_transpose(xgTransposerGhc,STATE_LINALG)
285 : :
286 : 4 : write(std_out,*) "ColsRows norm2"
287 : 4 : call xg_init(dotColsRows,SPACE_R,nband,1,xmpi_world)
288 : 4 : call xgBlock_colwiseNorm2(xghcLinalg,dotColsRows%self)
289 : : !call xgBlock_print(dotColsRows%self,std_out)
290 : :
291 : 4 : write(std_out,*) "Compare"
292 : 4 : call xgBlock_saxpy(dotLinalg%self, -1.0d0, dotColsRows%self)
293 : 4 : call xgBlock_reshape(dotLinalg%self,1,nband)
294 : 4 : call xgBlock_colwiseNorm2(dotLinalg%self,dotColsRows%self,max_val=maxdiff)
295 : 4 : write(std_out,"(a,f20.4)") " Difference: ",sqrt(maxdiff)
296 : :
297 : 4 : write(std_out,*) "Free everything"
298 : 4 : call xg_free(dotLinalg)
299 : 4 : call xg_free(dotColsRows)
300 : :
301 : 4 : call xgTransposer_free(xgTransposer)
302 : 4 : call xgTransposer_free(xgTransposerGh)
303 : 4 : call xgTransposer_free(xgTransposerGhc)
304 : :
305 [ - + ]: 4 : ABI_FREE(cg)
306 [ - + ]: 4 : ABI_FREE(gh)
307 [ - + ]: 4 : ABI_FREE(ghc)
308 : :
309 [ - + - + ]: 12 : end subroutine test2
310 : : !!***
311 : :
312 : : !!****f* testTransposer/initVectors
313 : : !!
314 : : !! NAME
315 : : !! initVectors
316 : : !!
317 : : !! FUNCTION
318 : : !!
319 : : !! INPUTS
320 : : !! (main routine)
321 : : !!
322 : : !! OUTPUT
323 : : !! (main routine)
324 : : !!
325 : : !! SOURCE
326 : :
327 : : subroutine initVectors()
328 : : integer, allocatable :: seed(:)
329 : : integer :: n, iseed
330 : : integer :: icol, irow
331 : :
332 : : call random_seed(size=n)
333 : : ABI_MALLOC(seed,(n))
334 : : do icol = 1, nband
335 : : do iseed = 1, n
336 : : seed(iseed) = (xmpi_comm_rank(xmpi_world)*nband+icol)*n+iseed
337 : : end do
338 : : call random_seed(put=seed)
339 : : do irow = 1, npw
340 : : call random_number(cg(:,(icol-1)*npw+1:icol*npw))
341 : : call random_number(gh(:,(icol-1)*npw+1:icol*npw))
342 : : end do
343 : : end do
344 : : ABI_FREE(seed)
345 : : end subroutine initVectors
346 : : !!***
347 : :
348 : : !!****f* testTransposer/backAndForth
349 : : !!
350 : : !! NAME
351 : : !! backAndForth
352 : : !!
353 : : !! FUNCTION
354 : : !!
355 : : !! INPUTS
356 : : !! (main routine)
357 : : !!
358 : : !! OUTPUT
359 : : !! (main routine)
360 : : !!
361 : : !! SOURCE
362 : :
363 : 16 : subroutine backAndForth()
364 : :
365 : 16 : maxt = 0
366 : 16 : cputime = 0
367 [ + + ]: 336 : do i=1,ncycle
368 : 320 : walltime = abi_wtime()
369 : 320 : call xgTransposer_transpose(xgTransposer,STATE_COLSROWS)
370 [ - + ]: 320 : if ( ncpucols > 1 ) then ! for 1 both states are aliased !!
371 : 0 : call random_number(cg)
372 : : end if
373 : : !call xgBlock_scale(xcgLinalg,0.d0,1)
374 : : !call xgBlock_print(xgeigen,6)
375 : 320 : call xgTransposer_transpose(xgTransposer,STATE_LINALG)
376 : : !call xgBlock_print(xgx0,6)
377 : 320 : call xmpi_barrier(xmpi_world)
378 : 320 : walltime = abi_wtime() - walltime
379 : 320 : cputime = cputime + walltime
380 : 336 : call xmpi_max(walltime,maxt,xmpi_world,ierr)
381 : : end do
382 : 16 : call xmpi_max(cputime,maxt,xmpi_world,ierr)
383 : 16 : write(std_out,"(a,f20.5)") "-Mean time: ", maxt/ncycle
384 [ + + + + ]: 384000016 : errmax = (sum(abs(cg0-cg)))/nband
385 : 16 : call xmpi_sum(errmax,xmpi_world,ierr)
386 : 16 : write(std_out,"(a,f20.14)") " Difference: ",errmax
387 : 16 : call xmpi_barrier(xmpi_world)
388 : 16 : end subroutine backAndForth
389 : : !!***
390 : :
391 : : !!****f* testTransposer/printTimes
392 : : !!
393 : : !! NAME
394 : : !! printTimes
395 : : !!
396 : : !! FUNCTION
397 : : !!
398 : : !! INPUTS
399 : : !! (main routine)
400 : : !!
401 : : !! OUTPUT
402 : : !! (main routine)
403 : : !!
404 : : !! SOURCE
405 : :
406 : 16 : subroutine printTimes()
407 : :
408 : : double precision :: total(2)
409 : : integer :: ntot
410 : 16 : write(std_out,'(1x,a30,a8,a17,a17)') "counter", "calls", "cpu_time", "wall_time"
411 : 16 : ntot = 0
412 : 16 : total(:) = 0.d0
413 [ + + ]: 144 : do i=1662,1669
414 : 128 : call time_accu(i,ncount,times,nflops,ftimes)
415 : 128 : total(1) = total(1) + times(1)
416 : 128 : total(2) = total(2) + times(2)
417 : 128 : ntot = ntot + ncount
418 [ + - ]: 144 : write(std_out,'(a,a30,i8,2F17.3)') "-",trim(names(i-1661)), ncount, times(1), times(2)
419 : : end do
420 : 16 : write(std_out,'(a,a30,i8,2F17.3)') "-","total", ntot, total(1), total(2)
421 : 16 : call timab(1,0,times)
422 : :
423 : 16 : end subroutine printTimes
424 : :
425 : :
426 : : end program testTransposer
427 : : !!***
|