Skip to content

Commit d793726

Browse files
committed
Tried to set different backends
1 parent a43b8e6 commit d793726

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

examples/Hdiv-mixed/include/structs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct CeedData_ {
4040
// Application context from user command line options
4141
typedef struct AppCtx_ *AppCtx;
4242
struct AppCtx_ {
43+
char ceed_resource[PETSC_MAX_PATH_LEN]; // libCEED backend
4344
MPI_Comm comm;
4445
// Degree of polynomial (1 only), extra quadrature pts
4546
PetscInt degree;

examples/Hdiv-mixed/main.c

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,6 @@ int main(int argc, char **argv) {
4040
// ---------------------------------------------------------------------------
4141
PetscCall( PetscInitialize(&argc, &argv, NULL, help) );
4242

43-
// ---------------------------------------------------------------------------
44-
// Initialize libCEED
45-
// ---------------------------------------------------------------------------
46-
// -- Initialize backend
47-
Ceed ceed;
48-
CeedInit("/cpu/self/ref/serial", &ceed);
49-
CeedMemType mem_type_backend;
50-
CeedGetPreferredMemType(ceed, &mem_type_backend);
51-
52-
VecType vec_type = NULL;
53-
switch (mem_type_backend) {
54-
case CEED_MEM_HOST: vec_type = VECSTANDARD; break;
55-
case CEED_MEM_DEVICE: {
56-
const char *resolved;
57-
CeedGetResource(ceed, &resolved);
58-
if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
59-
else if (strstr(resolved, "/gpu/hip/occa"))
60-
vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678
61-
else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP;
62-
else vec_type = VECSTANDARD;
63-
}
64-
}
65-
6643
// ---------------------------------------------------------------------------
6744
// Create structs
6845
// ---------------------------------------------------------------------------
@@ -101,6 +78,30 @@ int main(int argc, char **argv) {
10178
app_ctx->ctx_Hdiv = ctx_Hdiv;
10279
app_ctx->ctx_H1 = ctx_H1;
10380

81+
// ---------------------------------------------------------------------------
82+
// Initialize libCEED
83+
// ---------------------------------------------------------------------------
84+
// -- Initialize backend
85+
Ceed ceed;
86+
//CeedInit("/cpu/self/ref/serial", &ceed);
87+
CeedInit(app_ctx->ceed_resource, &ceed);
88+
CeedMemType mem_type_backend;
89+
CeedGetPreferredMemType(ceed, &mem_type_backend);
90+
91+
VecType vec_type = NULL;
92+
switch (mem_type_backend) {
93+
case CEED_MEM_HOST: vec_type = VECSTANDARD; break;
94+
case CEED_MEM_DEVICE: {
95+
const char *resolved;
96+
CeedGetResource(ceed, &resolved);
97+
if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
98+
else if (strstr(resolved, "/gpu/hip/occa"))
99+
vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678
100+
else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP;
101+
else vec_type = VECSTANDARD;
102+
}
103+
}
104+
104105
// -- Process general command line options
105106
MPI_Comm comm = PETSC_COMM_WORLD;
106107
// ---------------------------------------------------------------------------

examples/Hdiv-mixed/src/cl-options.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,22 @@
2323
PetscErrorCode ProcessCommandLineOptions(AppCtx app_ctx) {
2424

2525
PetscBool problem_flag = PETSC_FALSE;
26+
PetscBool ceed_flag = PETSC_FALSE;
2627
PetscFunctionBeginUser;
2728

2829
PetscOptionsBegin(app_ctx->comm, NULL, "H(div) examples in PETSc with libCEED",
2930
NULL);
3031

32+
PetscCall( PetscOptionsString("-ceed", "CEED resource specifier",
33+
NULL, app_ctx->ceed_resource, app_ctx->ceed_resource,
34+
sizeof(app_ctx->ceed_resource), &ceed_flag) );
35+
36+
// Provide default ceed resource if not specified
37+
if (!ceed_flag) {
38+
const char *ceed_resource = "/cpu/self";
39+
strncpy(app_ctx->ceed_resource, ceed_resource, 10);
40+
}
41+
3142
PetscCall( PetscOptionsFList("-problem", "Problem to solve", NULL,
3243
app_ctx->problems,
3344
app_ctx->problem_name, app_ctx->problem_name, sizeof(app_ctx->problem_name),

0 commit comments

Comments
 (0)