1313 * All rights reserved.
1414 * Copyright (c) 2009-2012 Cisco Systems, Inc. All rights reserved.
1515 * Copyright (c) 2011 Oak Ridge National Labs. All rights reserved.
16- * Copyright (c) 2013-2017 Intel, Inc. All rights reserved.
16+ * Copyright (c) 2013-2018 Intel, Inc. All rights reserved.
1717 * Copyright (c) 2015 Mellanox Technologies, Inc. All rights reserved.
1818 * $COPYRIGHT$
1919 *
@@ -97,11 +97,11 @@ int main(int argc, char **argv)
9797 int rc ;
9898 pmix_value_t value ;
9999 pmix_value_t * val = & value ;
100- char * tmp ;
100+ char * tmp , * ptr , * p ;
101101 pmix_proc_t proc ;
102- uint32_t nprocs , n ;
102+ uint32_t nprocs , m , n , local_cnt , * localpeers ;
103103 pmix_info_t * info ;
104- bool flag ;
104+ bool flag , local ;
105105 volatile int active ;
106106 pmix_status_t dbg = PMIX_ERR_DEBUGGER_RELEASE ;
107107
@@ -196,7 +196,7 @@ int main(int argc, char **argv)
196196 value .type = PMIX_UINT64 ;
197197 value .data .uint64 = 1234 ;
198198 if (PMIX_SUCCESS != (rc = PMIx_Put (PMIX_LOCAL , tmp , & value ))) {
199- fprintf (stderr , "Client ns %s rank %d: PMIx_Put internal failed: %d\n" , myproc .nspace , myproc .rank , rc );
199+ fprintf (stderr , "Client ns %s rank %d: PMIx_Put local failed: %d\n" , myproc .nspace , myproc .rank , rc );
200200 goto done ;
201201 }
202202 free (tmp );
@@ -207,7 +207,7 @@ int main(int argc, char **argv)
207207 value .type = PMIX_STRING ;
208208 value .data .string = "1234" ;
209209 if (PMIX_SUCCESS != (rc = PMIx_Put (PMIX_REMOTE , tmp , & value ))) {
210- fprintf (stderr , "Client ns %s rank %d: PMIx_Put internal failed: %d\n" , myproc .nspace , myproc .rank , rc );
210+ fprintf (stderr , "Client ns %s rank %d: PMIx_Put remote failed: %d\n" , myproc .nspace , myproc .rank , rc );
211211 goto done ;
212212 }
213213 free (tmp );
@@ -230,53 +230,96 @@ int main(int argc, char **argv)
230230 }
231231 PMIX_INFO_FREE (info , 1 );
232232
233+ /* get the number of local peers */
234+ if (PMIX_SUCCESS != (rc = PMIx_Get (& proc , PMIX_LOCAL_SIZE , NULL , 0 , & val ))) {
235+ fprintf (stderr , "Client ns %s rank %d: PMIx_Get PMIX_LOCAL_SIZE failed: %d" , myproc .nspace , myproc .rank , rc );
236+ goto done ;
237+ }
238+ local_cnt = val -> data .uint32 ;
239+ PMIX_VALUE_RELEASE (val );
240+
241+ /* create an array for the peers */
242+ localpeers = (uint32_t * )malloc (local_cnt * sizeof (int ));
243+
244+ /* get the list of local peers */
245+ if (PMIX_SUCCESS != (rc = PMIx_Get (& proc , PMIX_LOCAL_PEERS , NULL , 0 , & val ))) {
246+ fprintf (stderr , "Client ns %s rank %d: PMIx_Get PMIX_LOCAL_PEERS failed: %d" , myproc .nspace , myproc .rank , rc );
247+ goto done ;
248+ }
249+ ptr = strdup (val -> data .string );
250+ PMIX_VALUE_RELEASE (val );
251+
252+ /* populate the peers array */
253+ p = strtok (ptr , "," );
254+ localpeers [0 ] = strtoul (p , NULL , 10 );
255+ for (n = 1 ; n < local_cnt ; n ++ ) {
256+ p = strtok (NULL , "," );
257+ localpeers [n ] = strtoul (p , NULL , 10 );
258+ }
259+ free (ptr );
260+
233261 /* check the returned data */
234262 for (n = 0 ; n < nprocs ; n ++ ) {
235- if (0 > asprintf ( & tmp , "%s-%d-local" , myproc .nspace , myproc . rank ) ) {
236- exit ( 1 ) ;
263+ if (n == myproc .rank ) {
264+ continue ;
237265 }
238- if (PMIX_SUCCESS != (rc = PMIx_Get (& myproc , tmp , NULL , 0 , & val ))) {
239- fprintf (stderr , "Client ns %s rank %d: PMIx_Get %s failed: %d\n" , myproc .nspace , myproc .rank , tmp , rc );
240- goto done ;
241- }
242- if (PMIX_UINT64 != val -> type ) {
243- fprintf (stderr , "Client ns %s rank %d: PMIx_Get %s returned wrong type: %d\n" , myproc .nspace , myproc .rank , tmp , val -> type );
244- PMIX_VALUE_RELEASE (val );
245- free (tmp );
246- goto done ;
266+ proc .rank = n ;
267+ local = false;
268+ for (m = 0 ; m < local_cnt ; m ++ ) {
269+ if (localpeers [m ] == proc .rank ) {
270+ local = true;
271+ break ;
272+ }
247273 }
248- if (1234 != val -> data .uint64 ) {
249- fprintf (stderr , "Client ns %s rank %d: PMIx_Get %s returned wrong value: %d\n" , myproc .nspace , myproc .rank , tmp , (int )val -> data .uint64 );
274+ if (local ) {
275+ if (0 > asprintf (& tmp , "%s-%d-local" , proc .nspace , proc .rank )) {
276+ exit (1 );
277+ }
278+ if (PMIX_SUCCESS != (rc = PMIx_Get (& proc , tmp , NULL , 0 , & val ))) {
279+ fprintf (stderr , "Client ns %s rank %d: PMIx_Get %s failed: %d\n" , myproc .nspace , myproc .rank , tmp , rc );
280+ goto done ;
281+ }
282+ if (PMIX_UINT64 != val -> type ) {
283+ fprintf (stderr , "Client ns %s rank %d: PMIx_Get %s returned wrong type: %d\n" , myproc .nspace , myproc .rank , tmp , val -> type );
284+ PMIX_VALUE_RELEASE (val );
285+ free (tmp );
286+ goto done ;
287+ }
288+ if (1234 != val -> data .uint64 ) {
289+ fprintf (stderr , "Client ns %s rank %d: PMIx_Get %s returned wrong value: %d\n" , myproc .nspace , myproc .rank , tmp , (int )val -> data .uint64 );
290+ PMIX_VALUE_RELEASE (val );
291+ free (tmp );
292+ goto done ;
293+ }
294+ fprintf (stderr , "Client ns %s rank %d: PMIx_Get %s returned correct\n" , myproc .nspace , myproc .rank , tmp );
250295 PMIX_VALUE_RELEASE (val );
251296 free (tmp );
252- goto done ;
253- }
254- fprintf (stderr , "Client ns %s rank %d: PMIx_Get %s returned correct\n" , myproc .nspace , myproc .rank , tmp );
255- PMIX_VALUE_RELEASE (val );
256- free (tmp );
257- if (0 > asprintf (& tmp , "%s-%d-remote" , myproc .nspace , myproc .rank )) {
258- exit (1 );
259- }
260- if (PMIX_SUCCESS != (rc = PMIx_Get (& myproc , tmp , NULL , 0 , & val ))) {
261- fprintf (stderr , "Client ns %s rank %d: PMIx_Get %s failed: %d\n" , myproc .nspace , myproc .rank , tmp , rc );
262- goto done ;
263- }
264- if (PMIX_STRING != val -> type ) {
265- fprintf (stderr , "Client ns %s rank %d: PMIx_Get %s returned wrong type: %d\n" , myproc .nspace , myproc .rank , tmp , val -> type );
266- PMIX_VALUE_RELEASE (val );
267- free (tmp );
268- goto done ;
269- }
270- if (0 != strcmp (val -> data .string , "1234" )) {
271- fprintf (stderr , "Client ns %s rank %d: PMIx_Get %s returned wrong value: %s\n" , myproc .nspace , myproc .rank , tmp , val -> data .string );
297+ } else {
298+ if (0 > asprintf (& tmp , "%s-%d-remote" , proc .nspace , proc .rank )) {
299+ exit (1 );
300+ }
301+ if (PMIX_SUCCESS != (rc = PMIx_Get (& proc , tmp , NULL , 0 , & val ))) {
302+ fprintf (stderr , "Client ns %s rank %d: PMIx_Get %s failed: %d\n" , myproc .nspace , myproc .rank , tmp , rc );
303+ goto done ;
304+ }
305+ if (PMIX_STRING != val -> type ) {
306+ fprintf (stderr , "Client ns %s rank %d: PMIx_Get %s returned wrong type: %d\n" , myproc .nspace , myproc .rank , tmp , val -> type );
307+ PMIX_VALUE_RELEASE (val );
308+ free (tmp );
309+ goto done ;
310+ }
311+ if (0 != strcmp (val -> data .string , "1234" )) {
312+ fprintf (stderr , "Client ns %s rank %d: PMIx_Get %s returned wrong value: %s\n" , myproc .nspace , myproc .rank , tmp , val -> data .string );
313+ PMIX_VALUE_RELEASE (val );
314+ free (tmp );
315+ goto done ;
316+ }
317+ fprintf (stderr , "Client ns %s rank %d: PMIx_Get %s returned correct\n" , myproc .nspace , myproc .rank , tmp );
272318 PMIX_VALUE_RELEASE (val );
273319 free (tmp );
274- goto done ;
275320 }
276- fprintf (stderr , "Client ns %s rank %d: PMIx_Get %s returned correct\n" , myproc .nspace , myproc .rank , tmp );
277- PMIX_VALUE_RELEASE (val );
278- free (tmp );
279321 }
322+ free (localpeers );
280323
281324 done :
282325 /* finalize us */
0 commit comments