1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
|
/*
* Copyright (c) 2013-2016 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2013-2018 Inria. All rights reserved.
* Copyright (c) 2015 Bull SAS. All rights reserved.
* Copyright (c) 2016-2019 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include "common_monitoring.h"
#include "common_monitoring_coll.h"
#include "ompi/constants.h"
#include "ompi/communicator/communicator.h"
#include "opal/mca/base/mca_base_component_repository.h"
#include "opal/class/opal_hash_table.h"
#include <assert.h>
/*** Monitoring specific variables ***/
struct mca_monitoring_coll_data_t {
opal_object_t super;
char*procs;
char*comm_name;
int world_rank;
int is_released;
ompi_communicator_t*p_comm;
opal_atomic_size_t o2a_count;
opal_atomic_size_t o2a_size;
opal_atomic_size_t a2o_count;
opal_atomic_size_t a2o_size;
opal_atomic_size_t a2a_count;
opal_atomic_size_t a2a_size;
};
/* Collectives operation monitoring */
static opal_hash_table_t *comm_data = NULL;
int mca_common_monitoring_coll_cache_name(ompi_communicator_t*comm)
{
mca_monitoring_coll_data_t*data;
int ret = opal_hash_table_get_value_uint64(comm_data, *((uint64_t*)&comm), (void*)&data);
if( OPAL_SUCCESS == ret ) {
data->comm_name = strdup(comm->c_name);
data->p_comm = NULL;
}
return ret;
}
static inline void mca_common_monitoring_coll_cache(mca_monitoring_coll_data_t*data)
{
if( -1 == data->world_rank ) {
/* Get current process world_rank */
mca_common_monitoring_get_world_rank(ompi_comm_rank(data->p_comm),
data->p_comm->c_remote_group,
&data->world_rank);
}
/* Only list procs if the hashtable is already initialized,
i.e. if the previous call worked */
if( (-1 != data->world_rank) && (NULL == data->procs || 0 == strlen(data->procs)) ) {
int i, pos = 0, size, world_size = -1, max_length, world_rank;
char*tmp_procs;
size = ompi_comm_size(data->p_comm);
world_size = ompi_comm_size((ompi_communicator_t*)&ompi_mpi_comm_world) - 1;
assert( 0 < size );
/* Allocate enough space for list (add 1 to keep the final '\0' if already exact size) */
max_length = snprintf(NULL, 0, "%d,", world_size - 1) + 1;
tmp_procs = malloc((1 + max_length * size) * sizeof(char));
if( NULL == tmp_procs ) {
OPAL_MONITORING_PRINT_ERR("Cannot allocate memory for caching proc list.");
} else {
tmp_procs[0] = '\0';
/* Build procs list */
for(i = 0; i < size; ++i) {
if( OPAL_SUCCESS == mca_common_monitoring_get_world_rank(i, data->p_comm->c_remote_group, &world_rank) )
pos += sprintf(&tmp_procs[pos], "%d,", world_rank);
}
tmp_procs[pos - 1] = '\0'; /* Remove final coma */
data->procs = realloc(tmp_procs, pos * sizeof(char)); /* Adjust to size required */
}
}
}
mca_monitoring_coll_data_t*mca_common_monitoring_coll_new( ompi_communicator_t*comm )
{
mca_monitoring_coll_data_t*data = OBJ_NEW(mca_monitoring_coll_data_t);
if( NULL == data ) {
OPAL_MONITORING_PRINT_ERR("coll: new: data structure cannot be allocated");
return NULL;
}
data->p_comm = comm;
/* Allocate hashtable */
if( NULL == comm_data ) {
comm_data = OBJ_NEW(opal_hash_table_t);
if( NULL == comm_data ) {
OPAL_MONITORING_PRINT_ERR("coll: new: failed to allocate hashtable");
return data;
}
opal_hash_table_init(comm_data, 2048);
}
/* Insert in hashtable */
uint64_t key = *((uint64_t*)&comm);
if( OPAL_SUCCESS != opal_hash_table_set_value_uint64(comm_data, key, (void*)data) ) {
OPAL_MONITORING_PRINT_ERR("coll: new: failed to allocate memory or "
"growing the hash table");
}
/* Cache data so the procs can be released without affecting the output */
mca_common_monitoring_coll_cache(data);
return data;
}
void mca_common_monitoring_coll_release(mca_monitoring_coll_data_t*data)
{
#if OPAL_ENABLE_DEBUG
if( NULL == data ) {
OPAL_MONITORING_PRINT_ERR("coll: release: data structure empty or already deallocated");
return;
}
#endif /* OPAL_ENABLE_DEBUG */
/* not flushed yet */
data->is_released = 1;
mca_common_monitoring_coll_cache(data);
}
static void mca_common_monitoring_coll_cond_release(mca_monitoring_coll_data_t*data)
{
#if OPAL_ENABLE_DEBUG
if( NULL == data ) {
OPAL_MONITORING_PRINT_ERR("coll: release: data structure empty or already deallocated");
return;
}
#endif /* OPAL_ENABLE_DEBUG */
if( data->is_released ) { /* if the communicator is already released */
opal_hash_table_remove_value_uint64(comm_data, *((uint64_t*)&data->p_comm));
data->p_comm = NULL;
free(data->comm_name);
free(data->procs);
OBJ_RELEASE(data);
}
}
void mca_common_monitoring_coll_finalize( void )
{
if( NULL != comm_data ) {
opal_hash_table_remove_all( comm_data );
OBJ_RELEASE(comm_data);
}
}
void mca_common_monitoring_coll_flush(FILE *pf, mca_monitoring_coll_data_t*data)
{
/* Flush data */
fprintf(pf,
"D\t%s\tprocs: %s\n"
"O2A\t%" PRId32 "\t%zu bytes\t%zu msgs sent\n"
"A2O\t%" PRId32 "\t%zu bytes\t%zu msgs sent\n"
"A2A\t%" PRId32 "\t%zu bytes\t%zu msgs sent\n",
data->comm_name ? data->comm_name : data->p_comm ?
data->p_comm->c_name : "(no-name)", data->procs,
data->world_rank, data->o2a_size, data->o2a_count,
data->world_rank, data->a2o_size, data->a2o_count,
data->world_rank, data->a2a_size, data->a2a_count);
}
void mca_common_monitoring_coll_flush_all(FILE *pf)
{
if( NULL == comm_data ) return; /* No hashtable */
uint64_t key;
mca_monitoring_coll_data_t*previous = NULL, *data;
OPAL_HASH_TABLE_FOREACH(key, uint64, data, comm_data) {
if( NULL != previous && NULL == previous->p_comm ) {
/* Phase flushed -> free already released once coll_data_t */
mca_common_monitoring_coll_cond_release(previous);
}
mca_common_monitoring_coll_flush(pf, data);
previous = data;
}
mca_common_monitoring_coll_cond_release(previous);
}
void mca_common_monitoring_coll_reset(void)
{
if( NULL == comm_data ) return; /* No hashtable */
uint64_t key;
mca_monitoring_coll_data_t*data;
OPAL_HASH_TABLE_FOREACH(key, uint64, data, comm_data) {
data->o2a_count = 0; data->o2a_size = 0;
data->a2o_count = 0; data->a2o_size = 0;
data->a2a_count = 0; data->a2a_size = 0;
}
}
int mca_common_monitoring_coll_messages_notify(mca_base_pvar_t *pvar,
mca_base_pvar_event_t event,
void *obj_handle,
int *count)
{
switch (event) {
case MCA_BASE_PVAR_HANDLE_BIND:
*count = 1;
case MCA_BASE_PVAR_HANDLE_UNBIND:
return OMPI_SUCCESS;
case MCA_BASE_PVAR_HANDLE_START:
mca_common_monitoring_current_state = mca_common_monitoring_enabled;
return OMPI_SUCCESS;
case MCA_BASE_PVAR_HANDLE_STOP:
mca_common_monitoring_current_state = 0;
return OMPI_SUCCESS;
}
return OMPI_ERROR;
}
void mca_common_monitoring_coll_o2a(size_t size, mca_monitoring_coll_data_t*data)
{
if( 0 == mca_common_monitoring_current_state ) return; /* right now the monitoring is not started */
#if OPAL_ENABLE_DEBUG
if( NULL == data ) {
OPAL_MONITORING_PRINT_ERR("coll: o2a: data structure empty");
return;
}
#endif /* OPAL_ENABLE_DEBUG */
opal_atomic_add_fetch_size_t(&data->o2a_size, size);
opal_atomic_add_fetch_size_t(&data->o2a_count, 1);
}
int mca_common_monitoring_coll_get_o2a_count(const struct mca_base_pvar_t *pvar,
void *value,
void *obj_handle)
{
ompi_communicator_t *comm = (ompi_communicator_t *) obj_handle;
size_t *value_size = (size_t*) value;
mca_monitoring_coll_data_t*data;
int ret = opal_hash_table_get_value_uint64(comm_data, *((uint64_t*)&comm), (void*)&data);
if( OPAL_SUCCESS == ret ) {
*value_size = data->o2a_count;
}
return ret;
}
int mca_common_monitoring_coll_get_o2a_size(const struct mca_base_pvar_t *pvar,
void *value,
void *obj_handle)
{
ompi_communicator_t *comm = (ompi_communicator_t *) obj_handle;
size_t *value_size = (size_t*) value;
mca_monitoring_coll_data_t*data;
int ret = opal_hash_table_get_value_uint64(comm_data, *((uint64_t*)&comm), (void*)&data);
if( OPAL_SUCCESS == ret ) {
*value_size = data->o2a_size;
}
return ret;
}
void mca_common_monitoring_coll_a2o(size_t size, mca_monitoring_coll_data_t*data)
{
if( 0 == mca_common_monitoring_current_state ) return; /* right now the monitoring is not started */
#if OPAL_ENABLE_DEBUG
if( NULL == data ) {
OPAL_MONITORING_PRINT_ERR("coll: a2o: data structure empty");
return;
}
#endif /* OPAL_ENABLE_DEBUG */
opal_atomic_add_fetch_size_t(&data->a2o_size, size);
opal_atomic_add_fetch_size_t(&data->a2o_count, 1);
}
int mca_common_monitoring_coll_get_a2o_count(const struct mca_base_pvar_t *pvar,
void *value,
void *obj_handle)
{
ompi_communicator_t *comm = (ompi_communicator_t *) obj_handle;
size_t *value_size = (size_t*) value;
mca_monitoring_coll_data_t*data;
int ret = opal_hash_table_get_value_uint64(comm_data, *((uint64_t*)&comm), (void*)&data);
if( OPAL_SUCCESS == ret ) {
*value_size = data->a2o_count;
}
return ret;
}
int mca_common_monitoring_coll_get_a2o_size(const struct mca_base_pvar_t *pvar,
void *value,
void *obj_handle)
{
ompi_communicator_t *comm = (ompi_communicator_t *) obj_handle;
size_t *value_size = (size_t*) value;
mca_monitoring_coll_data_t*data;
int ret = opal_hash_table_get_value_uint64(comm_data, *((uint64_t*)&comm), (void*)&data);
if( OPAL_SUCCESS == ret ) {
*value_size = data->a2o_size;
}
return ret;
}
void mca_common_monitoring_coll_a2a(size_t size, mca_monitoring_coll_data_t*data)
{
if( 0 == mca_common_monitoring_current_state ) return; /* right now the monitoring is not started */
#if OPAL_ENABLE_DEBUG
if( NULL == data ) {
OPAL_MONITORING_PRINT_ERR("coll: a2a: data structure empty");
return;
}
#endif /* OPAL_ENABLE_DEBUG */
opal_atomic_add_fetch_size_t(&data->a2a_size, size);
opal_atomic_add_fetch_size_t(&data->a2a_count, 1);
}
int mca_common_monitoring_coll_get_a2a_count(const struct mca_base_pvar_t *pvar,
void *value,
void *obj_handle)
{
ompi_communicator_t *comm = (ompi_communicator_t *) obj_handle;
size_t *value_size = (size_t*) value;
mca_monitoring_coll_data_t*data;
int ret = opal_hash_table_get_value_uint64(comm_data, *((uint64_t*)&comm), (void*)&data);
if( OPAL_SUCCESS == ret ) {
*value_size = data->a2a_count;
}
return ret;
}
int mca_common_monitoring_coll_get_a2a_size(const struct mca_base_pvar_t *pvar,
void *value,
void *obj_handle)
{
ompi_communicator_t *comm = (ompi_communicator_t *) obj_handle;
size_t *value_size = (size_t*) value;
mca_monitoring_coll_data_t*data;
int ret = opal_hash_table_get_value_uint64(comm_data, *((uint64_t*)&comm), (void*)&data);
if( OPAL_SUCCESS == ret ) {
*value_size = data->a2a_size;
}
return ret;
}
static void mca_monitoring_coll_construct (mca_monitoring_coll_data_t*coll_data)
{
coll_data->procs = NULL;
coll_data->comm_name = NULL;
coll_data->world_rank = -1;
coll_data->p_comm = NULL;
coll_data->is_released = 0;
coll_data->o2a_count = 0;
coll_data->o2a_size = 0;
coll_data->a2o_count = 0;
coll_data->a2o_size = 0;
coll_data->a2a_count = 0;
coll_data->a2a_size = 0;
}
static void mca_monitoring_coll_destruct (mca_monitoring_coll_data_t*coll_data){}
OBJ_CLASS_INSTANCE(mca_monitoring_coll_data_t, opal_object_t, mca_monitoring_coll_construct, mca_monitoring_coll_destruct);
|