SpM Handbook 1.2.4
Loading...
Searching...
No Matches
spmf_rebalance.F90
Go to the documentation of this file.
1!>
2!> @file spmf_rebalance.F90
3!>
4!> @brief Fortran 90 internal testing to check gather/Scatter fortran
5!> interface.
6!>
7!> It basically gather a non balanced distributed spm, and
8!> re-distribute it in a balanced way.
9!>
10!> @copyright 2017-2024 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
11!> Univ. Bordeaux. All rights reserved.
12!>
13!> @version 1.2.4
14!> @author Mathieu Faverge
15!> @author Alycia Lisito
16!> @date 2024-05-29
17!>
18!> @ingroup examples_fortran
19!>
20#ifndef DOXYGEN_SHOULD_SKIP_THIS
21program spmf_rebalance
22 use iso_c_binding
23 use spmf
24#if defined(SPM_WITH_MPI)
25 use mpi_f08
26#endif
27 implicit none
28
29 type(spmatrix_t), target :: spm
30 type(spmatrix_t), target :: spml
31 type(spmatrix_t), target :: spmg
32 integer(c_int) :: info
33 integer(spm_int_t) :: n
34 integer :: rank = 0
35 integer :: size = 1
36
37#if defined(SPM_WITH_MPI)
38 ! SPM is compiled with MPI, thus MPI must be initialized
39 ! before any spm call
40 call mpi_init( info )
41 call mpi_comm_rank( mpi_comm_world, rank )
42 call mpi_comm_size( mpi_comm_world, size )
43#endif
44
45 !
46 ! Initialize the problem
47 ! 1- The matrix
48 call spmreaddriverdist( spmdriverlaplacian, "d:10:10:10:4.", spm, mpi_comm_world, info )
49 call spmprintinfo( spm )
50
51 n = spm%gN / size
52
53 if ( rank .eq. 0 ) then
54 call spmgather( spm, 0, spmg )
55 call spmprintinfo( spmg )
56 else
57 call spmgather( spm, 0 )
58 end if
59
60 call spmexit( spm )
61
62 if ( rank .eq. 0 ) then
63 n = n + mod( spm%gN, size )
64 call spmscatter( spml, 0, spmg )
65 call spmexit( spmg )
66 else
67 call spmscatter( spml, 0 )
68 end if
69
70 call spmprintinfo( spml )
71 call spmexit( spml )
72
73#if defined(SPM_WITH_MPI)
74 call mpi_finalize( info )
75#endif
76
77end program spmf_rebalance
78
79#endif