Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
IAlephCuda.h
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/* IAlephCnc.h (C) 2000-2012 */
9/* */
10/*---------------------------------------------------------------------------*/
11/*---------------------------------------------------------------------------*/
12#ifndef _ALEPH_INTERFACE_CNC_H_
13#define _ALEPH_INTERFACE_CNC_H_
14
15#include "arcane/aleph/cuda/AlephCuda.h"
16
17#include <cuda.h>
18#include <cublas.h>
19#include <cuda_runtime.h>
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24ARCANE_BEGIN_NAMESPACE
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29
30/******************************************************************************
31 * AlephVectorCnc
32 *****************************************************************************/
34public:
36 AlephKernel *kernel,
37 Integer index):IAlephVector(tm,kernel,index),
38 m_cnc_vector(0){
39 debug()<<"\t\t[AlephVectorCnc::AlephVectorCnc] new AlephVectorCnc";
40}
41
42/******************************************************************************
43 *****************************************************************************/
44void AlephVectorCreate(void){
45 debug()<<"\t\t[AlephVectorCnc::AlephVectorCreate] CNC VectorCreate 0-"<<m_kernel->topology()->nb_row_size()-1;
46 m_cnc_vector.allocate(m_kernel->topology()->nb_row_size());
47 debug()<<"\t\t[AlephVectorCnc::AlephVectorCreate] done";
48}
49
50/******************************************************************************
51 *****************************************************************************/
52void AlephVectorSet(const double *bfr_val, const int *bfr_idx, Integer size){
53 debug()<<"\t\t[AlephVectorCnc::AlephVectorSet]";
54 for(Integer i=0; i<size; ++i) {
55 m_cnc_vector[bfr_idx[i]] = bfr_val[i];
56 }
57}
58
59/******************************************************************************
60 *****************************************************************************/
61int AlephVectorAssemble(void){
62 return 0;
63}
64
65/******************************************************************************
66 *****************************************************************************/
67void AlephVectorGet(double *bfr_val, const int *bfr_idx, Integer size){
68 debug()<<"\t\t[AlephVectorCnc::AlephVectorGet]";
69 for(Integer i=0; i<size; ++i) {
70 bfr_val[i]=m_cnc_vector[bfr_idx[i]];
71 }
72}
73
74/******************************************************************************
75 *****************************************************************************/
76void writeToFile(const String filename){
77 debug()<<"\t\t[AlephVectorCnc::writeToFile]";
78 m_cnc_vector.print();
79}
80
81public:
82 CNC_Vector<double> m_cnc_vector;
83};
84
85
86/******************************************************************************
87 AlephMatrixCnc
88 *****************************************************************************/
90public:
91
92
93/******************************************************************************
94 AlephMatrixCnc
95*****************************************************************************/
97 AlephKernel *kernel,
98 Integer index):IAlephMatrix(tm,kernel,index),
99 m_cnc_matrix(0),
100 m_cuda(),
101 m_smcrs(),
102 has_been_allocated_on_gpu(false){
103 debug()<<"\t\t[AlephMatrixCnc::AlephMatrixCnc] new SolverMatrixCnc";
104}
105
106
107/******************************************************************************
108 * ~AlephMatrixCnc
109 *****************************************************************************/
111 debug()<<"\t\t[AlephMatrixCnc::~AlephMatrixCnc] DELETE SolverMatrixCnc";
112 m_smcrs.gpu_deallocate();
113}
114
115
116/******************************************************************************
117 *****************************************************************************/
118void AlephMatrixCreate(void){
119 debug()<<"\t\t[AlephMatrixCnc::AlephMatrixCreate] CNC MatrixCreate";
120 m_cnc_matrix.allocate(m_kernel->topology()->nb_row_size(),
121 m_kernel->topology()->nb_row_size(),
122 CNC_Matrix::ROWS,
123 false); // symmetric ?
124 m_cuda.cnc_cuda_set_dim_vec_from_n(m_kernel->topology()->nb_row_size());
125}
126
127/******************************************************************************
128 *****************************************************************************/
129void AlephMatrixSetFilled(bool){}
130
131/******************************************************************************
132 *****************************************************************************/
133int AlephMatrixAssemble(void){
134 debug()<<"\t\t[AlephMatrixCnc::AlephMatrixConfigure] AlephMatrixConfigure";
135 m_cuda.convert_matrix(m_cnc_matrix, m_smcrs, false);
136 if (has_been_allocated_on_gpu==false){
137 m_smcrs.gpu_allocate();
138 has_been_allocated_on_gpu=true;
139 }
140 return 0;
141}
142
143/******************************************************************************
144 *****************************************************************************/
145void AlephMatrixFill(int nrows, int *rows, int *cols, double *values){
146 debug()<<"\t\t[AlephMatrixCnc::AlephMatrixFill]";
147 for(int i=0,iMax=m_kernel->topology()->gathered_nb_setValued(m_kernel->rank());i<iMax;++i){
148 m_cnc_matrix.add(rows[i],
149 cols[i],
150 values[i]);
151 }
152 debug()<<"\t\t[AlephMatrixCnc::AlephMatrixFill] done";
153}
154
155 /******************************************************************************
156 * LinftyNormVectorProductAndSub
157 *****************************************************************************/
158 Real LinftyNormVectorProductAndSub(AlephVector* x,
159 AlephVector* b){
160 throw FatalErrorException("LinftyNormVectorProductAndSub", "error");
161 }
162
163
164/******************************************************************************
165 *****************************************************************************/
166int AlephMatrixSolve(AlephVector* x,
167 AlephVector* b,
168 AlephVector* t,
169 Integer& nb_iteration,
170 Real* residual_norm,
172 const String func_name("SolverMatrixCnc::solve");
173
174 debug()<<"\t\t[AlephMatrixCnc::AlephMatrixSolve] Getting X & B";
175 CNC_Vector<double> *X = &(dynamic_cast<AlephVectorCnc*> (x->implementation()))->m_cnc_vector;
176 CNC_Vector<double> *B = &(dynamic_cast<AlephVectorCnc*> (b->implementation()))->m_cnc_vector;
177
178 debug()<<"\t\t[AlephMatrixCnc::AlephMatrixSolve] Flushing X";
179 X->set_all(0.0f);
180
181 // résolution du système algébrique
182 unsigned int cnc_nb_iter_max = solver_param->maxIter();
183 double cnc_epsilon = solver_param->epsilon();
184
185 debug()<<"\t\t[AlephMatrixCnc::AlephMatrixSolve] Launching CNC_Solver";
186 m_cuda.solve(m_smcrs, *B, *X, cnc_nb_iter_max, cnc_epsilon, nb_iteration, residual_norm);
187
188/* debug()<<"\t\t[AlephMatrixCnc::AlephMatrixSolve] HARD-CODING arguments";
189 nb_iteration = cnc_nb_iter_max-1;
190 residual_norm[0] = cnc_epsilon;
191*/
192
193 if ( nb_iteration == solver_param->maxIter() && solver_param->stopErrorStrategy()){
194 info() << "\n============================================================";
195 info() << "\nCette erreur est retournée après " << nb_iteration << "\n";
196 info() << "\nOn a atteind le nombre max d'itérations du solveur.";
197 info() << "\nIl est possible de demander au code de ne pas tenir compte de cette erreur.";
198 info() << "\nVoir la documentation du jeu de données concernant le service solveur.";
199 info() << "\n======================================================";
200 throw Exception("AlephMatrixCnc::Solve", "On a atteind le nombre max d'itérations du solveur");
201 }
202 return 0;
203}
204
205/******************************************************************************
206 *****************************************************************************/
207void writeToFile(const String filename){
208 //CNC_MatrixPrint(m_cnc_matrix, filename.localstr());
209}
210
211public:
212 CNC_Matrix m_cnc_matrix;
213 Cuda m_cuda;
214 CNC_MatrixCRS<double> m_smcrs;
215 bool has_been_allocated_on_gpu;
216};
217
218/*---------------------------------------------------------------------------*/
219/*---------------------------------------------------------------------------*/
220
221ARCANE_END_NAMESPACE
222
223/*---------------------------------------------------------------------------*/
224/*---------------------------------------------------------------------------*/
225
226#endif // _ALEPH_INTERFACE_CNC_H_
Paramètres d'un système linéraire.
Definition AlephParams.h:34
Vecteur d'un système linéaire.
Definition AlephVector.h:33
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Classe de base d'une exception.
Exception lorsqu'une erreur fatale est survenue.
Interface du gestionnaire de traces.
Chaîne de caractères unicode.