]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix PETScWrappers::MatrixBase::set for 64bit indices and complex scalar type
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 26 Apr 2017 22:42:58 +0000 (00:42 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Thu, 27 Apr 2017 12:38:16 +0000 (14:38 +0200)
include/deal.II/lac/petsc_matrix_base.h

index 5cbcfb16c13d354e3dad2a1dfb9f7f810e5b3747..a1f25a63cba6ab3903d2a40991ede1343dc21236 100644 (file)
@@ -1208,26 +1208,32 @@ namespace PETScWrappers
                    const PetscScalar  *values,
                    const bool         elide_zero_values)
   {
-    (void)elide_zero_values;
-
     prepare_action(VectorOperation::insert);
 
     const PetscInt petsc_i = row;
-    PetscInt *col_index_ptr;
+    PetscInt const *col_index_ptr;
 
     PetscScalar const *col_value_ptr;
     int n_columns;
 
     // If we don't elide zeros, the pointers are already available...
-#ifndef PETSC_USE_64BIT_INDICES
     if (elide_zero_values == false)
       {
-        col_index_ptr = (int *)col_indices;
+#ifndef PETSC_USE_64BIT_INDICES
+        col_index_ptr = reinterpret_cast<const PetscInt *>(col_indices);
+#else
+        if (column_indices.size() < n_cols)
+          column_indices.resize(n_cols);
+
+        for (size_type j=0; j<n_cols; ++j)
+          column_indices[j] = col_indices[j];
+
+        col_index_ptr = &column_indices[0];
+#endif
         col_value_ptr = values;
         n_columns = n_cols;
       }
     else
-#endif
       {
         // Otherwise, extract nonzero values in each row and get the
         // respective index.
@@ -1355,21 +1361,29 @@ namespace PETScWrappers
     prepare_action(VectorOperation::add);
 
     const PetscInt petsc_i = row;
-    PetscInt *col_index_ptr;
+    PetscInt const *col_index_ptr;
 
     PetscScalar const *col_value_ptr;
     int n_columns;
 
     // If we don't elide zeros, the pointers are already available...
-#ifndef PETSC_USE_64BIT_INDICES
     if (elide_zero_values == false)
       {
-        col_index_ptr = (int *)col_indices;
+#ifndef PETSC_USE_64BIT_INDICES
+        col_index_ptr = reinterpret_cast<const PetscInt *>(col_indices);
+#else
+        if (column_indices.size() < n_cols)
+          column_indices.resize(n_cols);
+
+        for (size_type j=0; j<n_cols; ++j)
+          column_indices[j] = col_indices[j];
+
+        col_index_ptr = &column_indices[0];
+#endif
         col_value_ptr = values;
         n_columns = n_cols;
       }
     else
-#endif
       {
         // Otherwise, extract nonzero values in each row and get the
         // respective index.

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.