Skip to content

Commit 78d0a63

Browse files
committed
spml/ucx: fix for loop
Signed-off-by: Michal Shalev <mshalev.nvidia.com>
1 parent 03c59cd commit 78d0a63

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

oshmem/mca/spml/ucx/spml_ucx.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -638,12 +638,13 @@ int mca_spml_ucx_add_procs(oshmem_group_t* group, size_t nprocs)
638638
unsigned int *wk_roffs = NULL;
639639
unsigned int *wk_rsizes = NULL;
640640
char *wk_raddrs = NULL;
641-
size_t i, j, w, n, temp;
641+
size_t i, w, n;
642642
ucs_status_t err;
643643
ucp_address_t **wk_local_addr;
644644
unsigned int *wk_addr_len;
645645
ucp_ep_params_t ep_params;
646646
int *indices;
647+
int proc_index, swap_index, temp_index;
647648

648649
wk_local_addr = calloc(mca_spml_ucx.ucp_workers, sizeof(ucp_address_t *));
649650
wk_addr_len = calloc(mca_spml_ucx.ucp_workers, sizeof(size_t));
@@ -703,28 +704,28 @@ int mca_spml_ucx_add_procs(oshmem_group_t* group, size_t nprocs)
703704
srand((unsigned int)time(NULL));
704705

705706
/* Get the EP connection requests for all the processes from modex */
706-
for (i = nprocs - 1; i >= 0; --i) {
707+
for (proc_index = nprocs - 1; proc_index >= 0; --proc_index) {
707708
/* Fisher-Yates shuffle algorithm */
708-
if (i > 0) {
709-
j = rand() % (i + 1);
710-
temp = indices[i];
711-
indices[i] = indices[j];
712-
indices[j] = temp;
709+
if (proc_index > 0) {
710+
swap_index = rand() % (proc_index + 1);
711+
temp_index = indices[proc_index];
712+
indices[proc_index] = indices[swap_index];
713+
indices[proc_index] = temp_index;
713714
}
714715

715716
ep_params.field_mask = UCP_EP_PARAM_FIELD_REMOTE_ADDRESS;
716-
ep_params.address = (ucp_address_t *) mca_spml_ucx.remote_addrs_tbl[0][indices[i]];
717+
ep_params.address = (ucp_address_t *) mca_spml_ucx.remote_addrs_tbl[0][indices[proc_index]];
717718

718719
err = ucp_ep_create(mca_spml_ucx_ctx_default.ucp_worker[0], &ep_params,
719-
&mca_spml_ucx_ctx_default.ucp_peers[indices[i]].ucp_conn);
720+
&mca_spml_ucx_ctx_default.ucp_peers[indices[proc_index]].ucp_conn);
720721
if (UCS_OK != err) {
721722
SPML_UCX_ERROR("ucp_ep_create(proc=%zu/%zu) failed: %s", n, nprocs,
722723
ucs_status_string(err));
723724
goto error2;
724725
}
725726

726727
/* Initialize mkeys as NULL for all processes */
727-
mca_spml_ucx_peer_mkey_cache_init(&mca_spml_ucx_ctx_default, indices[i]);
728+
mca_spml_ucx_peer_mkey_cache_init(&mca_spml_ucx_ctx_default, indices[proc_index]);
728729
}
729730

730731
for (i = 0; i < mca_spml_ucx.ucp_workers; i++) {

0 commit comments

Comments
 (0)