YAC 3.18.0
Yet Another Coupler
Loading...
Searching...
No Matches
test_mpi_abort_c.c
Go to the documentation of this file.
1// Copyright (c) 2024 The YAC Authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#include <stdlib.h>
6#include <string.h>
7#include <stdio.h>
8#include <mpi.h>
9#include "tests.h"
10#include "yac.h"
11#include "yac_core.h"
12
18static void custom_error_handler(
19 MPI_Comm comm, const char * msg, const char * source, int line);
20
21char const * ref_msg = "reference message";
22char const * ref_source = __FILE__;
23int const ref_line = __LINE__;
25
26int main (void) {
27
28 if (yac_mpi_calls_are_allowed())
29 PUT_ERR("error in yac_mpi_calls_are_allowed");
30
31 MPI_Init(NULL, NULL);
32
33 if (!yac_mpi_calls_are_allowed())
34 PUT_ERR("error in yac_mpi_calls_are_allowed");
35
36 MPI_Comm_dup(MPI_COMM_WORLD, &ref_comm_world);
37
40 PUT_ERR("error in yac_get_abort_handler/yac_get_default_abort_handler");
41
44
46 PUT_ERR("error in yac_get_abort_handler");
47
49
52 PUT_ERR("error in yac_get_abort_handler/yac_get_default_abort_handler");
53
55
56 int rank;
57 MPI_Comm_rank(ref_comm_world, &rank);
58
59 if (rank == 0) {
61 } else {
63 }
64
65 // test should never reach this point
66 PUT_ERR("yac_abort_default did not abort program");
67
68 MPI_Finalize();
69
70 if (yac_mpi_calls_are_allowed())
71 PUT_ERR("error in yac_mpi_calls_are_allowed");
72
73 return TEST_EXIT_CODE;
74}
75
77 MPI_Comm comm, const char * msg, const char * source, int line) {
78
79 MPI_Barrier(comm);
80
81 int result;
82 MPI_Comm_compare(comm, ref_comm_world, &result);
83 if (result != MPI_IDENT) PUT_ERR("error in yac_abort_message (comm)");
84
85 if (strcmp(msg, ref_msg)) PUT_ERR("error in yac_abort_message (msg)");
86
87 if (strcmp(source, ref_source)) PUT_ERR("error in yac_abort_message (source)");
88
89 if (line != ref_line) PUT_ERR("error in yac_abort_message (line)");
90
91 // MPI_Abort may yield non-zero error codes of mpirun hence we
92 // terminate the programm gracefully
93 MPI_Finalize();
94 exit(TEST_EXIT_CODE);
95}
char const * ref_msg
int const ref_line
static void custom_error_handler(MPI_Comm comm, const char *msg, const char *source, int line)
MPI_Comm ref_comm_world
char const * ref_source
#define TEST_EXIT_CODE
Definition tests.h:15
#define PUT_ERR(string)
Definition tests.h:10
yac_abort_func yac_get_abort_handler(void)
void yac_set_default_comm(MPI_Comm comm)
void(* yac_abort_func)(MPI_Comm comm, const char *msg, const char *source, int line) __attribute__((noreturn))
Definition yac.h:3514
void yac_abort(MPI_Comm comm, const char *msg, const char *source, int line) __attribute__((noreturn))
void yac_restore_default_abort_handler(void)
yac_abort_func yac_get_default_abort_handler(void)
void yac_set_abort_handler(yac_abort_func custom_abort)
void yac_abort_message(char const *, char const *, int)