Skip to content
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

#56: implement parallel meshes as smaller instances of a global mesh #57

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

pierrepebay
Copy link
Contributor

Resolves #56

@pierrepebay pierrepebay added the enhancement New feature or request label Aug 5, 2022
@pierrepebay pierrepebay requested a review from lifflander August 5, 2022 15:21
@pierrepebay pierrepebay self-assigned this Aug 5, 2022
pierrepebay and others added 13 commits August 8, 2022 12:10
… size

Parallel mesh sizes are now more equally distributed
- needs handling of cases where parallel mesh is of multiple current location types at once (e.g. domain mesh is divided in (1, 1), (2, 1), etc. parallel meshes)
- needs usage of this type in order to correctly define mesh chunk borders
…nk creation

- needs (2, 1) and (1, 2) number of parallel meshes case handling
- needs further testing
@pierrepebay pierrepebay marked this pull request as ready for review August 15, 2022 13:24
@pierrepebay pierrepebay requested a review from cz4rs August 16, 2022 17:18
@cz4rs
Copy link

cz4rs commented Aug 17, 2022

Commit formatting check will keep complaining until all (non-merge) commits start with #issue_number:

Every commit must match these patterns: 'Merge*' OR '^#[0-9]+[: ]'

image

target_link_libraries(parallel_test MPI::MPI_CXX)
target_link_libraries(allTests MPI::MPI_CXX)
elseif(${USE_MPI} AND NOT MPI_FOUND)
MESSAGE(WARNING "MPI not found. Disabling MPI.")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as MPI is marked as REQUIRED, CMake should fail with adequate error in the find_package step.

Comment on lines +22 to +27
uint64_t n_c_x = 32;
uint64_t n_c_y = 32;
uint64_t n_parallel_meshes_x = 1;
uint64_t n_parallel_meshes_y = 1;
uint64_t n_colors_x = 1;
uint64_t n_colors_y = 1;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be printed as Input parameters as well? (see below)

Comment on lines +270 to +302
for(uint64_t ky = 0; ky < this->n_p_mesh_y; ky++){
n_y = n_cells_p_mesh_y;
// correct parallel mesh size with remainder
if(r_y > 0){
n_y++;
r_y--;
}

// compute location type of current parallel mesh
if(ky == 0){
p_mesh_border = static_cast<int>(LocationIndexEnum::VERT_BAR_BOT);
}
else if(ky == this->n_p_mesh_y - 1){
p_mesh_border = static_cast<int>(LocationIndexEnum::VERT_BAR_TOP);
}
else{
p_mesh_border = static_cast<int>(LocationIndexEnum::VERT_BAR_MID);
}

if(this->verbosity >= 2){
std::cout << "coordinates, pmesh border type: "
<< "(0, " << ky << ")"
<< " // " << static_cast<int>(p_mesh_border) << '\n';
}

// construct current parallel mesh
this->parallel_meshes.emplace
(std::piecewise_construct,
std::forward_as_tuple(std::array<uint64_t,2>{0, ky}),
std::forward_as_tuple(n_cells_p_mesh_x, n_y, this->h, n_p, n_q, p_mesh_border, o_x, o_y));

o_y += n_y * this->h;
}
Copy link

@cz4rs cz4rs Aug 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarity / method length: extract this into a separate helper method. This will make the whole top-level code much more readable:

if()
    if()
        do_only_one_column_of_parallel_meshes(...);
    elseif()
        do_only_one_row_of_parallel_meshes(...);
    else
        do_something(...);
else
    if()
        do_parallel_mesh_is_unique(...);
...
...
...

Comment on lines +306 to +338
for(uint64_t kx = 0; kx < this->n_p_mesh_x; kx++){
n_x = n_cells_p_mesh_x;
// correct parallel mesh size with remainder
if(r_x > 0){
n_x++;
r_x--;
}

// compute location type of current parallel mesh
if(kx == 0){
p_mesh_border = static_cast<int>(LocationIndexEnum::HORIZ_BAR_L);
}
else if(kx == this->n_p_mesh_x - 1){
p_mesh_border = static_cast<int>(LocationIndexEnum::HORIZ_BAR_R);
}
else{
p_mesh_border = static_cast<int>(LocationIndexEnum::HORIZ_BAR_MID);
}

if(this->verbosity >= 2){
std::cout << "coordinates, pmesh border type: "
<< "( " << kx << ", 0)"
<< " // " << static_cast<int>(p_mesh_border) << '\n';
}

// construct current parallel mesh
this->parallel_meshes.emplace
(std::piecewise_construct,
std::forward_as_tuple(std::array<uint64_t,2>{kx, 0}),
std::forward_as_tuple(n_x, n_cells_p_mesh_y, this->h, n_p, n_q, p_mesh_border, o_x, o_y));

o_x += n_x * this->h;
}
Copy link

@cz4rs cz4rs Aug 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: extract into a helper method, do the same for the remaining cases below.


// compute location type of current parallel mesh
if(ky == 0){
p_mesh_border = static_cast<int>(LocationIndexEnum::VERT_BAR_BOT);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since p_mesh_border is int8_t:

Suggested change
p_mesh_border = static_cast<int>(LocationIndexEnum::VERT_BAR_BOT);
p_mesh_border = static_cast<int8_t>(LocationIndexEnum::VERT_BAR_BOT);

here and everywhere below.

@cz4rs
Copy link

cz4rs commented Aug 17, 2022

Latest Kokkos release is 3.6.01.
Consider updating it here:

RUN ./kokkos.sh 3.1.01 /pkgs 0

Note: maybe this could be done in a separate issue?

@@ -9,6 +9,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})

# Setting options
option(OUTPUT_VTK_FILES "When OFF allows for a non-VTK build" OFF)
option(USE_MPI "When OFF allows for a non-MPI build" OFF)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this being OFF by default, this feature will not get tested in CI.
Long-term it would be really good to have that configuration tested as well.

EDGE_2 = 6,
EDGE_3 = 7,
INTERIOR = 8
CORNER_0 = 0, // Bottom Left
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider changing the names instead of adding comments.

@@ -28,6 +50,7 @@ class ParallelMesh
uint64_t get_n_points_y() const { return this->n_cells_y + 1; }
double get_cell_size() const { return this->h; }
std::array<double,2> get_origin() const {return this->origin; }
uint8_t get_location_type() const { return this->location_type; }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return type does not match int8_t location_type.

Suggested change
uint8_t get_location_type() const { return this->location_type; }
int8_t get_location_type() const { return this->location_type; }

Comment on lines +256 to +260
uint64_t n_cells_p_mesh_x = this->domain_size_x / this->n_p_mesh_x;
uint64_t n_cells_p_mesh_y = this->domain_size_y / this->n_p_mesh_y;

uint64_t remainder_x = this->domain_size_x % n_cells_p_mesh_x;
uint64_t remainder_y = this->domain_size_y % n_cells_p_mesh_y;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider making this constexpr getter methods.

Comment on lines +696 to +702
// // Get the number of processes
// int p;
// MPI_Comm_size(MPI_COMM_WORLD, &p);
//
// // Get process rank
// int world_rank;
// MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove if this is not needed.

Comment on lines +23 to +25
if(this->verbosity >= 1){
std::cout << "Assembling parallel meshes..." << std::endl;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Encapsulate this with a helper method like:

void debug_print(const std::string& msg) {
    if(this->verbosity >= 1){
        std::cout << msg << std::endl;
    }
}

so you can use:

debug_print("Assembling parallel meshes...");

Copy link

@cz4rs cz4rs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Various code quality comments posted. I have only briefly looked at the math / logic here, but I assume that part is OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement parallel meshes as smaller instances of a global mesh
2 participants