Skip to content

Commit

Permalink
Add support for MatShell to create Vecs of type standard, cuda, hip, …
Browse files Browse the repository at this point in the history
…kokkos depending on the value of -vec_type. This resolves errors associated with using --matrix_free yes
  • Loading branch information
dmay23 committed Sep 26, 2024
1 parent 0658ac5 commit b063726
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions app/common/PetscDGShell.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "PetscDGShell.h"
#include "common/PetscUtil.h"
#include "common/PetscVector.h"
#include <petsc/private/matimpl.h>

namespace tndm {

Expand All @@ -16,6 +17,34 @@ PetscDGShell::PetscDGShell(AbstractDGOperator<DomainDimension>& dgop) {

CHKERRTHROW(MatShellSetContext(A_, static_cast<void*>(&dgop)));
CHKERRTHROW(MatShellSetOperation(A_, MATOP_MULT, (void (*)(void))apply));
CHKERRTHROW(PetscStrallocpy(VECSTANDARD, &A_->defaultvectype)); // seq or mpi
{
char val[PETSC_MAX_PATH_LEN];
PetscBool found = PETSC_FALSE;
CHKERRTHROW(PetscOptionsGetString(NULL, NULL, "-vec_type", val, sizeof(val), &found));
if (found) {
PetscBool isstd, iskok, iscuda, iship;

CHKERRTHROW(PetscStrcmpAny(val, &isstd, VECSTANDARD, VECSEQ, VECMPI, ""));
if (isstd) {
CHKERRTHROW(PetscStrallocpy(VECSTANDARD, &A_->defaultvectype));
}
CHKERRTHROW(PetscStrcmpAny(val, &iskok, VECKOKKOS, VECSEQKOKKOS, VECMPIKOKKOS, ""));
if (iskok) {
CHKERRTHROW(PetscStrallocpy(VECKOKKOS, &A_->defaultvectype));
}

CHKERRTHROW(PetscStrcmpAny(val, &iscuda, VECCUDA, VECSEQCUDA, VECMPICUDA, ""));
if (iscuda) {
CHKERRTHROW(PetscStrallocpy(VECCUDA, &A_->defaultvectype));
}

CHKERRTHROW(PetscStrcmpAny(val, &iship, VECHIP, VECSEQHIP, VECMPIHIP, ""));
if (iship) {
CHKERRTHROW(PetscStrallocpy(VECHIP, &A_->defaultvectype));
}
}
}
}

PetscDGShell::~PetscDGShell() { MatDestroy(&A_); }
Expand Down

0 comments on commit b063726

Please sign in to comment.