|
| 1 | +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ |
| 2 | +/* |
| 3 | + * Copyright (c) 2025 Bull SAS. All rights reserved. |
| 4 | + * $COPYRIGHT$ |
| 5 | + * |
| 6 | + * Additional copyrights may follow |
| 7 | + * |
| 8 | + * $HEADER$ |
| 9 | + */ |
| 10 | + |
| 11 | +#include <execinfo.h> |
| 12 | +#include <stdint.h> |
| 13 | +#include <stdio.h> |
| 14 | + |
| 15 | +#include "ompi/communicator/communicator.h" |
| 16 | +#include "ompi/errhandler/errhandler.h" |
| 17 | +#include "ompi/include/mpi.h" |
| 18 | +#include "ompi/runtime/mpiruntime.h" |
| 19 | +#include "ompi/mca/common/ubcl/common_ubcl.h" |
| 20 | +#include "ompi/mca/pml/ubcl/pml_ubcl.h" |
| 21 | +#include "ompi/mca/pml/pml_constants.h" |
| 22 | +#include "opal/mca/common/ubcl/common_ubcl.h" |
| 23 | +#include "opal/util/output.h" |
| 24 | + |
| 25 | +/* Default ompi_common_ubcl values */ |
| 26 | +mca_ompi_common_ubcl_component_t mca_ompi_common_ubcl_component = { |
| 27 | + .n_addr = 32, |
| 28 | +}; |
| 29 | + |
| 30 | +static int mca_common_ubcl_find_rank(const struct ompi_communicator_t *comm, const uint64_t wrank) |
| 31 | +{ |
| 32 | + mca_pml_ubcl_comm_t *pml_comm = comm->c_pml_comm; |
| 33 | + |
| 34 | + if (NULL == comm->c_pml_comm) { |
| 35 | + common_ubcl_error("UBCL error: no translation array in comm"); |
| 36 | + abort(); |
| 37 | + } |
| 38 | + |
| 39 | + for (uint32_t i = 0; i < pml_comm->size; i++) { |
| 40 | + if (pml_comm->array[i] == wrank) { |
| 41 | + return i; |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + common_ubcl_error("UBCL error irank translation"); |
| 46 | + |
| 47 | + return 0; |
| 48 | +} |
| 49 | + |
| 50 | +int mca_common_ubcl_get_mpi_rank(const int rank, const struct ompi_communicator_t *comm, |
| 51 | + const uint64_t ubcl_rank) |
| 52 | +{ |
| 53 | + if (OMPI_ANY_SOURCE == rank) { |
| 54 | + return mca_common_ubcl_find_rank(comm, ubcl_rank); |
| 55 | + } else { |
| 56 | + return rank; |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +void mca_common_ubcl_status_to_ompi(ompi_status_public_t *status, |
| 61 | + ubcl_status_t ubcl_status, |
| 62 | + struct ompi_communicator_t *comm, int rank) |
| 63 | +{ |
| 64 | + if (MPI_STATUS_IGNORE != status) { |
| 65 | + status->_cancelled = 0; //TODO output the information of cancel |
| 66 | + status->_ucount = ubcl_status.size; |
| 67 | + status->MPI_TAG = (int) ubcl_status.tag; |
| 68 | + status->MPI_SOURCE = mca_common_ubcl_get_mpi_rank(rank, comm, ubcl_status.remote); |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +int ubcl_error_to_ompi(ubcl_error_t code) |
| 73 | +{ |
| 74 | + int ret; |
| 75 | + switch (code) { |
| 76 | + case UBCL_SUCCESS: |
| 77 | + ret = OPAL_SUCCESS; |
| 78 | + break; |
| 79 | + case UBCL_ERROR: |
| 80 | + ret = OPAL_ERROR; |
| 81 | + break; |
| 82 | + case UBCL_ERR_RESOURCE_BUSY: |
| 83 | + ret = OPAL_ERR_RESOURCE_BUSY; |
| 84 | + break; |
| 85 | + case UBCL_ERR_OUT_OF_RESOURCE: |
| 86 | + ret = OPAL_ERR_OUT_OF_RESOURCE; |
| 87 | + break; |
| 88 | + case UBCL_ERR_NOT_IMPLEMENTED: |
| 89 | + ret = OPAL_ERR_NOT_IMPLEMENTED; |
| 90 | + break; |
| 91 | + case UBCL_ERR_NOT_AVAILABLE: |
| 92 | + ret = OPAL_ERR_NOT_AVAILABLE; |
| 93 | + break; |
| 94 | + case UBCL_ERR_TEMP_OUT_OF_RESOURCE: |
| 95 | + ret = OPAL_ERR_TEMP_OUT_OF_RESOURCE; |
| 96 | + break; |
| 97 | + case UBCL_ERR_ARG_INVALID: |
| 98 | + ret = OPAL_ERR_BAD_PARAM; |
| 99 | + break; |
| 100 | + case UBCL_ERR_TOO_LATE: |
| 101 | + ret = OPAL_ERR_TIMEOUT; |
| 102 | + break; |
| 103 | + case UBCL_ERR_TRUNCATE: |
| 104 | + ret = MPI_ERR_TRUNCATE; |
| 105 | + break; |
| 106 | + default: |
| 107 | + ret = OPAL_ERROR; |
| 108 | + break; |
| 109 | + } |
| 110 | + |
| 111 | + return ret; |
| 112 | +} |
| 113 | + |
| 114 | +void _mca_common_ubcl_error(char *filename, int line, int err, |
| 115 | + char abort, int verbose, int output, |
| 116 | + int is_init, int comp_verbose, |
| 117 | + char *comp_name, char *format, ...) |
| 118 | +{ |
| 119 | + int n_addr = 0; |
| 120 | + void **stack_buffer = NULL; |
| 121 | + char **stack = NULL; |
| 122 | + |
| 123 | + stack_buffer = malloc(sizeof(void *) * mca_ompi_common_ubcl_component.n_addr); |
| 124 | + n_addr = backtrace(stack_buffer, mca_ompi_common_ubcl_component.n_addr); |
| 125 | + stack = backtrace_symbols(stack_buffer, n_addr); |
| 126 | + |
| 127 | + int char_per_line = 256; |
| 128 | + int n_char = char_per_line * n_addr + 1024; |
| 129 | + char *msg = malloc(n_char * sizeof(char)); |
| 130 | + |
| 131 | + if (NULL == stack || NULL == msg) { |
| 132 | + /* Output small error */ |
| 133 | + opal_output_verbose(verbose, output, |
| 134 | + "========\n== ERROR: Not enough memory while outputting error...\n== " |
| 135 | + "%s encountered an error (%d) at %s:%d\n========\n", |
| 136 | + comp_name, err, filename, line); |
| 137 | + } else { |
| 138 | + /* Output full error */ |
| 139 | + int current = 0; |
| 140 | + current += snprintf(msg + current, n_char - current, |
| 141 | + "========\n== %s encountered an error (%d) at %s:%d\n== %s:\n\t", |
| 142 | + comp_name, err, filename, line, abort ? "ERROR" : "WARNING"); |
| 143 | + va_list arglist; |
| 144 | + va_start(arglist, format); |
| 145 | + current += vsnprintf(msg + current, n_char - current, format, arglist); |
| 146 | + va_end(arglist); |
| 147 | + |
| 148 | + current += snprintf(msg + current, n_char - current, "\n== STACK:\n"); |
| 149 | + |
| 150 | + for (int i = 0; i < n_addr; i++) { |
| 151 | + size_t min_char = char_per_line < (n_char - current) ? char_per_line : n_char - current; |
| 152 | + current += snprintf(msg + current, min_char, "= [%2d] %s\n", i, |
| 153 | + stack[i]); |
| 154 | + } |
| 155 | + |
| 156 | + if (is_init && output > 0) { |
| 157 | + opal_output_verbose(verbose, output, |
| 158 | + "%s========", msg); |
| 159 | + } else if (abort || comp_verbose >= verbose) { |
| 160 | + fprintf(stderr, "%s\n", msg); |
| 161 | + fflush(stderr); |
| 162 | + } |
| 163 | + } |
| 164 | + |
| 165 | + if (abort) { |
| 166 | + OMPI_ERRHANDLER_INVOKE(&ompi_mpi_comm_world.comm, err, stack[0]); |
| 167 | + ompi_mpi_abort(&ompi_mpi_comm_world.comm, err); |
| 168 | + } |
| 169 | + |
| 170 | + free(stack_buffer); |
| 171 | + free(stack); |
| 172 | + free(msg); |
| 173 | +} |
0 commit comments