-
Notifications
You must be signed in to change notification settings - Fork 1
/
settings.c
120 lines (108 loc) · 4.62 KB
/
settings.c
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
/**
* (C) Copyright 2024 Hewlett Packard Enterprise Development LP
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************
* hpcat: display NUMA and CPU affinities in the context of HPC applications
* settings.c: Application specific settings and user defined parameters.
*
* URL https://github.com/HewlettPackard/hpcat
******************************************************************************/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <argp.h>
#include "settings.h"
const char *argp_program_version = HPCAT_VERSION;
const char *argp_program_bug_address = HPCAT_CONTACT;
/* Program documentation */
static char doc[] = "This application is designed to display NUMA and CPU affinities in the context "
"of HPC applications. Details about, MPI tasks, OpenMP (automatically enabled if "
"OMP_NUM_THREADS is set), accelerators (automatically enabled if GPUs are detected) "
"and network interfaces (Cray MPICH only, starting from 2 nodes) are reported. "
"The application only shows detected affinities but parameters can be used to "
"force enabling/disabling details. It accepts the following arguments:";
/* A description of the arguments we accept (in addition to the options) */
static char args_doc[] = " ";
/* Options */
static struct argp_option options[] =
{
{"enable-omp", 11, 0, 0, "Enable display of OpenMP affinities"},
{"disable-omp", 21, 0, 0, "Disable display of OpenMP affinities"},
{"disable-accel", 22, 0, 0, "Disable display of GPU affinities"},
{"disable-nic", 23, 0, 0, "Disable display of Network Interface affinities"},
{"no-banner", 31, 0, 0, "Do not display header and footer banners"},
{"verbose", 'v', 0, 0, "Make the operation more talkative"},
{"yaml", 'y', 0, 0, "YAML output"},
{0}
};
/* Parse a single option */
static error_t parse_opt(int key, char *arg, struct argp_state *state)
{
HpcatSettings_t *settings = (HpcatSettings_t *)state->input;
switch (key)
{
case 11:
settings->enable_omp = true;
break;
case 21:
settings->enable_omp = false;
break;
case 22:
settings->enable_accel = false;
break;
case 23:
settings->enable_nic = false;
break;
case 31:
settings->enable_banner = false;
break;
case 'v':
settings->enable_verbose = true;
break;
case 'y':
settings->output_type = YAML;
break;
case ARGP_KEY_END:
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
/* Argp parser */
static struct argp argp = { options, parse_opt, args_doc, doc };
/**
* Initialize settings / parsing arguments
*
* @param argc[in] Amount of arguments
* @param argv[in] Array of arguments
* @param hpcat_args[out] Application settings structure
*/
void hpcat_settings_init(int argc, char *argv[], HpcatSettings_t *hpcat_settings)
{
/* Set defaults and auto-detect */
hpcat_settings->output_type = STDOUT;
hpcat_settings->enable_accel = true;
hpcat_settings->enable_banner = true;
hpcat_settings->enable_nic = true;
hpcat_settings->enable_omp = (getenv("OMP_NUM_THREADS") != NULL);
hpcat_settings->enable_verbose = false;
argp_parse(&argp, argc, argv, 0, 0, hpcat_settings);
}