Skip to content

Commit c11fc3c

Browse files
authored
Merge pull request #1746 from CEED/jeremy/fix-bpsswarm
petsc - fix vec type checking
2 parents 6eb91da + 072672e commit c11fc3c

File tree

6 files changed

+84
-82
lines changed

6 files changed

+84
-82
lines changed

examples/petsc/area.c

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ int main(int argc, char **argv) {
7171
Ceed ceed;
7272
CeedData ceed_data;
7373
ProblemType problem_choice;
74-
VecType vec_type;
74+
VecType vec_type = VECSTANDARD;
7575
PetscMemType mem_type;
7676

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

113-
// Create vectors
114-
PetscCall(DMCreateGlobalVector(dm, &U));
115-
PetscCall(VecGetLocalSize(U, &l_size));
116-
PetscCall(VecGetSize(U, &g_size));
117-
PetscCall(DMCreateLocalVector(dm, &U_loc));
118-
PetscCall(VecGetSize(U_loc, &xl_size));
119-
PetscCall(VecDuplicate(U, &V));
120-
PetscCall(VecDuplicate(U_loc, &V_loc));
121-
122113
// Setup op_apply_ctx structure
123114
PetscCall(PetscMalloc1(1, &op_apply_ctx));
124115

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

130-
PetscCall(DMGetVecType(dm, &vec_type));
131-
if (!vec_type) { // Not yet set by op_apply_ctx -dm_vec_type
132-
switch (mem_type_backend) {
133-
case CEED_MEM_HOST:
134-
vec_type = VECSTANDARD;
135-
break;
136-
case CEED_MEM_DEVICE: {
137-
const char *resolved;
138-
CeedGetResource(ceed, &resolved);
139-
if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
140-
else if (strstr(resolved, "/gpu/hip/occa")) vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678
141-
else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP;
142-
else vec_type = VECSTANDARD;
143-
}
121+
// Set mesh vec_type
122+
switch (mem_type_backend) {
123+
case CEED_MEM_HOST:
124+
vec_type = VECSTANDARD;
125+
break;
126+
case CEED_MEM_DEVICE: {
127+
const char *resolved;
128+
129+
CeedGetResource(ceed, &resolved);
130+
if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
131+
else if (strstr(resolved, "/gpu/hip/occa")) vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678
132+
else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP;
133+
else vec_type = VECSTANDARD;
144134
}
145-
PetscCall(DMSetVecType(dm, vec_type));
146135
}
136+
PetscCall(DMSetVecType(dm, vec_type));
137+
138+
// Create vectors
139+
PetscCall(DMCreateGlobalVector(dm, &U));
140+
PetscCall(VecGetLocalSize(U, &l_size));
141+
PetscCall(VecGetSize(U, &g_size));
142+
PetscCall(DMCreateLocalVector(dm, &U_loc));
143+
PetscCall(VecGetSize(U_loc, &xl_size));
144+
PetscCall(VecDuplicate(U, &V));
145+
PetscCall(VecDuplicate(U_loc, &V_loc));
147146

148147
// Print summary
149148
if (!test_mode) {

examples/petsc/bps.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static PetscErrorCode RunWithDM(RunParams rp, DM dm, const char *ceed_resource)
6262
CeedQFunction qf_error;
6363
CeedOperator op_error;
6464
CeedVector rhs_ceed, target;
65-
VecType vec_type;
65+
VecType vec_type = VECSTANDARD;
6666
PetscMemType mem_type;
6767

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

74-
PetscCall(DMGetVecType(dm, &vec_type));
75-
if (!vec_type) { // Not yet set by user -dm_vec_type
76-
switch (mem_type_backend) {
77-
case CEED_MEM_HOST:
78-
vec_type = VECSTANDARD;
79-
break;
80-
case CEED_MEM_DEVICE: {
81-
const char *resolved;
82-
CeedGetResource(ceed, &resolved);
83-
if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
84-
else if (strstr(resolved, "/gpu/hip/occa")) vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678
85-
else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP;
86-
else vec_type = VECSTANDARD;
87-
}
74+
// Set mesh vec_type
75+
switch (mem_type_backend) {
76+
case CEED_MEM_HOST:
77+
vec_type = VECSTANDARD;
78+
break;
79+
case CEED_MEM_DEVICE: {
80+
const char *resolved;
81+
82+
CeedGetResource(ceed, &resolved);
83+
if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
84+
else if (strstr(resolved, "/gpu/hip/occa")) vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678
85+
else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP;
86+
else vec_type = VECSTANDARD;
8887
}
89-
PetscCall(DMSetVecType(dm, vec_type));
9088
}
89+
PetscCall(DMSetVecType(dm, vec_type));
90+
PetscCall(DMSetFromOptions(dm));
9191

9292
// Create global and local solution vectors
9393
PetscCall(DMCreateGlobalVector(dm, &X));

examples/petsc/bpsraw.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ int main(int argc, char **argv) {
403403
break;
404404
case CEED_MEM_DEVICE: {
405405
const char *resolved;
406+
406407
CeedGetResource(ceed, &resolved);
407408
if (strstr(resolved, "/gpu/cuda")) default_vec_type = VECCUDA;
408409
else if (strstr(resolved, "/gpu/hip/occa")) default_vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678

examples/petsc/bpssphere.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ int main(int argc, char **argv) {
6464
CeedOperator op_error;
6565
CeedVector rhs_ceed, target;
6666
BPType bp_choice;
67-
VecType vec_type;
67+
VecType vec_type = VECSTANDARD;
6868
PetscMemType mem_type;
6969

7070
PetscCall(PetscInitialize(&argc, &argv, NULL, help));
@@ -130,23 +130,22 @@ int main(int argc, char **argv) {
130130
CeedMemType mem_type_backend;
131131
CeedGetPreferredMemType(ceed, &mem_type_backend);
132132

133-
PetscCall(DMGetVecType(dm, &vec_type));
134-
if (!vec_type) { // Not yet set by user -dm_vec_type
135-
switch (mem_type_backend) {
136-
case CEED_MEM_HOST:
137-
vec_type = VECSTANDARD;
138-
break;
139-
case CEED_MEM_DEVICE: {
140-
const char *resolved;
141-
CeedGetResource(ceed, &resolved);
142-
if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
143-
else if (strstr(resolved, "/gpu/hip/occa")) vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678
144-
else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP;
145-
else vec_type = VECSTANDARD;
146-
}
133+
// Set mesh vec_type
134+
switch (mem_type_backend) {
135+
case CEED_MEM_HOST:
136+
vec_type = VECSTANDARD;
137+
break;
138+
case CEED_MEM_DEVICE: {
139+
const char *resolved;
140+
141+
CeedGetResource(ceed, &resolved);
142+
if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
143+
else if (strstr(resolved, "/gpu/hip/occa")) vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678
144+
else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP;
145+
else vec_type = VECSTANDARD;
147146
}
148-
PetscCall(DMSetVecType(dm, vec_type));
149147
}
148+
PetscCall(DMSetVecType(dm, vec_type));
150149

151150
// Print summary
152151
if (!test_mode) {

examples/petsc/bpsswarm.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int main(int argc, char **argv) {
6565
CeedData ceed_data;
6666
CeedOperator op_error;
6767
BPType bp_choice;
68-
VecType vec_type;
68+
VecType vec_type = VECSTANDARD;
6969
PointSwarmType point_swarm_type = SWARM_GAUSS;
7070
PetscMPIInt ranks_per_node;
7171
char hostname[PETSC_MAX_PATH_LEN];
@@ -195,6 +195,29 @@ int main(int argc, char **argv) {
195195
PetscCall(PetscObjectSetName((PetscObject)dm_swarm, "Particle Swarm"));
196196
PetscCall(DMViewFromOptions(dm_swarm, NULL, "-dm_swarm_view"));
197197

198+
// Set up libCEED
199+
CeedInit(ceed_resource, &ceed);
200+
CeedMemType mem_type_backend;
201+
CeedGetPreferredMemType(ceed, &mem_type_backend);
202+
203+
// Set background mesh vec_type
204+
switch (mem_type_backend) {
205+
case CEED_MEM_HOST:
206+
vec_type = VECSTANDARD;
207+
break;
208+
case CEED_MEM_DEVICE: {
209+
const char *resolved;
210+
211+
CeedGetResource(ceed, &resolved);
212+
if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
213+
else if (strstr(resolved, "/gpu/hip/occa")) vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678
214+
else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP;
215+
else vec_type = VECSTANDARD;
216+
}
217+
}
218+
PetscCall(DMSetVecType(dm_mesh, vec_type));
219+
PetscCall(DMSetFromOptions(dm_mesh));
220+
198221
// Create vectors
199222
PetscCall(DMCreateGlobalVector(dm_mesh, &X));
200223
PetscCall(VecGetLocalSize(X, &l_size));
@@ -211,29 +234,6 @@ int main(int argc, char **argv) {
211234
PetscCall(MatShellSetOperation(mat_O, MATOP_MULT, (void (*)(void))MatMult_Ceed));
212235
PetscCall(MatShellSetOperation(mat_O, MATOP_GET_DIAGONAL, (void (*)(void))MatGetDiag));
213236

214-
// Set up libCEED
215-
CeedInit(ceed_resource, &ceed);
216-
CeedMemType mem_type_backend;
217-
CeedGetPreferredMemType(ceed, &mem_type_backend);
218-
219-
PetscCall(DMGetVecType(dm_mesh, &vec_type));
220-
if (!vec_type) { // Not yet set by user -dm_vec_type
221-
switch (mem_type_backend) {
222-
case CEED_MEM_HOST:
223-
vec_type = VECSTANDARD;
224-
break;
225-
case CEED_MEM_DEVICE: {
226-
const char *resolved;
227-
CeedGetResource(ceed, &resolved);
228-
if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
229-
else if (strstr(resolved, "/gpu/hip/occa")) vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678
230-
else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP;
231-
else vec_type = VECSTANDARD;
232-
}
233-
}
234-
PetscCall(DMSetVecType(dm_mesh, vec_type));
235-
}
236-
237237
// Print summary
238238
if (!test_mode) {
239239
PetscInt P = degree + 1, Q = P + q_extra;

examples/petsc/multigrid.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,16 @@ int main(int argc, char **argv) {
120120
PetscCall(DMPlexCreateBoxMesh(PETSC_COMM_WORLD, dim, simplex, mesh_elem, NULL, NULL, NULL, PETSC_TRUE, 0, PETSC_FALSE, &dm_orig));
121121
}
122122

123-
VecType vec_type;
123+
// Set mesh vec_type
124+
VecType vec_type = VECSTANDARD;
125+
124126
switch (mem_type_backend) {
125127
case CEED_MEM_HOST:
126128
vec_type = VECSTANDARD;
127129
break;
128130
case CEED_MEM_DEVICE: {
129131
const char *resolved;
132+
130133
CeedGetResource(ceed, &resolved);
131134
if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
132135
else if (strstr(resolved, "/gpu/hip/occa")) vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678

0 commit comments

Comments
 (0)