Skip to content

Commit

Permalink
Adress comment Timo and change int to size_t in changes from #713
Browse files Browse the repository at this point in the history
  • Loading branch information
MFraters committed Jun 10, 2024
1 parent 75a6018 commit b703c03
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
14 changes: 7 additions & 7 deletions source/world_builder/utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ namespace WorldBuilder
MPI_Comm_rank(comm, &my_rank);
if (my_rank == 0)
{
uint64_t filesize;
int filesize;
std::ifstream filestream;
filestream.open(filename.c_str());
WBAssertThrow (filestream.is_open(), std::string("Could not open file <") + filename + ">.");
Expand Down Expand Up @@ -1217,17 +1217,17 @@ namespace WorldBuilder
}

data_string = datastream.str();
filesize = data_string.size();
WBAssertThrow(filesize < std::numeric_limits<uint64_t>::max(),
WBAssertThrow(static_cast<long int>(data_string.size()) < std::numeric_limits<int>::max(),
"File to large to be send with MPI.");
filesize = static_cast<int>(data_string.size());

// Distribute data_size and data across processes
int ierr = MPI_Bcast(&filesize, 1, MPI_UNSIGNED, 0, comm);
WBAssertThrow(ierr == 0, "MPI_Bcast failed.");

// Receive and store data
ierr = MPI_Bcast(&data_string[0],
static_cast<int>(filesize),
filesize,
MPI_CHAR,
0,
comm);
Expand Down Expand Up @@ -1510,12 +1510,12 @@ namespace WorldBuilder
multiply_3x3_matrices(const std::array<std::array<double,3>,3> mat1, const std::array<std::array<double,3>,3> mat2)
{
std::array<std::array<double,3>,3> result;
for (int i = 0; i < 3; i++)
for (size_t i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
for (size_t j = 0; j < 3; j++)
{
result[i][j] = 0;
for (int k = 0; k < 3; k++)
for (size_t k = 0; k < 3; k++)
{
result[i][j] += mat1[i][k] * mat2[k][j];
}
Expand Down
24 changes: 12 additions & 12 deletions tests/unit_tests/utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,54 +40,54 @@ TEST_CASE("multiply 3x3 matrices")
std::array<std::array<double,3>,3> result6 = {{{{39.9,36.8,33.7}},{{60,47.5,35}},{{-94.2,-80.5,-66.8}}}}; //mat3*mat2

std::array<std::array<double,3>,3> result7 = Utilities::multiply_3x3_matrices(mat1, mat2);
for (int i = 0; i < 3; i++)
for (size_t i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
for (size_t j = 0; j < 3; j++)
{
CHECK(result1[i][j] == Approx(result7[i][j]));
}
}

std::array<std::array<double,3>,3> result8 = Utilities::multiply_3x3_matrices(mat2, mat1);
for (int i = 0; i < 3; i++)
for (size_t i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
for (size_t j = 0; j < 3; j++)
{
CHECK(result2[i][j] == Approx(result8[i][j]));
}
}

std::array<std::array<double,3>,3> result9 = Utilities::multiply_3x3_matrices(mat1, mat3);
for (int i = 0; i < 3; i++)
for (size_t i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
for (size_t j = 0; j < 3; j++)
{
CHECK(result3[i][j] == Approx(result9[i][j]));
}
}

std::array<std::array<double,3>,3> result10 = Utilities::multiply_3x3_matrices(mat3, mat1);
for (int i = 0; i < 3; i++)
for (size_t i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
for (size_t j = 0; j < 3; j++)
{
CHECK(result4[i][j] == Approx(result10[i][j]));
}
}

std::array<std::array<double,3>,3> result11 = Utilities::multiply_3x3_matrices(mat2, mat3);
for (int i = 0; i < 3; i++)
for (size_t i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
for (size_t j = 0; j < 3; j++)
{
CHECK(result5[i][j] == Approx(result11[i][j]));
}
}

std::array<std::array<double,3>,3> result12 = Utilities::multiply_3x3_matrices(mat3, mat2);
for (int i = 0; i < 3; i++)
for (size_t i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
for (size_t j = 0; j < 3; j++)
{
CHECK(result6[i][j] == Approx(result12[i][j]));
}
Expand Down

0 comments on commit b703c03

Please sign in to comment.