YAC 3.21.0
Yet Another Coupler
Loading...
Searching...
No Matches
yac_pak.c File Reference
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <limits.h>
#include <time.h>
#include "config.h"
#include "yac_config.h"
#include "yac_pak.h"
#include "yac_assert.h"
#include "yac_mpi_common.h"
#include "ensure_array_size.h"
#include "utils_core.h"
#include "utils_common.h"
#include "io_utils.h"
Include dependency graph for yac_pak.c:

Go to the source code of this file.

Data Structures

struct  yac_pak_timer_t
 
struct  yac_pak_event_info_t
 
struct  yac_pak_open_event_t
 
struct  yac_pak_str_t
 
struct  yac_pak_trace_entry_t
 
struct  yac_pak
 

Macros

#define YAC_PAK_TRACE_ENV   "YAC_PAK_TRACE"
 
#define YAC_PAK_TRACE_LEVEL_ENV   "YAC_PAK_TRACE_LEVEL"
 
#define YAC_PAK_TRACE_SETUP_ENV   "YAC_PAK_TRACE_SETUP"
 
#define YAC_PAK_TRACE_CAPACITY_ENV   "YAC_PAK_TRACE_CAPACITY"
 
#define YAC_PAK_TRACE_DIR_ENV   "YAC_PAK_TRACE_DIR"
 
#define YAC_PAK_TRACE_STRIDE_ENV   "YAC_PAK_TRACE_STRIDE"
 
#define YAC_PAK_TRACE_FLUSH_TIME_ENV   "YAC_PAK_TRACE_FLUSH_TIME"
 
#define YAC_PAK_TRACE_CONFIG_ENV   "YAC_PAK_TRACE_CONFIG"
 
#define YAC_PAK_TRACE_WRITE_MODE_ENV   "YAC_PAK_TRACE_WRITE_MODE"
 
#define YAC_PAK_TRACE_VERBOSE_ENV   "YAC_PAK_TRACE_VERBOSE"
 

Enumerations

enum  { YAC_PAK_TRACE_CAPACITY_DEFAULT = 4096 , YAC_PAK_TRACE_CAPACITY_MIN = 1 }
 
enum  yac_pak_output_mode_t { YAC_PAK_OUTPUT_FILE_PER_RANK }
 
enum  yac_pak_trace_write_mode_t { YAC_PAK_TRACE_WRITE_AT_FINALIZE , YAC_PAK_TRACE_WRITE_INSTANT }
 

Functions

 DEF_NAME_TYPE_PAIRS (yac_pak_event_type_pairs, DEF_NAME_TYPE_PAIR(INIT, YAC_PAK_EVENT_TYPE_INIT), DEF_NAME_TYPE_PAIR(DEF_COMP, YAC_PAK_EVENT_TYPE_DEF_COMP), DEF_NAME_TYPE_PAIR(SYNC_DEF, YAC_PAK_EVENT_TYPE_SYNC_DEF), DEF_NAME_TYPE_PAIR(ENDDEF, YAC_PAK_EVENT_TYPE_ENDDEF), DEF_NAME_TYPE_PAIR(FINALIZE, YAC_PAK_EVENT_TYPE_FINALIZE), DEF_NAME_TYPE_PAIR(GET, YAC_PAK_EVENT_TYPE_GET), DEF_NAME_TYPE_PAIR(AGET, YAC_PAK_EVENT_TYPE_AGET), DEF_NAME_TYPE_PAIR(PUT, YAC_PAK_EVENT_TYPE_PUT), DEF_NAME_TYPE_PAIR(REGION, YAC_PAK_EVENT_TYPE_REGION), DEF_NAME_TYPE_PAIR(UPDATE, YAC_PAK_EVENT_TYPE_UPDATE), DEF_NAME_TYPE_PAIR(WAIT, YAC_PAK_EVENT_TYPE_WAIT))
 
static int yac_pak_event_type_is_setup (yac_pak_event_type_t type)
 
 DEF_NAME_TYPE_PAIRS (yac_pak_trace_write_mode_pairs, DEF_NAME_TYPE_PAIR(at_finalize, YAC_PAK_TRACE_WRITE_AT_FINALIZE), DEF_NAME_TYPE_PAIR(instant, YAC_PAK_TRACE_WRITE_INSTANT))
 
static int directory_exists (char const *path)
 
static char const * get_component_name (struct yac_pak const *pak)
 
static int compute_is_writer (struct yac_pak const *pak)
 
static void pak_make_trace_dir (char const *path, int verbose)
 
static char * build_output_path_per_rank (struct yac_pak const *pak, char const *suffix, int rank)
 
static void str_appendf (yac_pak_str_t *str, char const *fmt,...) __attribute__((format(printf
 
static void append_trace_header (yac_pak_str_t *str, struct yac_pak const *pak, double flush_dur)
 
static void append_trace_row (yac_pak_str_t *str, struct yac_pak const *pak, yac_pak_trace_entry_t const *entry, int in_progress)
 
static void write_trace_row (FILE *out, struct yac_pak const *pak, yac_pak_trace_entry_t const *entry, int in_progress)
 
static void write_metadata_json_file (struct yac_pak const *pak, double flush_dur_rank0)
 
static void yac_pak_setup_trace_dir (struct yac_pak *pak)
 
static size_t get_finished_event_idx (struct yac_pak *pak)
 
static size_t get_open_event_idx (struct yac_pak *pak)
 
static void rewrite_open_file (struct yac_pak *pak)
 
static void write_trace_row_instant (struct yac_pak *pak, yac_pak_trace_entry_t const *entry)
 
static void rename_open_file (struct yac_pak const *pak, char **path, char const *suffix)
 
static void set_component_name (struct yac_pak *pak, char const *component)
 
static void open_instant_files (struct yac_pak *pak)
 
static void rewrite_instant_header (struct yac_pak *pak)
 
static void discard_instant_files (struct yac_pak *pak)
 
static void release_open_event (struct yac_pak *pak, size_t handle)
 
struct yac_pak * yac_pak_new (MPI_Comm comm, int capacity)
 Construct a new YAC PAK object.
 
void yac_pak_delete (struct yac_pak *pak)
 Destroy a YAC PAK object.
 
int yac_pak_trace_is_enabled (struct yac_pak const *pak)
 Event tracing support.
 
int yac_pak_setup_trace_is_enabled (struct yac_pak const *pak)
 Check whether setup-phase tracing is active.
 
int yac_pak_region_trace_is_enabled (struct yac_pak const *pak, yac_pak_trace_level_t level)
 Check whether region events at a given trace level will be recorded.
 
char const * yac_pak_get_config_output_path (struct yac_pak const *pak)
 Return the coupling configuration output file path if enabled.
 
void yac_pak_set_component (struct yac_pak *pak, char const *comp_name, int comp_rank, int comp_size)
 Set the component this process belongs to.
 
int yac_pak_trace_start_setup (struct yac_pak *pak, char const *name, yac_pak_event_type_t type)
 Setup-phase event tracing.
 
int yac_pak_trace_record (struct yac_pak *pak, char const *field, char const *component, char const *grid, yac_pak_event_type_t type, double tstart, double tend)
 Record a complete trace entry with explicit timestamps.
 
int yac_pak_trace_start_ex (struct yac_pak *pak, char const *field, char const *component, char const *grid, yac_pak_event_type_t type, int put_idx, char const *datetime, int action, yac_pak_trace_level_t level)
 Start a trace event with full metadata.
 
int yac_pak_trace_stop (struct yac_pak *pak, int handle)
 Stop a trace event.
 
int yac_pak_flush_trace (struct yac_pak *pak)
 Flush trace data to disk.
 
int yac_pak_register (struct yac_pak *pak, char const *name)
 Register a named timer.
 
int yac_pak_start (struct yac_pak *pak, int idx)
 Start a registered timer.
 
int yac_pak_stop (struct yac_pak *pak, int idx)
 Stop a registered timer.
 
int yac_pak_report (struct yac_pak *pak, FILE *out)
 Generate collective timer report.
 

Macro Definition Documentation

◆ YAC_PAK_TRACE_CAPACITY_ENV

#define YAC_PAK_TRACE_CAPACITY_ENV   "YAC_PAK_TRACE_CAPACITY"

Definition at line 66 of file yac_pak.c.

◆ YAC_PAK_TRACE_CONFIG_ENV

#define YAC_PAK_TRACE_CONFIG_ENV   "YAC_PAK_TRACE_CONFIG"

Definition at line 70 of file yac_pak.c.

◆ YAC_PAK_TRACE_DIR_ENV

#define YAC_PAK_TRACE_DIR_ENV   "YAC_PAK_TRACE_DIR"

Definition at line 67 of file yac_pak.c.

◆ YAC_PAK_TRACE_ENV

#define YAC_PAK_TRACE_ENV   "YAC_PAK_TRACE"

Definition at line 63 of file yac_pak.c.

◆ YAC_PAK_TRACE_FLUSH_TIME_ENV

#define YAC_PAK_TRACE_FLUSH_TIME_ENV   "YAC_PAK_TRACE_FLUSH_TIME"

Definition at line 69 of file yac_pak.c.

◆ YAC_PAK_TRACE_LEVEL_ENV

#define YAC_PAK_TRACE_LEVEL_ENV   "YAC_PAK_TRACE_LEVEL"

Definition at line 64 of file yac_pak.c.

◆ YAC_PAK_TRACE_SETUP_ENV

#define YAC_PAK_TRACE_SETUP_ENV   "YAC_PAK_TRACE_SETUP"

Definition at line 65 of file yac_pak.c.

◆ YAC_PAK_TRACE_STRIDE_ENV

#define YAC_PAK_TRACE_STRIDE_ENV   "YAC_PAK_TRACE_STRIDE"

Definition at line 68 of file yac_pak.c.

◆ YAC_PAK_TRACE_VERBOSE_ENV

#define YAC_PAK_TRACE_VERBOSE_ENV   "YAC_PAK_TRACE_VERBOSE"

Definition at line 72 of file yac_pak.c.

◆ YAC_PAK_TRACE_WRITE_MODE_ENV

#define YAC_PAK_TRACE_WRITE_MODE_ENV   "YAC_PAK_TRACE_WRITE_MODE"

Definition at line 71 of file yac_pak.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
YAC_PAK_TRACE_CAPACITY_DEFAULT 
YAC_PAK_TRACE_CAPACITY_MIN 

Definition at line 74 of file yac_pak.c.

◆ yac_pak_output_mode_t

Enumerator
YAC_PAK_OUTPUT_FILE_PER_RANK 

Definition at line 79 of file yac_pak.c.

◆ yac_pak_trace_write_mode_t

When event rows are written to the per-rank trace file.

Enumerator
YAC_PAK_TRACE_WRITE_AT_FINALIZE 
YAC_PAK_TRACE_WRITE_INSTANT 

Definition at line 84 of file yac_pak.c.

Function Documentation

◆ append_trace_header()

static void append_trace_header ( yac_pak_str_t * str,
struct yac_pak const * pak,
double flush_dur )
static

Append the comment header and the column names of a trace file.

Parameters
[in,out]strGrowing string
[in]pakYAC PAK object
[in]flush_durFlush duration to report, negative to omit it

Definition at line 327 of file yac_pak.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ append_trace_row()

static void append_trace_row ( yac_pak_str_t * str,
struct yac_pak const * pak,
yac_pak_trace_entry_t const * entry,
int in_progress )
static

Append one event row.

Single definition of the row format, so that the buffered and the instant write path cannot drift apart.

Parameters
[in,out]strGrowing string
[in]pakYAC PAK object
[in]entryEvent to render
[in]in_progressEvent has started but not ended: the tend and duration columns are left empty

Definition at line 362 of file yac_pak.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ build_output_path_per_rank()

static char * build_output_path_per_rank ( struct yac_pak const * pak,
char const * suffix,
int rank )
static

Definition at line 272 of file yac_pak.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compute_is_writer()

static int compute_is_writer ( struct yac_pak const * pak)
static

Definition at line 260 of file yac_pak.c.

Here is the caller graph for this function:

◆ DEF_NAME_TYPE_PAIRS() [1/2]

◆ DEF_NAME_TYPE_PAIRS() [2/2]

DEF_NAME_TYPE_PAIRS ( yac_pak_trace_write_mode_pairs ,
DEF_NAME_TYPE_PAIR(at_finalize, YAC_PAK_TRACE_WRITE_AT_FINALIZE) ,
DEF_NAME_TYPE_PAIR(instant, YAC_PAK_TRACE_WRITE_INSTANT)  )

Definition at line 224 of file yac_pak.c.

Here is the call graph for this function:

◆ directory_exists()

static int directory_exists ( char const * path)
static

Definition at line 250 of file yac_pak.c.

Here is the caller graph for this function:

◆ discard_instant_files()

static void discard_instant_files ( struct yac_pak * pak)
static

Definition at line 719 of file yac_pak.c.

Here is the caller graph for this function:

◆ get_component_name()

static char const * get_component_name ( struct yac_pak const * pak)
static

Definition at line 255 of file yac_pak.c.

Here is the caller graph for this function:

◆ get_finished_event_idx()

static size_t get_finished_event_idx ( struct yac_pak * pak)
static

Definition at line 508 of file yac_pak.c.

Here is the caller graph for this function:

◆ get_open_event_idx()

static size_t get_open_event_idx ( struct yac_pak * pak)
static

Definition at line 524 of file yac_pak.c.

Here is the caller graph for this function:

◆ open_instant_files()

static void open_instant_files ( struct yac_pak * pak)
static

Definition at line 656 of file yac_pak.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pak_make_trace_dir()

static void pak_make_trace_dir ( char const * path,
int verbose )
static

Definition at line 265 of file yac_pak.c.

Here is the caller graph for this function:

◆ release_open_event()

static void release_open_event ( struct yac_pak * pak,
size_t handle )
static

Definition at line 729 of file yac_pak.c.

Here is the caller graph for this function:

◆ rename_open_file()

static void rename_open_file ( struct yac_pak const * pak,
char ** path,
char const * suffix )
static

Rename an open file to the current component name. The descriptor keeps pointing at the same file.

Parameters
[in]pakYAC PAK object
[in,out]pathPath of the file, updated to the new name
[in]suffixFile name suffix, e.g. ".csv"

Definition at line 616 of file yac_pak.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rewrite_instant_header()

static void rewrite_instant_header ( struct yac_pak * pak)
static

Definition at line 681 of file yac_pak.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rewrite_open_file()

static void rewrite_open_file ( struct yac_pak * pak)
static

Rewrite the companion/debug file listing the events in progress.

The file is rewritten from scratch on every event start and end, so it always shows what this rank is doing right now. If the run hangs, its contents are the operations it is stuck in, a clean shutdown removes it.

Definition at line 565 of file yac_pak.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_component_name()

static void set_component_name ( struct yac_pak * pak,
char const * component )
static

Take the component name from the first event that carries one.

Later events may name a different component (a rank can serve several); only the first one names the files. The component of an individual event is always in its own "component" column.

In write mode "instant" the files were created before any component was defined, they still carry the placeholder name and are renamed here.

Definition at line 638 of file yac_pak.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ str_appendf()

static void static void str_appendf ( yac_pak_str_t * str,
char const * fmt,
... )
static

Append printf-style output to a growing heap string.

The string starts out empty (zero) and grows as needed, so no caller has to think about buffer sizes. Release it with free(str->buf).

Parameters
[in,out]strGrowing string
[in]fmtprintf-style format string

Definition at line 303 of file yac_pak.c.

Here is the caller graph for this function:

◆ write_metadata_json_file()

static void write_metadata_json_file ( struct yac_pak const * pak,
double flush_dur_rank0 )
static

Write trace_metadata.json (rank 0 only).

Parameters
[in]pakYAC PAK object
[in]flush_dur_rank0Flush duration to report, negative to omit it

Definition at line 405 of file yac_pak.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_trace_row()

static void write_trace_row ( FILE * out,
struct yac_pak const * pak,
yac_pak_trace_entry_t const * entry,
int in_progress )
static

Write one event row to a stream.

Parameters
[in]outOutput stream
[in]pakYAC PAK object
[in]entryEvent to write
[in]in_progressEvent has started but not ended

Definition at line 389 of file yac_pak.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_trace_row_instant()

static void write_trace_row_instant ( struct yac_pak * pak,
yac_pak_trace_entry_t const * entry )
static

Append a finished event and make it visible.

Definition at line 598 of file yac_pak.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_pak_event_type_is_setup()

static int yac_pak_event_type_is_setup ( yac_pak_event_type_t type)
static

Definition at line 216 of file yac_pak.c.

Here is the caller graph for this function:

◆ yac_pak_setup_trace_dir()

static void yac_pak_setup_trace_dir ( struct yac_pak * pak)
static

Definition at line 438 of file yac_pak.c.

Here is the call graph for this function:
Here is the caller graph for this function: