5
5
* Copyright (c) 2020-2022 Triad National Security, LLC. All rights
6
6
* reserved.
7
7
* Copyright (c) 2020-2021 Cisco Systems, Inc. All rights reserved.
8
- * Copyright (c) 2021 Nanook Consulting. All rights reserved.
8
+ * Copyright (c) 2021-2023 Nanook Consulting. All rights reserved.
9
9
* Copyright (c) 2021 Amazon.com, Inc. or its affiliates. All rights
10
10
* reserved.
11
11
* Copyright (c) 2023 UT-Battelle, LLC. All rights reserved.
@@ -469,11 +469,11 @@ static int check_provider_attr(struct fi_info *provider_info, struct fi_info *pr
469
469
static int compute_dev_distances (pmix_device_distance_t * * distances ,
470
470
size_t * ndist )
471
471
{
472
- int ret = 0 ;
472
+ int ret = OPAL_SUCCESS ;
473
473
size_t ninfo ;
474
474
pmix_info_t * info ;
475
475
pmix_cpuset_t cpuset ;
476
- pmix_topology_t * pmix_topo ;
476
+ pmix_topology_t pmix_topo ;
477
477
pmix_device_type_t type = PMIX_DEVTYPE_OPENFABRICS |
478
478
PMIX_DEVTYPE_NETWORK ;
479
479
@@ -482,10 +482,16 @@ static int compute_dev_distances(pmix_device_distance_t **distances,
482
482
if (PMIX_SUCCESS != ret ) {
483
483
goto out ;
484
484
}
485
+ /* if we are not bound, then we cannot compute distances */
486
+ if (hwloc_bitmap_iszero (cpuset .bitmap ) ||
487
+ hwloc_bitmap_isfull (cpuset .bitmap )) {
488
+ return OPAL_ERR_NOT_BOUND ;
489
+ }
485
490
486
- /* load the PMIX topology */
487
- PMIx_Topology_free (pmix_topo , 1 );
488
- ret = PMIx_Load_topology (pmix_topo );
491
+ /* load the PMIX topology - this just loads a pointer to
492
+ * the local topology held in PMIx, so you must not
493
+ * free it */
494
+ ret = PMIx_Load_topology (& pmix_topo );
489
495
if (PMIX_SUCCESS != ret ) {
490
496
goto out ;
491
497
}
@@ -497,7 +503,6 @@ static int compute_dev_distances(pmix_device_distance_t **distances,
497
503
ndist );
498
504
PMIx_Info_free (info , ninfo );
499
505
500
- PMIx_Topology_free (pmix_topo , 1 );
501
506
out :
502
507
return ret ;
503
508
}
@@ -533,8 +538,9 @@ get_nearest_nics(int *num_distances, pmix_value_t **valin)
533
538
PMIx_Info_destruct (& directive );
534
539
if (ret != PMIX_SUCCESS || !val ) {
535
540
ret = compute_dev_distances (& distances , & ndist );
536
- if (ret )
541
+ if (ret ) {
537
542
goto out ;
543
+ }
538
544
goto find_nearest ;
539
545
}
540
546
@@ -554,8 +560,9 @@ get_nearest_nics(int *num_distances, pmix_value_t **valin)
554
560
555
561
find_nearest :
556
562
nearest = calloc (sizeof (* distances ), ndist );
557
- if (!nearest )
563
+ if (!nearest ) {
558
564
goto out ;
565
+ }
559
566
560
567
for (i = 0 ; i < ndist ; i ++ ) {
561
568
if (distances [i ].type != PMIX_DEVTYPE_NETWORK &&
0 commit comments