Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
AlephCudaMatrix.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*
8 * CNC: Concurrent Number Cruncher
9 * Copyright (C) 2008 GOCAD/ASGA, INRIA/ALICE
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 * If you modify this software, you should include a notice giving the
26 * name of the person performing the modification, the date of modification,
27 * and the reason for such modification.
28 *
29 * Contact: Luc Buatois
30 *
31 * buatois@gocad.org
32 *
33 * ASGA-INPL Bt. G
34 * Rue du Doyen Marcel Roubault - BP 40
35 * 54501 VANDOEUVRE LES NANCY
36 * FRANCE
37 *
38 * Note that the GNU General Public License does not permit incorporating
39 * the Software into proprietary programs.
40 */
41
42#include "arcane/aleph/AlephArcane.h"
43#include "arcane/aleph/cuda/AlephCuda.h"
44
45
46
47ARCANE_BEGIN_NAMESPACE
48
49//---------------------------------------------------------------------------//
50
51CNC_Matrix::CNC_Matrix(long m, long n, Storage storage) {
52 storage_ = NONE ;
53 allocate(m,n,storage,false) ;
54}
55
56//---------------------------------------------------------------------------//
57
58CNC_Matrix::CNC_Matrix(long n, Storage storage, bool symmetric_storage) {
59 storage_ = NONE ;
60 allocate(n,n,storage,symmetric_storage) ;
61}
62
63//---------------------------------------------------------------------------//
64
65CNC_Matrix::CNC_Matrix( long n ) {
66 m_ = 0 ;
67 n_ = 0 ;
68 diag_size_ = 0 ;
69
70 row_ = NULL ;
71 column_ = NULL ;
72 diag_ = NULL ;
73
74 storage_ = ROWS ;
75 allocate(n,n,storage_,false) ;
76}
77
78//---------------------------------------------------------------------------//
79
80CNC_Matrix::~CNC_Matrix() {
81 deallocate() ;
82}
83
84//---------------------------------------------------------------------------//
85
86CNC_Matrix::CNC_Matrix() {
87 m_ = 0 ;
88 n_ = 0 ;
89 diag_size_ = 0 ;
90
91 row_ = NULL ;
92 column_ = NULL ;
93 diag_ = NULL ;
94
95 storage_ = NONE ;
96 rows_are_stored_ = false ;
97 columns_are_stored_ = false ;
98 symmetric_storage_ = false ;
99 symmetric_tag_ = false ;
100}
101
102//---------------------------------------------------------------------------//
103
104long CNC_Matrix::m() const {return m_ ; }
105
106long CNC_Matrix::n() const {return n_ ; }
107
108long CNC_Matrix::diag_size() const {return diag_size_ ;}
109
110
111long CNC_Matrix::nnz() const {
112 long result = 0 ;
113 if(rows_are_stored()) {
114 for(long i=0; i<m(); i++) {
115 result += row(i).nb_coeffs() ;
116 }
117 } else if(columns_are_stored()) {
118 for(long j=0; j<n(); j++) {
119 result += column(j).nb_coeffs() ;
120 }
121 } else {
122 }
123 return result ;
124}
125
126
127bool CNC_Matrix::rows_are_stored() const {
128 return rows_are_stored_ ;
129 }
130
131bool CNC_Matrix::columns_are_stored() const {
132 return columns_are_stored_ ;
133 }
134
135CNC_Matrix::Storage CNC_Matrix::storage() const {
136 return storage_ ;
137 }
138
139bool CNC_Matrix::has_symmetric_storage() const {
140 return symmetric_storage_ ;
141 }
142
143bool CNC_Matrix::is_square() const {
144 return (m_ == n_) ;
145 }
146
147bool CNC_Matrix::is_symmetric() const {
148 return (symmetric_storage_ || symmetric_tag_) ;
149 }
150
155void CNC_Matrix::set_symmetric_tag(bool x) {
156 symmetric_tag_ = x ;
157 }
158
163CNCSparseRowColumn& CNC_Matrix::row(long i) {
164 return row_[i] ;
165 }
166
171const CNCSparseRowColumn& CNC_Matrix::row(long i) const {
172 return row_[i] ;
173 }
174
179CNCSparseRowColumn& CNC_Matrix::column(long j) {
180 return column_[j] ;
181 }
182
187const CNCSparseRowColumn& CNC_Matrix::column(long j) const {
188 return column_[j] ;
189 }
190
194double CNC_Matrix::diag(long i) const {
195 return diag_[i] ;
196}
197
201void CNC_Matrix::add(long i, long j, double val) {
202 if(symmetric_storage_ && j > i) {
203 return ;
204 }
205 if(i == j) {
206 diag_[i] += val ;
207 }
208 if(rows_are_stored_) {
209 row(i).add(j, val) ;
210 }
211 if(columns_are_stored_) {
212 column(j).add(i, val) ;
213 }
214}
215
216//---------------------------------------------------------------------------//
217
218void CNC_Matrix::sort() {
219 if(rows_are_stored_) {
220 for(long i=0; i<m_; i++) {
221 row(i).sort() ;
222 }
223 }
224 if(columns_are_stored_) {
225 for(long j=0; j<n_; j++) {
226 column(j).sort() ;
227 }
228 }
229}
230
231//---------------------------------------------------------------------------//
232
233void CNC_Matrix::zero() {
234 if(rows_are_stored_) {
235 for(long i=0; i<m_; i++) {
236 row(i).zero() ;
237 }
238 }
239 if(columns_are_stored_) {
240 for(long j=0; j<n_; j++) {
241 column(j).zero() ;
242 }
243 }
244 for(long i=0; i<diag_size_; i++) {
245 diag_[i] = 0.0 ;
246 }
247}
248
249//---------------------------------------------------------------------------//
250
251void CNC_Matrix::clear() {
252 if(rows_are_stored_) {
253 for(long i=0; i<m_; i++) {
254 row(i).clear() ;
255 }
256 }
257 if(columns_are_stored_) {
258 for(long j=0; j<n_; j++) {
259 column(j).clear() ;
260 }
261 }
262 for(long i=0; i<diag_size_; i++) {
263 diag_[i] = 0.0 ;
264 }
265}
266
267//---------------------------------------------------------------------------//
268
269void CNC_Matrix::deallocate() {
270 m_ = 0 ;
271 n_ = 0 ;
272 diag_size_ = 0 ;
273
274 if ( row_ != NULL ) delete[] row_ ;
275 if ( column_ != NULL ) delete[] column_ ;
276 if ( diag_ != NULL ) delete[] diag_ ;
277 row_ = NULL ;
278 column_ = NULL ;
279 diag_ = NULL ;
280
281 storage_ = NONE ;
282 rows_are_stored_ = false ;
283 columns_are_stored_ = false ;
284 symmetric_storage_ = false ;
285}
286
287//---------------------------------------------------------------------------//
288
289void CNC_Matrix::allocate(long m, long n, Storage storage, bool symmetric_storage){
290 m_ = m ;
291 n_ = n ;
292 diag_size_ = (m<n)?(m):(n) ;
293 symmetric_storage_ = symmetric_storage ;
294 symmetric_tag_ = false ;
295 storage_ = storage ;
296 switch(storage) {
297 case NONE:
298 break ;
299 case ROWS:
300 rows_are_stored_ = true ;
301 columns_are_stored_ = false ;
302 break ;
303 case COLUMNS:
304 rows_are_stored_ = false ;
305 columns_are_stored_ = true ;
306 break ;
307 case ROWS_AND_COLUMNS:
308 rows_are_stored_ = true ;
309 columns_are_stored_ = true ;
310 break ;
311 }
312 diag_ = new double[diag_size_] ;
313 for(long i=0; i<diag_size_; i++) {
314 diag_[i] = 0.0 ;
315 }
316
317 if(rows_are_stored_) {
318 row_ = new CNCSparseRowColumn[m] ;
319 } else {
320 row_ = NULL ;
321 }
322
323 if(columns_are_stored_) {
324 column_ = new CNCSparseRowColumn[n] ;
325 } else {
326 column_ = NULL ;
327 }
328}
329
330
331
332ARCANE_END_NAMESPACE
333
334
335//---------------------------------------------------------------------------//
336//---------------------------------------------------------------------------//
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120