Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 24 additions & 25 deletions examples/petsc/area.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int main(int argc, char **argv) {
Ceed ceed;
CeedData ceed_data;
ProblemType problem_choice;
VecType vec_type;
VecType vec_type = VECSTANDARD;
PetscMemType mem_type;

PetscCall(PetscInitialize(&argc, &argv, NULL, help));
Expand Down Expand Up @@ -110,15 +110,6 @@ int main(int argc, char **argv) {
// Create DM
PetscCall(SetupDMByDegree(dm, degree, q_extra, num_comp_u, topo_dim, false));

// Create vectors
PetscCall(DMCreateGlobalVector(dm, &U));
PetscCall(VecGetLocalSize(U, &l_size));
PetscCall(VecGetSize(U, &g_size));
PetscCall(DMCreateLocalVector(dm, &U_loc));
PetscCall(VecGetSize(U_loc, &xl_size));
PetscCall(VecDuplicate(U, &V));
PetscCall(VecDuplicate(U_loc, &V_loc));

// Setup op_apply_ctx structure
PetscCall(PetscMalloc1(1, &op_apply_ctx));

Expand All @@ -127,23 +118,31 @@ int main(int argc, char **argv) {
CeedMemType mem_type_backend;
CeedGetPreferredMemType(ceed, &mem_type_backend);

PetscCall(DMGetVecType(dm, &vec_type));
if (!vec_type) { // Not yet set by op_apply_ctx -dm_vec_type
switch (mem_type_backend) {
case CEED_MEM_HOST:
vec_type = VECSTANDARD;
break;
case CEED_MEM_DEVICE: {
const char *resolved;
CeedGetResource(ceed, &resolved);
if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
else if (strstr(resolved, "/gpu/hip/occa")) vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678
else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP;
else vec_type = VECSTANDARD;
}
// Set mesh vec_type
switch (mem_type_backend) {
case CEED_MEM_HOST:
vec_type = VECSTANDARD;
break;
case CEED_MEM_DEVICE: {
const char *resolved;

CeedGetResource(ceed, &resolved);
if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
else if (strstr(resolved, "/gpu/hip/occa")) vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678
else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP;
else vec_type = VECSTANDARD;
}
PetscCall(DMSetVecType(dm, vec_type));
}
PetscCall(DMSetVecType(dm, vec_type));

// Create vectors
PetscCall(DMCreateGlobalVector(dm, &U));
PetscCall(VecGetLocalSize(U, &l_size));
PetscCall(VecGetSize(U, &g_size));
PetscCall(DMCreateLocalVector(dm, &U_loc));
PetscCall(VecGetSize(U_loc, &xl_size));
PetscCall(VecDuplicate(U, &V));
PetscCall(VecDuplicate(U_loc, &V_loc));

// Print summary
if (!test_mode) {
Expand Down
32 changes: 16 additions & 16 deletions examples/petsc/bps.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static PetscErrorCode RunWithDM(RunParams rp, DM dm, const char *ceed_resource)
CeedQFunction qf_error;
CeedOperator op_error;
CeedVector rhs_ceed, target;
VecType vec_type;
VecType vec_type = VECSTANDARD;
PetscMemType mem_type;

PetscFunctionBeginUser;
Expand All @@ -71,23 +71,23 @@ static PetscErrorCode RunWithDM(RunParams rp, DM dm, const char *ceed_resource)
CeedMemType mem_type_backend;
CeedGetPreferredMemType(ceed, &mem_type_backend);

PetscCall(DMGetVecType(dm, &vec_type));
if (!vec_type) { // Not yet set by user -dm_vec_type
switch (mem_type_backend) {
case CEED_MEM_HOST:
vec_type = VECSTANDARD;
break;
case CEED_MEM_DEVICE: {
const char *resolved;
CeedGetResource(ceed, &resolved);
if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
else if (strstr(resolved, "/gpu/hip/occa")) vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678
else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP;
else vec_type = VECSTANDARD;
}
// Set mesh vec_type
switch (mem_type_backend) {
case CEED_MEM_HOST:
vec_type = VECSTANDARD;
break;
case CEED_MEM_DEVICE: {
const char *resolved;

CeedGetResource(ceed, &resolved);
if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
else if (strstr(resolved, "/gpu/hip/occa")) vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678
else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP;
else vec_type = VECSTANDARD;
}
PetscCall(DMSetVecType(dm, vec_type));
}
PetscCall(DMSetVecType(dm, vec_type));
PetscCall(DMSetFromOptions(dm));

// Create global and local solution vectors
PetscCall(DMCreateGlobalVector(dm, &X));
Expand Down
1 change: 1 addition & 0 deletions examples/petsc/bpsraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ int main(int argc, char **argv) {
break;
case CEED_MEM_DEVICE: {
const char *resolved;

CeedGetResource(ceed, &resolved);
if (strstr(resolved, "/gpu/cuda")) default_vec_type = VECCUDA;
else if (strstr(resolved, "/gpu/hip/occa")) default_vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678
Expand Down
31 changes: 15 additions & 16 deletions examples/petsc/bpssphere.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int main(int argc, char **argv) {
CeedOperator op_error;
CeedVector rhs_ceed, target;
BPType bp_choice;
VecType vec_type;
VecType vec_type = VECSTANDARD;
PetscMemType mem_type;

PetscCall(PetscInitialize(&argc, &argv, NULL, help));
Expand Down Expand Up @@ -130,23 +130,22 @@ int main(int argc, char **argv) {
CeedMemType mem_type_backend;
CeedGetPreferredMemType(ceed, &mem_type_backend);

PetscCall(DMGetVecType(dm, &vec_type));
if (!vec_type) { // Not yet set by user -dm_vec_type
switch (mem_type_backend) {
case CEED_MEM_HOST:
vec_type = VECSTANDARD;
break;
case CEED_MEM_DEVICE: {
const char *resolved;
CeedGetResource(ceed, &resolved);
if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
else if (strstr(resolved, "/gpu/hip/occa")) vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678
else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP;
else vec_type = VECSTANDARD;
}
// Set mesh vec_type
switch (mem_type_backend) {
case CEED_MEM_HOST:
vec_type = VECSTANDARD;
break;
case CEED_MEM_DEVICE: {
const char *resolved;

CeedGetResource(ceed, &resolved);
if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
else if (strstr(resolved, "/gpu/hip/occa")) vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678
else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP;
else vec_type = VECSTANDARD;
}
PetscCall(DMSetVecType(dm, vec_type));
}
PetscCall(DMSetVecType(dm, vec_type));

// Print summary
if (!test_mode) {
Expand Down
48 changes: 24 additions & 24 deletions examples/petsc/bpsswarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int main(int argc, char **argv) {
CeedData ceed_data;
CeedOperator op_error;
BPType bp_choice;
VecType vec_type;
VecType vec_type = VECSTANDARD;
PointSwarmType point_swarm_type = SWARM_GAUSS;
PetscMPIInt ranks_per_node;
char hostname[PETSC_MAX_PATH_LEN];
Expand Down Expand Up @@ -195,6 +195,29 @@ int main(int argc, char **argv) {
PetscCall(PetscObjectSetName((PetscObject)dm_swarm, "Particle Swarm"));
PetscCall(DMViewFromOptions(dm_swarm, NULL, "-dm_swarm_view"));

// Set up libCEED
CeedInit(ceed_resource, &ceed);
CeedMemType mem_type_backend;
CeedGetPreferredMemType(ceed, &mem_type_backend);

// Set background mesh vec_type
switch (mem_type_backend) {
case CEED_MEM_HOST:
vec_type = VECSTANDARD;
break;
case CEED_MEM_DEVICE: {
const char *resolved;

CeedGetResource(ceed, &resolved);
if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
else if (strstr(resolved, "/gpu/hip/occa")) vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678
else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP;
else vec_type = VECSTANDARD;
}
}
PetscCall(DMSetVecType(dm_mesh, vec_type));
PetscCall(DMSetFromOptions(dm_mesh));

// Create vectors
PetscCall(DMCreateGlobalVector(dm_mesh, &X));
PetscCall(VecGetLocalSize(X, &l_size));
Expand All @@ -211,29 +234,6 @@ int main(int argc, char **argv) {
PetscCall(MatShellSetOperation(mat_O, MATOP_MULT, (void (*)(void))MatMult_Ceed));
PetscCall(MatShellSetOperation(mat_O, MATOP_GET_DIAGONAL, (void (*)(void))MatGetDiag));

// Set up libCEED
CeedInit(ceed_resource, &ceed);
CeedMemType mem_type_backend;
CeedGetPreferredMemType(ceed, &mem_type_backend);

PetscCall(DMGetVecType(dm_mesh, &vec_type));
if (!vec_type) { // Not yet set by user -dm_vec_type
switch (mem_type_backend) {
case CEED_MEM_HOST:
vec_type = VECSTANDARD;
break;
case CEED_MEM_DEVICE: {
const char *resolved;
CeedGetResource(ceed, &resolved);
if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
else if (strstr(resolved, "/gpu/hip/occa")) vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678
else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP;
else vec_type = VECSTANDARD;
}
}
PetscCall(DMSetVecType(dm_mesh, vec_type));
}

// Print summary
if (!test_mode) {
PetscInt P = degree + 1, Q = P + q_extra;
Expand Down
5 changes: 4 additions & 1 deletion examples/petsc/multigrid.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,16 @@ int main(int argc, char **argv) {
PetscCall(DMPlexCreateBoxMesh(PETSC_COMM_WORLD, dim, simplex, mesh_elem, NULL, NULL, NULL, PETSC_TRUE, 0, PETSC_FALSE, &dm_orig));
}

VecType vec_type;
// Set mesh vec_type
VecType vec_type = VECSTANDARD;

switch (mem_type_backend) {
case CEED_MEM_HOST:
vec_type = VECSTANDARD;
break;
case CEED_MEM_DEVICE: {
const char *resolved;

CeedGetResource(ceed, &resolved);
if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
else if (strstr(resolved, "/gpu/hip/occa")) vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678
Expand Down
Loading