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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2006 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2011 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015-2020 Intel, Inc. All rights reserved.
* Copyright (c) 2016 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2021-2022 Nanook Consulting. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/** @file
* PMIX output stream facility.
*
* The PMIX output stream facility is used to send output from the PMIX
* libraries to output devices. It is meant to fully replace all
* forms of printf() (and friends). Output streams are opened via the
* pmix_output_open() function call, and then sent output via
* pmix_output_verbose(), PMIX_OUTPUT(), and pmix_output(). Streams are
* closed with pmix_output_close().
*
* Streams can multiplex output to several kinds of outputs (one of
* each):
*
* - the syslog (if available)
* - standard output
* - standard error
* - file
*
* Which outputs to use are specified during pmix_output_open().
*
* WARNING: When using "file" as an output destination, be aware that
* the file may not exist until the session directory for the process
* exists. This is at least part of the way through MPI_INIT (for
* example). Most MCA components and internals of PMIx won't be
* affected by this, but some RTE / startup aspects of PMIx will
* not be able to write to a file for output. See pmix_output() for
* details on what happens in these cases.
*
* pmix_output_open() returns an integer handle that is used in
* successive calls to PMIX_OUTPUT() and pmix_output() to send output to
* the stream.
*
* The default "verbose" stream is opened after invoking
* pmix_output_init() (and closed after invoking
* pmix_output_finalize()). This stream outputs to stderr only, and
* has a stream handle ID of 0.
*
* It is erroneous to have one thread close a stream and have another
* try to write to it. Multiple threads writing to a single stream
* will be serialized in an unspecified order.
*/
/* There are systems where all output needs to be redirected to syslog
* and away from stdout/stderr or files - e.g., embedded systems whose
* sole file system is in flash. To support such systems, we provide
* the following environmental variables that support redirecting -all-
* output (both from pmix_output and stdout/stderr of processes) to
* syslog:
*
* PMIX_OUTPUT_REDIRECT - set to "syslog" to redirect to syslog. Other
* options may someday be supported
* PMIX_OUTPUT_SYSLOG_PRI - set to "info", "error", or "warn" to have
* output sent to syslog at that priority
* PMIX_OUTPUT_SYSLOG_IDENT - a string identifier for the log
*
* We also define two global variables that notify all other
* layers that output is being redirected to syslog at the given
* priority. These are used, for example, by the IO forwarding
* subsystem to tell it to dump any collected output directly to
* syslog instead of forwarding it to another location.
*/
PMIX_EXPORT extern bool pmix_output_redirected_to_syslog;
PMIX_EXPORT extern int pmix_output_redirected_syslog_pri;
/**
* \class pmix_output_stream_t
*
* Structure used to request the opening of a PMIX output stream. A
* pointer to this structure is passed to pmix_output_open() to tell
* the pmix_output subsystem where to send output for a given stream.
* It is valid to specify multiple destinations of output for a stream
* -- output streams can be multiplexed to multiple different
* destinations through the pmix_output facility.
*
* Note that all strings in this struct are cached on the stream by
* value; there is no need to keep them allocated after the return
* from pmix_output_open().
*/
;
/**
* Convenience typedef
*/
typedef struct pmix_output_stream_t pmix_output_stream_t;
/* tracking structure */
typedef struct pmix_output_desc_t;
PMIX_EXPORT extern pmix_output_desc_t pmix_output_info;
/**
* Initializes the output stream system and opens a default
* "verbose" stream.
*
* @retval true Upon success.
* @retval false Upon failure.
*
* This should be the first function invoked in the output
* subsystem. After this call, the default "verbose" stream is open
* and can be written to via calls to pmix_output_verbose() and
* pmix_output_error().
*
* By definition, the default verbose stream has a handle ID of 0,
* and has a verbose level of 0.
*/
PMIX_EXPORT bool ;
/**
* Shut down the output stream system.
*
* Shut down the output stream system, including the default verbose
* stream.
*/
PMIX_EXPORT void ;
/**
* Opens an output stream.
*
* @param lds A pointer to pmix_output_stream_t describing what the
* characteristics of the output stream should be.
*
* This function opens an output stream and returns an integer
* handle. The caller is responsible for maintaining the handle and
* using it in successive calls to PMIX_OUTPUT(), pmix_output(),
* pmix_output_switch(), and pmix_output_close().
*
* If lds is NULL, the default descriptions will be used, meaning
* that output will only be sent to stderr.
*
* It is safe to have multiple threads invoke this function
* simultaneously; their execution will be serialized in an
* unspecified manner.
*
* Be sure to see pmix_output() for a description of what happens
* when open_open() / pmix_output() is directed to send output to a
* file but the process session directory does not yet exist.
*/
PMIX_EXPORT int ;
/**
* Re-opens / redirects an output stream.
*
* @param output_id Stream handle to reopen
* @param lds A pointer to pmix_output_stream_t describing what the
* characteristics of the reopened output stream should be.
*
* This function redirects an existing stream into a new [set of]
* location[s], as specified by the lds parameter. If the output_id
* passed is invalid, this call is effectively the same as opening a
* new stream with a specific stream handle.
*/
PMIX_EXPORT int ;
/**
* Enables and disables output streams.
*
* @param output_id Stream handle to switch
* @param enable Boolean indicating whether to enable the stream
* output or not.
*
* @returns The previous enable state of the stream (true == enabled,
* false == disabled).
*
* The output of a stream can be temporarily disabled by passing an
* enable value to false, and later resumed by passing an enable
* value of true. This does not close the stream -- it simply tells
* the pmix_output subsystem to intercept and discard any output sent
* to the stream via PMIX_OUTPUT() or pmix_output() until the output
* is re-enabled.
*/
PMIX_EXPORT bool ;
/**
* \internal
*
* Reopens all existing output streams.
*
* This function should never be called by user applications; it is
* typically only invoked after a restart (i.e., in a new process)
* where output streams need to be re-initialized.
*/
PMIX_EXPORT void ;
/**
* Close an output stream.
*
* @param output_id Handle of the stream to close.
*
* Close an output stream. No output will be sent to the stream
* after it is closed. Be aware that pmix_output_handles tend to be
* re-used; it is possible that after a stream is closed, if another
* stream is opened, it will get the same handle value.
*/
PMIX_EXPORT void ;
/**
* Main function to send output to a stream.
*
* @param output_id Stream id returned from pmix_output_open().
* @param format printf-style format string.
* @param varargs printf-style varargs list to fill the string
* specified by the format parameter.
*
* This is the main function to send output to custom streams (note
* that output to the default "verbose" stream is handled through
* pmix_output_verbose() and pmix_output_error()).
*
* It is never necessary to send a trailing "\n" in the strings to
* this function; some streams requires newlines, others do not --
* this function will append newlines as necessary.
*
* Verbosity levels are ignored in this function.
*
* Note that for output streams that are directed to files, the
* files are stored under the process' session directory. If the
* session directory does not exist when pmix_output() is invoked,
* the output will be discarded! Once the session directory is
* created, pmix_output() will automatically create the file and
* writing to it.
*/
PMIX_EXPORT void ;
/**
* Send output to a stream only if the passed verbosity level is
* high enough.
*
* @param output_id Stream id returned from pmix_output_open().
* @param level Target verbosity level.
* @param format printf-style format string.
* @param varargs printf-style varargs list to fill the string
* specified by the format parameter.
*
* Output is only sent to the stream if the current verbosity level
* is greater than or equal to the level parameter. This mechanism
* can be used to send "information" kinds of output to user
* applications, but only when the user has asked for a high enough
* verbosity level.
*
* It is never necessary to send a trailing "\n" in the strings to
* this function; some streams requires newlines, others do not --
* this function will append newlines as necessary.
*
* This function is really a convenience wrapper around checking the
* current verbosity level set on the stream, and if the passed
* level is less than or equal to the stream's verbosity level, this
* function will effectively invoke pmix_output to send the output to
* the stream.
*
* @see pmix_output_set_verbosity()
*/
/* protect legacy users */
/**
* Set the verbosity level for a stream.
*
* @param output_id Stream id returned from pmix_output_open().
* @param level New verbosity level
*
* This function sets the verbosity level on a given stream. It
* will be used for all future invocations of pmix_output_verbose().
*/
PMIX_EXPORT void ;
/**
* Get the verbosity level for a stream
*
* @param output_id Stream id returned from pmix_output_open()
* @returns Verbosity of stream
*/
PMIX_EXPORT int ;
/**
* Set characteristics for output files.
*
* @param dir Directory where output files will go
* @param olddir If non-NULL, the directory where output files
* were previously opened
* @param prefix Prefix of files in the output directory
* @param oldprefix If non-NULL, the old prefix
*
* This function controls the final filename used for all new
* output streams that request output files. Specifically, when
* pmix_output_stream_t::lds_want_file is true, the output
* filename will be of the form $dir/$prefix$suffix.
*
* The default value for the output directory is whatever is
* specified in the TMPDIR environment variable if it exists, or
* $HOME if it does not. The default value for the prefix is
* "output-pid<pid>-" (where "<pid>" is replaced by the PID of the
* current process).
*
* If dir or prefix are NULL, new values are not set. The strings
* represented by dir and prefix are copied into internal storage;
* it is safe to pass string constants or free() these values
* after pmix_output_set_output_file_info() returns.
*
* If olddir or oldprefix are not NULL, copies of the old
* directory and prefix (respectively) are returned in these
* parameters. The caller is responsible for calling (free) on
* these values. This allows one to get the old values, output an
* output file in a specific directory and/or with a specific
* prefix, and then restore the old values.
*
* Note that this function only affects the creation of \em new
* streams -- streams that have already started writing to output
* files are not affected (i.e., their output files are not moved
* to the new directory). More specifically, the pmix_output
* system only opens/creates output files lazily -- so calling
* this function affects both new streams \em and any stream that
* was previously opened but had not yet output anything.
*/
PMIX_EXPORT void ;
/**
* Same as pmix_output_verbose(), but pointer to buffer and size.
*/
PMIX_EXPORT void ;
/**
* Declare the class of this type. Note that the constructor for
* this class is for convenience only -- it is \em not necessary
* to be invoked. If the constructor it used, it sets all values
* in the struct to be false / 0 (i.e., turning off all output).
* The intended usage is to invoke the constructor and then enable
* the output fields that you want.
*/
PMIX_EXPORT ;
/* PMIX_OUTPUT_H_ */