SpM Handbook 1.2.4
Loading...
Searching...
No Matches
spm_update_compute_fields.c
Go to the documentation of this file.
1/**
2 *
3 * @file spm_update_compute_fields.c
4 *
5 * SPM routine to update the computed fields in the data structure.
6 *
7 * @copyright 2016-2024 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8 * Univ. Bordeaux. All rights reserved.
9 *
10 * @version 1.2.4
11 * @author Pierre Ramet
12 * @author Mathieu Faverge
13 * @author Tony Delarue
14 * @author Alycia Lisito
15 * @date 2024-06-25
16 *
17 * @ingroup spm_dev_check
18 * @{
19 **/
20#include "common.h"
21
22/**
23 *******************************************************************************
24 *
25 * @brief Compute the expended field for variadic dof in the shared memory case.
26 *
27 *******************************************************************************
28 *
29 * @param[inout] spm
30 * The sparse matrix for which nexp and nnzexp must be computed.
31 *
32 *******************************************************************************/
33static inline void
35{
36 spm_int_t i, j, k, dofi, dofj;
37 spm_int_t *dofptr, *colptr, *rowptr;
38 spm_int_t baseval;
39
40 colptr = spm->colptr;
41 rowptr = spm->rowptr;
42 dofptr = spm->dofs;
43 baseval = spm->baseval;
44
45 assert( dofptr != NULL );
46 assert( spm->replicated );
47 assert( spm->loc2glob == NULL );
48
49 spm->nexp = dofptr[ spm->n ] - baseval;
50
51 spm->nnzexp = 0;
52 switch(spm->fmttype)
53 {
54 case SpmCSR:
55 /* Swap pointers to call CSC */
56 colptr = spm->rowptr;
57 rowptr = spm->colptr;
58
59 spm_attr_fallthrough;
60
61 case SpmCSC:
62 for(j=0; j<spm->n; j++, colptr++) {
63 dofj = dofptr[j+1] - dofptr[j];
64
65 for(k=colptr[0]; k<colptr[1]; k++, rowptr++) {
66 i = *rowptr - baseval;
67 dofi = dofptr[i+1] - dofptr[i];
68
69 spm->nnzexp += dofi * dofj;
70 }
71 }
72 break;
73 case SpmIJV:
74 for(k=0; k<spm->nnz; k++, rowptr++, colptr++)
75 {
76 i = *rowptr - baseval;
77 j = *colptr - baseval;
78 dofi = dofptr[i+1] - dofptr[i];
79 dofj = dofptr[j+1] - dofptr[j];
80
81 spm->nnzexp += dofi * dofj;
82 }
83 }
84}
85
86/**
87 *******************************************************************************
88 *
89 * @brief Compute the expended field for variadic dof in the distributed case for CSC/CSR formats
90 *
91 *******************************************************************************
92 *
93 * @param[inout] spm
94 * The sparse matrix for which nexp and nnzexp must be computed.
95 *
96 * @param[in] colptr
97 * The colptr/rowptr array to adapt to the CSC computations
98 *
99 * @param[in] rowptr
100 * The rowptr/colptr array to adapt to the CSC computations
101 *
102 *******************************************************************************/
103static inline void
105 const spm_int_t *colptr,
106 const spm_int_t *rowptr )
107{
108 spm_int_t ig, jl, jg, k, dofi, dofj, nnz;
109 spm_int_t *dofptr, *loc2glob;
110
111 dofptr = spm->dofs - spm->baseval;
112 loc2glob = spm->loc2glob;
113
114 spm->nexp = 0;
115 spm->nnzexp = 0;
116
117 for(jl=0; jl<spm->n; jl++, colptr++, loc2glob++) {
118 jg = *loc2glob;
119 dofj = dofptr[jg+1] - dofptr[jg];
120
121 spm->nexp += dofj;
122
123 nnz = 0;
124 for(k=colptr[0]; k<colptr[1]; k++, rowptr++) {
125 ig = *rowptr;
126 dofi = dofptr[ig+1] - dofptr[ig];
127
128 nnz += dofi;
129 }
130
131 spm->nnzexp += dofj * nnz;
132 }
133}
134
135/**
136 *******************************************************************************
137 *
138 * @brief Compute the expended field for variadic dof in the distributed case for IJV format
139 *
140 *******************************************************************************
141 *
142 * @param[inout] spm
143 * The sparse matrix for which nexp and nnzexp must be computed.
144 *
145 *******************************************************************************/
146static inline void
148{
149 spm_int_t ig, jg, k, dofi, dofj;
150 const spm_int_t *dofptr, *colptr, *rowptr, *loc2glob;
151
152 colptr = spm->colptr;
153 rowptr = spm->rowptr;
154 dofptr = spm->dofs - spm->baseval;
155 loc2glob = spm->loc2glob;
156
157 assert( spm->dofs != NULL );
158
159 spm->nnzexp = 0;
160 for(k=0; k<spm->nnz; k++, rowptr++, colptr++)
161 {
162 ig = *rowptr;
163 jg = *colptr;
164 dofi = dofptr[ig+1] - dofptr[ig];
165 dofj = dofptr[jg+1] - dofptr[jg];
166
167 spm->nnzexp += dofi * dofj;
168 }
169
170 spm->nexp = 0;
171 for(k=0; k<spm->n; k++, loc2glob++)
172 {
173 ig = *loc2glob;
174 spm->nexp += dofptr[ig+1] - dofptr[ig];
175 }
176}
177
178/**
179 *******************************************************************************
180 *
181 * @brief Compute the expended field for variadic dof in the distributed case
182 *
183 *******************************************************************************
184 *
185 * @param[inout] spm
186 * The sparse matrix for which nexp and nnzexp must be computed.
187 *
188 *******************************************************************************/
189static inline void
191{
192 assert( spm->dofs != NULL );
193 assert( spm->loc2glob != NULL );
194
195 spm->nexp = 0;
196 spm->nnzexp = 0;
197 switch(spm->fmttype)
198 {
199 case SpmCSR:
200 spm_ucf_variadic_mpi_csx( spm, spm->rowptr, spm->colptr );
201 break;
202
203 case SpmCSC:
204 spm_ucf_variadic_mpi_csx( spm, spm->colptr, spm->rowptr );
205 break;
206
207 case SpmIJV:
209 }
210}
211/**
212 * @}
213 */
214
215/**
216 *******************************************************************************
217 *
218 * @ingroup spm
219 * @brief Update all the computed fields based on the static values stored.
220 *
221 *******************************************************************************
222 *
223 * @param[inout] spm
224 * The sparse matrix to update.
225 *
226 *******************************************************************************/
227void
229{
230 if ( spm->dof > 0 ) {
231 /*
232 * Compute the local expended field for constant multi-dofs
233 */
234 spm->nexp = spm->n * spm->dof;
235 spm->nnzexp = spm->nnz * spm->dof * spm->dof;
236 }
237 else {
238 /*
239 * Compute the local expended field for variadic multi-dofs
240 */
241 if ( spm->replicated ) {
243 }
244 else {
246 }
247 }
248
249#if defined(SPM_WITH_MPI)
250 if ( !spm->replicated && (spm->clustnbr > 1) ) {
251 MPI_Allreduce( &(spm->n), &(spm->gN), 1, SPM_MPI_INT, MPI_SUM, spm->comm );
252 MPI_Allreduce( &(spm->nnz), &(spm->gnnz), 1, SPM_MPI_INT, MPI_SUM, spm->comm );
253 MPI_Allreduce( &(spm->nexp), &(spm->gNexp), 1, SPM_MPI_INT, MPI_SUM, spm->comm );
254 MPI_Allreduce( &(spm->nnzexp), &(spm->gnnzexp), 1, SPM_MPI_INT, MPI_SUM, spm->comm );
255 }
256 else
257#endif
258 {
259 spm->gN = spm->n;
260 spm->gnnz = spm->nnz;
261 spm->gNexp = spm->nexp;
262 spm->gnnzexp = spm->nnzexp;
263 }
264}
@ SpmCSC
Definition const.h:73
@ SpmCSR
Definition const.h:74
@ SpmIJV
Definition const.h:75
spm_int_t * dofs
Definition spm.h:85
spm_int_t nexp
Definition spm.h:78
int clustnbr
Definition spm.h:96
spm_int_t nnz
Definition spm.h:75
spm_int_t nnzexp
Definition spm.h:80
spm_int_t * rowptr
Definition spm.h:90
spm_int_t gnnz
Definition spm.h:74
spm_fmttype_t fmttype
Definition spm.h:69
spm_int_t dof
Definition spm.h:82
spm_int_t n
Definition spm.h:73
spm_int_t * loc2glob
Definition spm.h:91
SPM_Comm comm
Definition spm.h:97
spm_int_t baseval
Definition spm.h:71
spm_int_t gnnzexp
Definition spm.h:79
spm_int_t * colptr
Definition spm.h:89
spm_int_t gNexp
Definition spm.h:77
spm_int_t gN
Definition spm.h:72
int replicated
Definition spm.h:98
#define SPM_MPI_INT
The MPI type associated to spm_int_t.
Definition datatypes.h:72
void spmUpdateComputedFields(spmatrix_t *spm)
Update all the computed fields based on the static values stored.
int spm_int_t
The main integer datatype used in spm arrays.
Definition datatypes.h:70
The sparse matrix data structure.
Definition spm.h:64
static void spm_ucf_variadic_mpi_ijv(spmatrix_t *spm)
Compute the expended field for variadic dof in the distributed case for IJV format.
static void spm_ucf_variadic_mpi_csx(spmatrix_t *spm, const spm_int_t *colptr, const spm_int_t *rowptr)
Compute the expended field for variadic dof in the distributed case for CSC/CSR formats.
static void spm_ucf_variadic_mpi(spmatrix_t *spm)
Compute the expended field for variadic dof in the distributed case.
static void spm_ucf_variadic_shm(spmatrix_t *spm)
Compute the expended field for variadic dof in the shared memory case.