15
15
* Copyright (c) 2011 Oak Ridge National Labs. All rights reserved.
16
16
* Copyright (c) 2013-2019 Intel, Inc. All rights reserved.
17
17
* Copyright (c) 2015 Mellanox Technologies, Inc. All rights reserved.
18
+ * Copyright (c) 2021 Nanook Consulting. All rights reserved.
18
19
* $COPYRIGHT$
19
20
*
20
21
* Additional copyrights may follow
26
27
#include <stdbool.h>
27
28
#include <stdio.h>
28
29
#include <stdlib.h>
29
- #include <unistd.h>
30
30
#include <time.h>
31
+ #include <unistd.h>
31
32
32
- #include <pmix.h>
33
33
#include "examples.h"
34
+ #include <pmix.h>
34
35
35
36
/* this is a callback function for the PMIx_Query and
36
37
* PMIx_Allocate APIs. The query will callback with a status indicating
44
45
* Once we have dealt with the returned data, we must
45
46
* call the release_fn so that the PMIx library can
46
47
* cleanup */
47
- static void infocbfunc (pmix_status_t status ,
48
- pmix_info_t * info , size_t ninfo ,
49
- void * cbdata ,
50
- pmix_release_cbfunc_t release_fn ,
51
- void * release_cbdata )
48
+ static void infocbfunc (pmix_status_t status , pmix_info_t * info , size_t ninfo , void * cbdata ,
49
+ pmix_release_cbfunc_t release_fn , void * release_cbdata )
52
50
{
53
- myquery_data_t * mq = (myquery_data_t * ) cbdata ;
51
+ myquery_data_t * mq = (myquery_data_t * ) cbdata ;
54
52
size_t n ;
55
53
56
54
fprintf (stderr , "Allocation request returned %s\n" , PMIx_Error_string (status ));
@@ -61,7 +59,7 @@ static void infocbfunc(pmix_status_t status,
61
59
if (0 < ninfo ) {
62
60
PMIX_INFO_CREATE (mq -> info , ninfo );
63
61
mq -> ninfo = ninfo ;
64
- for (n = 0 ; n < ninfo ; n ++ ) {
62
+ for (n = 0 ; n < ninfo ; n ++ ) {
65
63
fprintf (stderr , "Transferring %s\n" , info [n ].key );
66
64
PMIX_INFO_XFER (& mq -> info [n ], & info [n ]);
67
65
}
@@ -86,22 +84,19 @@ static void infocbfunc(pmix_status_t status,
86
84
* the status to see if it was "alloc complete", but it often is simpler
87
85
* to declare a use-specific notification callback point. In this case,
88
86
* we are asking to know when the allocation request completes */
89
- static void release_fn (size_t evhdlr_registration_id ,
90
- pmix_status_t status ,
91
- const pmix_proc_t * source ,
92
- pmix_info_t info [], size_t ninfo ,
87
+ static void release_fn (size_t evhdlr_registration_id , pmix_status_t status ,
88
+ const pmix_proc_t * source , pmix_info_t info [], size_t ninfo ,
93
89
pmix_info_t results [], size_t nresults ,
94
- pmix_event_notification_cbfunc_fn_t cbfunc ,
95
- void * cbdata )
90
+ pmix_event_notification_cbfunc_fn_t cbfunc , void * cbdata )
96
91
{
97
92
myrel_t * lock ;
98
93
size_t n ;
99
94
100
95
/* find the return object */
101
96
lock = NULL ;
102
- for (n = 0 ; n < ninfo ; n ++ ) {
97
+ for (n = 0 ; n < ninfo ; n ++ ) {
103
98
if (0 == strncmp (info [n ].key , PMIX_EVENT_RETURN_OBJECT , PMIX_MAX_KEYLEN )) {
104
- lock = (myrel_t * ) info [n ].value .data .ptr ;
99
+ lock = (myrel_t * ) info [n ].value .data .ptr ;
105
100
break ;
106
101
}
107
102
}
@@ -134,15 +129,13 @@ static void release_fn(size_t evhdlr_registration_id,
134
129
* to the registered event. The index is used later on to deregister
135
130
* an event handler - if we don't explicitly deregister it, then the
136
131
* PMIx server will do so when it sees us exit */
137
- static void evhandler_reg_callbk (pmix_status_t status ,
138
- size_t evhandler_ref ,
139
- void * cbdata )
132
+ static void evhandler_reg_callbk (pmix_status_t status , size_t evhandler_ref , void * cbdata )
140
133
{
141
- mylock_t * lock = (mylock_t * ) cbdata ;
134
+ mylock_t * lock = (mylock_t * ) cbdata ;
142
135
143
136
if (PMIX_SUCCESS != status ) {
144
- fprintf (stderr , "EVENT HANDLER REGISTRATION FAILED WITH STATUS %d, ref=%lu\n" ,
145
- status , (unsigned long )evhandler_ref );
137
+ fprintf (stderr , "EVENT HANDLER REGISTRATION FAILED WITH STATUS %d, ref=%lu\n" , status ,
138
+ (unsigned long ) evhandler_ref );
146
139
}
147
140
lock -> status = status ;
148
141
lock -> evhandler_ref = evhandler_ref ;
@@ -168,17 +161,19 @@ int main(int argc, char **argv)
168
161
169
162
/* init us */
170
163
if (PMIX_SUCCESS != (rc = PMIx_Init (& myproc , NULL , 0 ))) {
171
- fprintf (stderr , "Client ns %s rank %d: PMIx_Init failed: %d\n" , myproc .nspace , myproc .rank , rc );
164
+ fprintf (stderr , "Client ns %s rank %d: PMIx_Init failed: %d\n" , myproc .nspace , myproc .rank ,
165
+ rc );
172
166
exit (0 );
173
167
}
174
168
fprintf (stderr , "Client ns %s rank %d: Running\n" , myproc .nspace , myproc .rank );
175
169
176
170
/* get our job size */
177
171
PMIX_PROC_CONSTRUCT (& proc );
178
- (void )strncpy (proc .nspace , myproc .nspace , PMIX_MAX_NSLEN );
172
+ (void ) strncpy (proc .nspace , myproc .nspace , PMIX_MAX_NSLEN );
179
173
proc .rank = PMIX_RANK_WILDCARD ;
180
174
if (PMIX_SUCCESS != (rc = PMIx_Get (& proc , PMIX_JOB_SIZE , NULL , 0 , & val ))) {
181
- fprintf (stderr , "Client ns %s rank %d: PMIx_Get job size failed: %d\n" , myproc .nspace , myproc .rank , rc );
175
+ fprintf (stderr , "Client ns %s rank %d: PMIx_Get job size failed: %d\n" , myproc .nspace ,
176
+ myproc .rank , rc );
182
177
goto done ;
183
178
}
184
179
nprocs = val -> data .uint32 ;
@@ -191,19 +186,20 @@ int main(int argc, char **argv)
191
186
PMIX_INFO_CREATE (info , 2 );
192
187
PMIX_INFO_LOAD (& info [0 ], PMIX_ALLOC_NUM_NODES , & nnodes , PMIX_UINT64 );
193
188
PMIX_INFO_LOAD (& info [0 ], PMIX_ALLOC_ID , myallocation , PMIX_STRING );
194
- if (PMIX_SUCCESS != (rc = PMIx_Allocation_request_nb (PMIX_ALLOC_NEW , info , 2 , infocbfunc , & mydata ))) {
195
- fprintf (stderr , "Client ns %s rank %d: PMIx_Allocation_request_nb failed: %d\n" , myproc .nspace , myproc .rank , rc );
189
+ if (PMIX_SUCCESS
190
+ != (rc = PMIx_Allocation_request_nb (PMIX_ALLOC_NEW , info , 2 , infocbfunc , & mydata ))) {
191
+ fprintf (stderr , "Client ns %s rank %d: PMIx_Allocation_request_nb failed: %d\n" ,
192
+ myproc .nspace , myproc .rank , rc );
196
193
goto done ;
197
194
}
198
195
DEBUG_WAIT_THREAD (& mydata .lock );
199
196
PMIX_INFO_FREE (info , 2 );
200
- fprintf (stderr , "Client ns %s rank %d: Allocation returned status: %s\n" ,
201
- myproc .nspace , myproc . rank , PMIx_Error_string (mydata .lock .status ));
197
+ fprintf (stderr , "Client ns %s rank %d: Allocation returned status: %s\n" , myproc . nspace ,
198
+ myproc .rank , PMIx_Error_string (mydata .lock .status ));
202
199
DEBUG_DESTRUCT_MYQUERY (& mydata );
203
200
/* if it didn't succeed and we have peers out there, then we better wake
204
201
* them up */
205
202
206
-
207
203
} else if (1 == myproc .rank ) {
208
204
/* demonstrate a notification based approach - register a handler
209
205
* specifically for when the allocation operation completes */
@@ -213,17 +209,17 @@ int main(int argc, char **argv)
213
209
PMIX_INFO_LOAD (& info [1 ], PMIX_EVENT_RETURN_OBJECT , & myrel , PMIX_POINTER );
214
210
DEBUG_CONSTRUCT_LOCK (& mylock );
215
211
code = PMIX_NOTIFY_ALLOC_COMPLETE ;
216
- PMIx_Register_event_handler (& code , 1 , info , 2 ,
217
- release_fn , evhandler_reg_callbk , (void * ) & mylock );
212
+ PMIx_Register_event_handler (& code , 1 , info , 2 , release_fn , evhandler_reg_callbk ,
213
+ (void * ) & mylock );
218
214
DEBUG_WAIT_THREAD (& mylock );
219
215
PMIX_INFO_FREE (info , 2 );
220
216
rc = mylock .status ;
221
217
DEBUG_DESTRUCT_LOCK (& mylock );
222
218
223
219
/* now wait to hear that the request is complete */
224
220
DEBUG_WAIT_THREAD (& myrel .lock );
225
- fprintf (stderr , "[%s:%d] Allocation returned status: %s\n" ,
226
- myproc . nspace , myproc . rank , PMIx_Error_string (myrel .lock .status ));
221
+ fprintf (stderr , "[%s:%d] Allocation returned status: %s\n" , myproc . nspace , myproc . rank ,
222
+ PMIx_Error_string (myrel .lock .status ));
227
223
DEBUG_DESTRUCT_MYREL (& myrel );
228
224
229
225
} else {
@@ -237,25 +233,27 @@ int main(int argc, char **argv)
237
233
PMIX_INFO_CREATE (query [0 ].qualifiers , 1 );
238
234
PMIX_INFO_LOAD (& query [0 ].qualifiers [0 ], PMIX_ALLOC_ID , myallocation , PMIX_STRING );
239
235
240
- if (PMIX_SUCCESS != (rc = PMIx_Query_info_nb (query , 1 , infocbfunc , (void * ) & mydata ))) {
236
+ if (PMIX_SUCCESS != (rc = PMIx_Query_info_nb (query , 1 , infocbfunc , (void * ) & mydata ))) {
241
237
fprintf (stderr , "PMIx_Query_info failed: %d\n" , rc );
242
238
goto done ;
243
239
}
244
240
DEBUG_WAIT_THREAD (& mydata .lock );
245
241
PMIX_QUERY_FREE (query , 1 );
246
- fprintf (stderr , "[%s:%d] Allocation returned status: %s\n" ,
247
- myproc . nspace , myproc . rank , PMIx_Error_string (mydata .lock .status ));
242
+ fprintf (stderr , "[%s:%d] Allocation returned status: %s\n" , myproc . nspace , myproc . rank ,
243
+ PMIx_Error_string (mydata .lock .status ));
248
244
DEBUG_DESTRUCT_MYQUERY (& mydata );
249
245
}
250
246
251
- done :
247
+ done :
252
248
/* finalize us */
253
249
fprintf (stderr , "Client ns %s rank %d: Finalizing\n" , myproc .nspace , myproc .rank );
254
250
if (PMIX_SUCCESS != (rc = PMIx_Finalize (NULL , 0 ))) {
255
- fprintf (stderr , "Client ns %s rank %d:PMIx_Finalize failed: %d\n" , myproc .nspace , myproc .rank , rc );
251
+ fprintf (stderr , "Client ns %s rank %d:PMIx_Finalize failed: %d\n" , myproc .nspace ,
252
+ myproc .rank , rc );
256
253
} else {
257
- fprintf (stderr , "Client ns %s rank %d:PMIx_Finalize successfully completed\n" , myproc .nspace , myproc .rank );
254
+ fprintf (stderr , "Client ns %s rank %d:PMIx_Finalize successfully completed\n" ,
255
+ myproc .nspace , myproc .rank );
258
256
}
259
257
fflush (stderr );
260
- return (0 );
258
+ return (0 );
261
259
}
0 commit comments