Skip to content

Commit

Permalink
grid: Call MPI_Init and MPI_Finalize in grid_unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
oschuett committed May 3, 2023
1 parent 7a40705 commit c772426
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/grid/grid_unittest.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,26 @@
#include "common/grid_library.h"
#include "grid_replay.h"

// Only used to call MPI_Init and MPI_Finalize to avoid spurious MPI error.
#if defined(__parallel)
#include <mpi.h>
#endif

/*******************************************************************************
* \brief Standin for mpi_sum, passed to grid_library_print_stats.
* \author Ole Schuett
******************************************************************************/
static void mpi_sum_func(long *number, int mpi_comm) {
*number += 0; // Nothing todo without MPI, pretend arguments are used anyways.
mpi_comm += 0;
(void)number; // mark used
(void)mpi_comm;
}

/*******************************************************************************
* \brief Wrapper for printf, passed to grid_library_print_stats.
* \author Ole Schuett
******************************************************************************/
static void print_func(char *message, int output_unit) {
output_unit += 0; // Pretend argument is used.
(void)output_unit; // mark used
printf("%s", message);
}

Expand Down Expand Up @@ -65,6 +70,10 @@ static int run_test(const char cp2k_root_dir[], const char task_file[]) {
}

int main(int argc, char *argv[]) {
#if defined(__parallel)
MPI_Init(&argc, &argv);
#endif

if (argc != 2) {
printf("Usage: grid_unittest.x <cp2k-root-dir>\n");
return 1;
Expand Down Expand Up @@ -96,6 +105,10 @@ int main(int argc, char *argv[]) {
printf("\nFound %i errors :-(\n", errors);
}

#if defined(__parallel)
MPI_Finalize();
#endif

return errors;
}

Expand Down

0 comments on commit c772426

Please sign in to comment.