-
Notifications
You must be signed in to change notification settings - Fork 201
Scalable point location #5396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Scalable point location #5396
Changes from all commits
1accc33
6b5eea5
06da607
4709136
0ce05f9
793a92d
ff062ff
1dd92d4
2fc20a6
ea48fb6
f413029
d792583
923db26
cb25eb6
7418224
a66d16d
ac08113
44863a6
5a60847
df6df0b
789b486
088e8c7
a0be450
431daec
aae03f4
6719b40
4cfd969
17cdaa4
db7972b
bf7037e
859032e
9f6ebd8
f852bc7
841af86
2f2e450
ed91eaf
e8ee003
6bf2a79
cb714a1
47b282e
eaa3cae
4d8fcf0
1f055bd
7147a71
e6b5613
d52bd1f
31e7b6c
0c3a195
df61091
7a4ac42
7b78a8e
c0c53ea
e527389
21d6c3b
c62aed6
53e8559
ae38341
134df37
a763304
d9b504c
4afb92f
c08a2bd
25a1931
35a4da5
0c9b497
c8ef52e
7da726b
287de23
42e8043
7d6a839
d9da160
19a2975
87a1cfc
3287edf
834f029
2ddefde
9441b00
18e1ccd
94acf88
9821b28
d0f5bf8
163d599
652ff63
15e6046
3847d7b
fe30274
4766a33
a492db8
d31cf38
2328530
0b6e605
85f6b88
bb51164
785fdc5
38f9dca
98fadff
89b1dcc
2edaed8
5100474
a1ae81e
3c23260
774cbed
9b31432
fe3a64d
c28e6e3
90e358e
5110928
efa91cf
7686278
539cc47
52987d3
31d4cdc
88c795b
e011c7d
c70e6cb
3926344
ba78ddb
1641137
ebb9aed
093b2b5
75479a8
f952270
3b36b89
86a675d
6a651da
103c14b
4df098d
106414b
0f92a05
4b046b3
e1f2800
0827193
cfed258
54a9f2b
a6fc0a7
425390b
39b7b1b
3d7c6f6
c321012
e7cac8c
d99abf5
e209f8f
b1de9fd
c211427
5570933
875f4c3
9e3407e
d39ac1e
2ad2709
4ed302b
9f10b94
fde4af2
62253a1
b9dafee
b10bd41
0442911
f28763e
e1af963
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,9 @@ PetscErrorCode locate_cell_from_candidates(struct Function *f, | |
| const int64_t *ids, | ||
| size_t ncells_ignore, | ||
| const PetscInt *cells_ignore, | ||
| PetscInt *cell_out) | ||
| const PetscInt *cell_owner_ranks, | ||
| PetscInt *cell_out, | ||
| PetscInt *owner_out) | ||
| { | ||
| bool cell_ignore_found = false; | ||
| /* NOTE: temp_ref_coords and found_ref_coords are actually of type | ||
|
|
@@ -21,13 +23,20 @@ PetscErrorCode locate_cell_from_candidates(struct Function *f, | |
| surrounds this is declared in pointquery_utils.py. We cast when we use the | ||
| ref_coords_copy function and trust that the underlying memory which the | ||
| pointers refer to is updated as necessary. */ | ||
| PetscReal ref_cell_dist_l1 = PETSC_MAX_REAL; | ||
| PetscReal current_ref_cell_dist_l1 = -0.5; | ||
| PetscReal best_distance = PETSC_MAX_REAL; | ||
| PetscInt best_owner = -1; | ||
| PetscInt best_cell = -1; | ||
| /* NOTE: `tolerance`, which is used throughout this function, is a static | ||
| variable defined outside this function when putting together all the C | ||
| code that needs to be compiled - see pointquery_utils.py */ | ||
|
|
||
| /* NOTE: `cell_owner_ranks` and `owner_out` may be NULL. In this case, every | ||
| candidate is treated as having owner rank 0. This is for backwards compatibility | ||
| with the `Function.at` code path which is being deprecated soon. */ | ||
| *cell_out = -1; | ||
| if (owner_out) { | ||
| *owner_out = -1; | ||
| } | ||
| for (size_t i = 0; i < nids; ++i) { | ||
| /* Check that casting the ids from int64 to PetscInt is safe (for 32 bit petsc builds). | ||
| Since the ids are mesh cell ids this *should* always be safe, but better to check | ||
|
|
@@ -47,33 +56,34 @@ PetscErrorCode locate_cell_from_candidates(struct Function *f, | |
| continue; | ||
| } | ||
|
|
||
| PetscReal distance; | ||
| PetscInt owner; | ||
| if (f->extruded) { | ||
| PetscInt nlayers = f->n_layers; | ||
| PetscInt c = candidate / nlayers; | ||
| PetscInt l = candidate % nlayers; | ||
| current_ref_cell_dist_l1 = (*try_candidate_xtr)(temp_ref_coords, f, c, l, x); | ||
| distance = (*try_candidate_xtr)(temp_ref_coords, f, c, l, x); | ||
| owner = cell_owner_ranks ? cell_owner_ranks[c] : 0; | ||
| } | ||
| else { | ||
| current_ref_cell_dist_l1 = (*try_candidate)(temp_ref_coords, f, candidate, x); | ||
| distance = (*try_candidate)(temp_ref_coords, f, candidate, x); | ||
| owner = cell_owner_ranks ? cell_owner_ranks[candidate] : 0; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a backwards compatibility thing? (
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Added a comment |
||
| } | ||
|
|
||
| if (current_ref_cell_dist_l1 <= 0.0) { | ||
| /* Found cell! */ | ||
| *cell_out = candidate; | ||
| /* Select owning cell by minimum L1 distance, with ties broken by highest owning rank. */ | ||
| if (distance < best_distance || (distance == best_distance && owner > best_owner)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still worry about this. Consider an interval mesh like (which is allowed since we don't always need a full cell of overlap) If
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A rank doesn't decide at this point that they own the point. The 'global' selection in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will it work if both ranks think that the other rank is the owner?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I'm reading your example correctly, rank 0 can see no cells of rank 1 and vice-versa. So I can't see how a rank could think the point lived in a cell owned by the other rank in this case. If we do have halos then this can happen, but by selecting the single highest owning rank we can never end up that situation.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't apply to the example I gave earlier. Only if there are halos. I guess my concern comes down to my mental model of floating point in parallel. Can we be sure that two ranks will compute the distance of a point on the cell boundary as exactly zero under any circumstance? |
||
| best_distance = distance; | ||
| best_owner = owner; | ||
| best_cell = candidate; | ||
| memcpy(found_ref_coords, temp_ref_coords, sizeof(struct ReferenceCoords)); | ||
| found_ref_cell_dist_l1[0] = current_ref_cell_dist_l1; | ||
| break; | ||
| } | ||
| else if (current_ref_cell_dist_l1 < ref_cell_dist_l1) { | ||
| /* getting closer... */ | ||
| ref_cell_dist_l1 = current_ref_cell_dist_l1; | ||
| if (ref_cell_dist_l1 < tolerance) { | ||
| /* Close to cell within tolerance so could be this cell */ | ||
| *cell_out = candidate; | ||
| memcpy(found_ref_coords, temp_ref_coords, sizeof(struct ReferenceCoords)); | ||
| found_ref_cell_dist_l1[0] = ref_cell_dist_l1; | ||
| } | ||
| } | ||
|
|
||
| if (best_cell != -1 && (best_distance <= 0.0 || best_distance < tolerance)) { | ||
| *cell_out = best_cell; | ||
| if (owner_out) { | ||
| *owner_out = best_owner; | ||
| } | ||
| *found_ref_cell_dist_l1 = best_distance; | ||
| } | ||
| return PETSC_SUCCESS; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this important?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment