1313 * Copyright (c) 2014-2018 Intel, Inc. All rights reserved.
1414 * Copyright (c) 2017 Research Organization for Information Science
1515 * and Technology (RIST). All rights reserved.
16+ * Copyright (c) 2019 IBM Corporation. All rights reserved.
1617 * $COPYRIGHT$
1718 *
1819 * Additional copyrights may follow
@@ -377,8 +378,25 @@ static int rank_by(orte_job_t *jdata,
377378 * Perhaps someday someone will come up with a more efficient
378379 * algorithm, but this works for now.
379380 */
381+ // In 3.x this was two loops:
382+ // while (cnt < app->num_procs)
383+ // for (i=0; i<num_objs; ...)
384+ // Then in 4.x it switched to
385+ // while (cnt < app->num_procs && i < (int)node->num_procs)
386+ // where that extra i part seems wrong to me. First of all if anything
387+ // it seems like it should be i<num_objs since that's the array i is
388+ // cycling through, but even then all the usage of i below is
389+ // (i % num_objs) so I think i is intended to wrap and you should
390+ // keep looping until you've made all the assignments you can for
391+ // this node.
392+ //
393+ // So that's what I added the other loop counter for, figuring if it
394+ // cycles through the whole array of objs without making an assignment
395+ // it's time for this loop to end and the outer loop to take us to the
396+ // next node.
380397 i = 0 ;
381- while (cnt < app -> num_procs && i < (int )node -> num_procs ) {
398+ int niters_of_i_without_assigning_a_proc = 0 ;
399+ while (cnt < app -> num_procs && niters_of_i_without_assigning_a_proc <= num_objs ) {
382400 /* get the next object */
383401 obj = (hwloc_obj_t )opal_pointer_array_get_item (& objs , i % num_objs );
384402 if (NULL == obj ) {
@@ -446,6 +464,7 @@ static int rank_by(orte_job_t *jdata,
446464 return rc ;
447465 }
448466 num_ranked ++ ;
467+ niters_of_i_without_assigning_a_proc = 0 ;
449468 /* track where the highest vpid landed - this is our
450469 * new bookmark
451470 */
@@ -454,6 +473,7 @@ static int rank_by(orte_job_t *jdata,
454473 break ;
455474 }
456475 i ++ ;
476+ ++ niters_of_i_without_assigning_a_proc ;
457477 }
458478 }
459479 /* cleanup */
0 commit comments