* adding/inserting local data into
* the (large) sparse matrix.
*/
- std::vector<unsigned int> column_indices;
+#ifdef PETSC_USE_64BIT_INDICES
+ std::vector<PetscInt> column_indices;
+#else
+ std::vector<int> column_indices;
+#endif
/**
* An internal array of double values
{
prepare_action(LastAction::insert);
- const signed int petsc_i = row;
+#ifdef PETSC_USE_64BIT_INDICES
+ const PetscInt petsc_i = row;
+ PetscInt * col_index_ptr;
+#else
+ const int petsc_i = row;
int * col_index_ptr;
+#endif
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;
n_columns = n_cols;
}
else
+#endif
{
// Otherwise, extract nonzero values in
// each row and get the respective index.
}
Assert(n_columns <= (int)n_cols, ExcInternalError());
- col_index_ptr = (int*)&column_indices[0];
+ col_index_ptr = &column_indices[0];
col_value_ptr = &column_values[0];
}
{
prepare_action(LastAction::add);
- const signed int petsc_i = row;
+#ifdef PETSC_USE_64BIT_INDICES
+ const PetscInt petsc_i = row;
+ PetscInt * col_index_ptr;
+#else
+ const int petsc_i = row;
int * col_index_ptr;
+#endif
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;
n_columns = n_cols;
}
else
+#endif
{
// Otherwise, extract nonzero values in
// each row and get the respective index.
}
Assert(n_columns <= (int)n_cols, ExcInternalError());
- col_index_ptr = (int*)&column_indices[0];
+ col_index_ptr = &column_indices[0];
col_value_ptr = &column_values[0];
}
bool
MatrixBase::in_local_range (const unsigned int index) const
{
+#ifdef PETSC_USE_64BIT_INDICES
+ PetscInt begin, end;
+#else
int begin, end;
+#endif
const int ierr = MatGetOwnershipRange (static_cast<const Mat &>(matrix),
&begin, &end);
AssertThrow (ierr == 0, ExcPETScError(ierr));
* convergence has been reached.
*/
static
- int
+#ifdef PETSC_USE_64BIT_INDICES
+ PetscErrorCode
+#else
+ int
+#endif
convergence_test (KSP ksp,
+#ifdef PETSC_USE_64BIT_INDICES
+ const PetscInt iteration,
+#else
const int iteration,
+#endif
const PetscReal residual_norm,
KSPConvergedReason *reason,
void *solver_control);
AssertThrow (ierr == 0, ExcPETScError(ierr));
}
+#ifdef PETSC_USE_64BIT_INDICES
+ const PetscInt petsc_i = index;
+#else
const signed int petsc_i = index;
+#endif
const int ierr
= VecSetValues (vector, 1, &petsc_i, &value, INSERT_VALUES);
return *this;
// use the PETSc function to add something
+#ifdef PETSC_USE_64BIT_INDICES
+ const PetscInt petsc_i = index;
+#else
const signed int petsc_i = index;
+#endif
const int ierr
= VecSetValues (vector, 1, &petsc_i, &value, ADD_VALUES);
AssertThrow (ierr == 0, ExcPETScError(ierr));
return *this;
// use the PETSc function to add something
+#ifdef PETSC_USE_64BIT_INDICES
+ const PetscInt petsc_i = index;
+#else
const signed int petsc_i = index;
+#endif
const PetscScalar subtractand = -value;
const int ierr
= VecSetValues (vector, 1, &petsc_i, &subtractand, ADD_VALUES);
if (value == 1.)
return *this;
+#ifdef PETSC_USE_64BIT_INDICES
+ const PetscInt petsc_i = index;
+#else
const signed int petsc_i = index;
+#endif
const PetscScalar new_value
= static_cast<PetscScalar>(*this) * value;
if (value == 1.)
return *this;
+ #ifdef PETSC_USE_64BIT_INDICES
+ const PetscInt petsc_i = index;
+#else
const signed int petsc_i = index;
+#endif
const PetscScalar new_value
= static_cast<PetscScalar>(*this) / value;
bool
VectorBase::in_local_range (const unsigned int index) const
{
+#ifdef PETSC_USE_64BIT_INDICES
+ PetscInt begin, end;
+#else
int begin, end;
+#endif
+
const int ierr = VecGetOwnershipRange (static_cast<const Vec &>(vector),
&begin, &end);
AssertThrow (ierr == 0, ExcPETScError(ierr));
// get a representation of the present
// row
- int ncols;
-
#if (PETSC_VERSION_MAJOR <= 2) && \
((PETSC_VERSION_MINOR < 2) || \
((PETSC_VERSION_MINOR == 2) && (PETSC_VERSION_SUBMINOR == 0)))
+ int ncols;
int *colnums;
PetscScalar *values;
#else
- const int *colnums;
+ PetscInt ncols;
+ const PetscInt *colnums;
const PetscScalar *values;
#endif
MatrixBase::el (const unsigned int i,
const unsigned int j) const
{
- const signed int petsc_i = i;
- const signed int petsc_j = j;
+#ifdef PETSC_USE_64BIT_INDICES
+ PetscInt
+#else
+ int
+#endif
+ petsc_i = i, petsc_j = j;
PetscScalar value;
const int ierr
unsigned int
MatrixBase::m () const
{
- int n_rows, n_cols;
+#ifdef PETSC_USE_64BIT_INDICES
+ PetscInt
+#else
+ int
+#endif
+ n_rows, n_cols;
int ierr = MatGetSize (matrix, &n_rows, &n_cols);
AssertThrow (ierr == 0, ExcPETScError(ierr));
unsigned int
MatrixBase::n () const
{
- int n_rows, n_cols;
+#ifdef PETSC_USE_64BIT_INDICES
+ PetscInt
+#else
+ int
+#endif
+ n_rows, n_cols;
int ierr = MatGetSize (matrix, &n_rows, &n_cols);
AssertThrow (ierr == 0, ExcPETScError(ierr));
unsigned int
MatrixBase::local_size () const
{
- int n_rows, n_cols;
+#ifdef PETSC_USE_64BIT_INDICES
+ PetscInt
+#else
+ int
+#endif
+ n_rows, n_cols;
int ierr = MatGetLocalSize (matrix, &n_rows, &n_cols);
AssertThrow (ierr == 0, ExcPETScError(ierr));
std::pair<unsigned int, unsigned int>
MatrixBase::local_range () const
{
- int begin, end;
+#ifdef PETSC_USE_64BIT_INDICES
+ PetscInt
+#else
+ int
+#endif
+ begin, end;
const int ierr = MatGetOwnershipRange (static_cast<const Mat &>(matrix),
&begin, &end);
AssertThrow (ierr == 0, ExcPETScError(ierr));
// get a representation of the present
// row
- int ncols;
-
-#if (PETSC_VERSION_MAJOR <= 2) && \
+ #if (PETSC_VERSION_MAJOR <= 2) && \
((PETSC_VERSION_MINOR < 2) || \
((PETSC_VERSION_MINOR == 2) && (PETSC_VERSION_SUBMINOR == 0)))
+ int ncols;
int *colnums;
PetscScalar *values;
#else
- const int *colnums;
+ PetscInt ncols;
+ const PetscInt *colnums;
const PetscScalar *values;
#endif
// signed integers. so we have to
// convert, unless we want to play dirty
// tricks with conversions of pointers
+#ifdef PETSC_USE_64BIT_INDICES
+ const std::vector<PetscInt> int_row_lengths (row_lengths.begin(),
+ row_lengths.end());
+ PetscInt
+#else
const std::vector<signed int> int_row_lengths (row_lengths.begin(),
row_lengths.end());
+ int
+#endif
+ petsc_m = m, petsc_n = n;
//TODO: There must be a significantly better way to provide information about the off-diagonal blocks of the matrix. this way, petsc keeps allocating tiny chunks of memory, and gets completely hung up over this
+
const int ierr
= MatCreateMPIAIJ(communicator,
local_rows, local_columns,
// then count the elements in- and
// out-of-window for the rows we own
- std::vector<int> row_lengths_in_window (local_row_end - local_row_start);
- std::vector<int> row_lengths_out_of_window (local_row_end - local_row_start);
+#ifdef PETSC_USE_64BIT_INDICES
+ std::vector<PetscInt>
+#else
+ std::vector<int>
+#endif
+ row_lengths_in_window (local_row_end - local_row_start),
+ row_lengths_out_of_window (local_row_end - local_row_start);
for (unsigned int row = local_row_start; row<local_row_end; ++row)
for (unsigned int c=0; c<sparsity_pattern.row_length(row); ++c)
{
((PETSC_VERSION_MINOR < 2) || \
((PETSC_VERSION_MINOR == 2) && (PETSC_VERSION_SUBMINOR == 0)))
- std::vector<int> row_entries;
+#ifdef PETSC_USE_64BIT_INDICES
+ std::vector<PetscInt>
+#else
+ std::vector<int>
+#endif
+ row_entries;
std::vector<PetscScalar> row_values;
for (unsigned int i=0; i<sparsity_pattern.n_rows(); ++i)
{
// dummy entry at the end to make
// sure petsc doesn't read past the
// end
- std::vector<int> rowstart_in_window (local_row_end -
- local_row_start + 1,
- 0);
- std::vector<int> colnums_in_window;
+#ifdef PETSC_USE_64BIT_INDICES
+ std::vector<PetscInt>
+#else
+ std::vector<int>
+#endif
+ rowstart_in_window (local_row_end - local_row_start + 1, 0),
+ colnums_in_window;
{
unsigned int n_cols = 0;
for (unsigned int i=local_row_start; i<local_row_end; ++i)
for (unsigned int i=local_row_start; i<local_row_end; ++i)
{
- const int petsc_i = i;
+#ifdef PETSC_USE_64BIT_INDICES
+ PetscInt
+#else
+ int
+#endif
+ petsc_i = i;
MatSetValues (matrix, 1, &petsc_i,
sparsity_pattern.row_length(i),
&colnums_in_window[rowstart_in_window[i-local_row_start]],
int
SolverBase::convergence_test (KSP /*ksp*/,
- const int iteration,
+#ifdef PETSC_USE_64BIT_INDICES
+ const PetscInt iteration,
+#else
+ const int iteration,
+#endif
const PetscReal residual_norm,
KSPConvergedReason *reason,
void *solver_control_x)
// signed integers. so we have to
// convert, unless we want to play dirty
// tricks with conversions of pointers
- const std::vector<signed int> int_row_lengths (row_lengths.begin(),
- row_lengths.end());
+#ifdef PETSC_USE_64BIT_INDICES
+ const std::vector<PetscInt>
+#else
+ const std::vector<int>
+#endif
+ int_row_lengths (row_lengths.begin(), row_lengths.end());
const int ierr
= MatCreateSeqAIJ(PETSC_COMM_SELF, m, n, 0,
&int_row_lengths[0], &matrix);
// class.
if (preset_nonzero_locations == true)
{
- std::vector<int> row_entries;
+#ifdef PETSC_USE_64BIT_INDICES
+ std::vector<PetscInt>
+#else
+ std::vector<int>
+#endif
+ row_entries;
std::vector<PetscScalar> row_values;
for (unsigned int i=0; i<sparsity_pattern.n_rows(); ++i)
{
for (unsigned int j=0; j<row_lengths[i]; ++j)
row_entries[j] = sparsity_pattern.column_number (i,j);
- const int int_row = i;
+#ifdef PETSC_USE_64BIT_INDICES
+ const PetscInt
+#else
+ const int
+#endif
+ int_row = i;
MatSetValues (matrix, 1, &int_row,
row_lengths[i], &row_entries[0],
&row_values[0], INSERT_VALUES);
// element is actually locally
// available
int ierr;
- int begin, end;
+#ifdef PETSC_USE_64BIT_INDICES
+ PetscInt
+#else
+ int
+#endif
+ begin, end;
ierr = VecGetOwnershipRange (static_cast<const Vec &>(vector),
&begin, &end);
AssertThrow (ierr == 0, ExcPETScError(ierr));
unsigned int
VectorBase::size () const
{
- int sz;
+#ifdef PETSC_USE_64BIT_INDICES
+ PetscInt
+#else
+ int
+#endif
+ sz;
const int ierr = VecGetSize (vector, &sz);
AssertThrow (ierr == 0, ExcPETScError(ierr));
unsigned int
VectorBase::local_size () const
{
- int sz;
+#ifdef PETSC_USE_64BIT_INDICES
+ PetscInt
+#else
+ int
+#endif
+ sz;
const int ierr = VecGetLocalSize (vector, &sz);
AssertThrow (ierr == 0, ExcPETScError(ierr));
std::pair<unsigned int, unsigned int>
VectorBase::local_range () const
{
- int begin, end;
+#ifdef PETSC_USE_64BIT_INDICES
+ PetscInt
+#else
+ int
+#endif
+ begin, end;
const int ierr = VecGetOwnershipRange (static_cast<const Vec &>(vector),
&begin, &end);
AssertThrow (ierr == 0, ExcPETScError(ierr));
// (unlike the above calls)
if (n_elements != 0)
{
-#if (PETSC_VERSION_MAJOR <= 2) && \
- ((PETSC_VERSION_MINOR < 2) || \
- ((PETSC_VERSION_MINOR == 2) && (PETSC_VERSION_SUBMINOR == 0)))
- const int * petsc_indices = indices;
-#else
+#ifdef PETSC_USE_64BIT_INDICES
std::vector<PetscInt> petsc_ind (n_elements);
for (unsigned int i=0; i<n_elements; ++i)
petsc_ind[i] = indices[i];
- const PetscInt * petsc_indices = &petsc_ind[0];
+ const PetscInt *petsc_indices = &petsc_ind[0];
+#else
+ const int * petsc_indices = (const int*)indices;
#endif
InsertMode mode = ADD_VALUES;
// get number of converged
// eigenstates
ierr = EPSGetConverged (solver_data->eps,
+#ifdef PETSC_USE_64BIT_INDICES
+ reinterpret_cast<PetscInt *>(n_converged));
+#else
reinterpret_cast<int *>(n_converged));
+#endif
AssertThrow (ierr == 0, ExcSLEPcError(ierr));
}