@@ -68,9 +68,11 @@ CSysMatrix<ScalarType>::~CSysMatrix() {
6868 MemoryAllocation::aligned_free (matrix);
6969 MemoryAllocation::aligned_free (invM);
7070
71- GPUMemoryAllocation::gpu_free (d_matrix);
72- GPUMemoryAllocation::gpu_free (d_row_ptr);
73- GPUMemoryAllocation::gpu_free (d_col_ind);
71+ if (useCuda) {
72+ GPUMemoryAllocation::gpu_free (d_matrix);
73+ GPUMemoryAllocation::gpu_free (d_row_ptr);
74+ GPUMemoryAllocation::gpu_free (d_col_ind);
75+ }
7476
7577#ifdef USE_MKL
7678 mkl_jit_destroy (MatrixMatrixProductJitter);
@@ -142,19 +144,23 @@ void CSysMatrix<ScalarType>::Initialize(unsigned long npoint, unsigned long npoi
142144
143145 allocAndInit (matrix, nnz * nVar * nEqn);
144146
145- auto GPUAllocAndInit = [](ScalarType*& ptr, unsigned long num) {
146- ptr = GPUMemoryAllocation::gpu_alloc<ScalarType, true >(num * sizeof (ScalarType));
147- };
147+ useCuda = config->GetCUDA ();
148148
149- auto GPUAllocAndCopy = [](const unsigned long *& ptr, const unsigned long *& src_ptr, unsigned long num) {
150- ptr = GPUMemoryAllocation::gpu_alloc_cpy<const unsigned long >(src_ptr, num * sizeof (const unsigned long ));
151- };
149+ if (useCuda) {
150+ /* --- Allocate GPU data. ---*/
151+ auto GPUAllocAndInit = [](ScalarType*& ptr, unsigned long num) {
152+ ptr = GPUMemoryAllocation::gpu_alloc<ScalarType, true >(num * sizeof (ScalarType));
153+ };
154+
155+ auto GPUAllocAndCopy = [](const unsigned long *& ptr, const unsigned long *& src_ptr, unsigned long num) {
156+ ptr = GPUMemoryAllocation::gpu_alloc_cpy<const unsigned long >(src_ptr, num * sizeof (const unsigned long ));
157+ };
158+
159+ GPUAllocAndInit (d_matrix, nnz * nVar * nEqn);
160+ GPUAllocAndCopy (d_row_ptr, row_ptr, (nPointDomain + 1.0 ));
161+ GPUAllocAndCopy (d_col_ind, col_ind, nnz);
162+ }
152163
153- GPUAllocAndInit (d_matrix, nnz * nVar * nEqn);
154- GPUAllocAndCopy (d_row_ptr, row_ptr, (nPointDomain + 1.0 ));
155- GPUAllocAndCopy (d_col_ind, col_ind, nnz);
156- GPUAllocAndCopy (d_dia_ptr, dia_ptr, nPointDomain);
157-
158164 if (needTranspPtr) col_ptr = geometry->GetTransposeSparsePatternMap (type).data ();
159165
160166 if (type == ConnectivityType::FiniteVolume) {
0 commit comments