From 6c4ba31188a4b7c108c8b93431b67a8f6526fa2a Mon Sep 17 00:00:00 2001 From: "David M. Ozog" Date: Mon, 16 Dec 2019 17:55:30 -0500 Subject: [PATCH 1/7] Fix several bugs in the team_split_2D operation The 2D team split operation was neglected a bit during development of shmem_team_split_strided, so it's missing some important properties: * PE numbers must be w.r.t. the team indexing * updates to the PE strides must be w.r.t. the team's stride * The returned team object(s) should be the one(s) containing my PE Signed-off-by: David M. Ozog --- src/shmem_team.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/shmem_team.c b/src/shmem_team.c index d569b1654..1ec8bddd9 100644 --- a/src/shmem_team.c +++ b/src/shmem_team.c @@ -371,21 +371,26 @@ int shmem_internal_team_split_2d(shmem_internal_team_t *parent_team, int xrange, const int num_xteams = ceil( parent_size / (float)xrange ); const int num_yteams = xrange; - int start = parent_start; + int start = 0; int ret = 0; + shmem_internal_team_t *my_xteam, *my_yteam; + for (int i = 0; i < num_xteams; i++) { int xsize = (i == num_xteams - 1 && parent_size % xrange) ? parent_size % xrange : xrange; ret = shmem_internal_team_split_strided(parent_team, start, parent_stride, - xsize, xaxis_config, xaxis_mask, xaxis_team); + xsize, xaxis_config, xaxis_mask, &my_xteam); if (ret) { - RAISE_ERROR_MSG("Creation of x-axis team %d of %d failed\n", i, num_xteams); + RAISE_ERROR_MSG("Creation of x-axis team %d of %d failed\n", i+1, num_xteams); } - start += xrange * parent_stride; + start += xrange; + + if (my_xteam != SHMEMX_TEAM_INVALID) + *xaxis_team = my_xteam; } - start = parent_start; + start = 0; for (int i = 0; i < num_yteams; i++) { int remainder = parent_size % xrange; @@ -393,11 +398,14 @@ int shmem_internal_team_split_2d(shmem_internal_team_t *parent_team, int xrange, int ysize = (remainder && i < remainder) ? yrange + 1 : yrange; ret = shmem_internal_team_split_strided(parent_team, start, xrange*parent_stride, - ysize, yaxis_config, yaxis_mask, yaxis_team); + ysize, yaxis_config, yaxis_mask, &my_yteam); if (ret) { - RAISE_ERROR_MSG("Creation of y-axis team %d of %d failed\n", i, num_yteams); + RAISE_ERROR_MSG("Creation of y-axis team %d of %d failed\n", i+1, num_yteams); } - start += parent_stride; + start += 1; + + if (my_yteam != SHMEMX_TEAM_INVALID) + *yaxis_team = my_yteam; } long *psync = shmem_internal_team_choose_psync(parent_team, SYNC); From e2d15bdfbc04ea09f0b6366c2811ddf8b241e252 Mon Sep 17 00:00:00 2001 From: "David M. Ozog" Date: Wed, 18 Dec 2019 16:04:33 -0500 Subject: [PATCH 2/7] Teams: assert one team per axis per PE in 2D split Signed-off-by: David M. Ozog --- src/shmem_team.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/shmem_team.c b/src/shmem_team.c index 1ec8bddd9..ef876bcdd 100644 --- a/src/shmem_team.c +++ b/src/shmem_team.c @@ -373,10 +373,10 @@ int shmem_internal_team_split_2d(shmem_internal_team_t *parent_team, int xrange, int start = 0; int ret = 0; - - shmem_internal_team_t *my_xteam, *my_yteam; + *xaxis_team = SHMEMX_TEAM_INVALID; for (int i = 0; i < num_xteams; i++) { + shmem_internal_team_t *my_xteam; int xsize = (i == num_xteams - 1 && parent_size % xrange) ? parent_size % xrange : xrange; ret = shmem_internal_team_split_strided(parent_team, start, parent_stride, @@ -386,13 +386,17 @@ int shmem_internal_team_split_2d(shmem_internal_team_t *parent_team, int xrange, } start += xrange; - if (my_xteam != SHMEMX_TEAM_INVALID) + if (my_xteam != SHMEMX_TEAM_INVALID) { + shmem_internal_assert(*xaxis_team == SHMEMX_TEAM_INVALID); *xaxis_team = my_xteam; + } } start = 0; + *yaxis_team = SHMEMX_TEAM_INVALID; for (int i = 0; i < num_yteams; i++) { + shmem_internal_team_t *my_yteam; int remainder = parent_size % xrange; int yrange = parent_size / xrange; int ysize = (remainder && i < remainder) ? yrange + 1 : yrange; @@ -404,8 +408,10 @@ int shmem_internal_team_split_2d(shmem_internal_team_t *parent_team, int xrange, } start += 1; - if (my_yteam != SHMEMX_TEAM_INVALID) + if (my_yteam != SHMEMX_TEAM_INVALID) { + shmem_internal_assert(*yaxis_team == SHMEMX_TEAM_INVALID); *yaxis_team = my_yteam; + } } long *psync = shmem_internal_team_choose_psync(parent_team, SYNC); From 918539d8714842b574bf8503a8d144f6586f8b6b Mon Sep 17 00:00:00 2001 From: James Dinan Date: Wed, 18 Dec 2019 21:17:28 -0500 Subject: [PATCH 3/7] Add 2d split unit test Signed-off-by: James Dinan --- test/shmemx/Makefile.am | 1 + test/shmemx/shmemx_team_split_2d.c | 100 +++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 test/shmemx/shmemx_team_split_2d.c diff --git a/test/shmemx/Makefile.am b/test/shmemx/Makefile.am index 913c17af4..e92e97255 100644 --- a/test/shmemx/Makefile.am +++ b/test/shmemx/Makefile.am @@ -33,6 +33,7 @@ check_PROGRAMS += \ shmemx_test_all \ c11_test_shmemx_wait_until \ c11_test_shmemx_test \ + shmemx_team_split_2d \ shmemx_team_translate_2 \ shmemx_team_reuse_teams \ shmemx_team_collect_active_set \ diff --git a/test/shmemx/shmemx_team_split_2d.c b/test/shmemx/shmemx_team_split_2d.c new file mode 100644 index 000000000..027fade2e --- /dev/null +++ b/test/shmemx/shmemx_team_split_2d.c @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2019 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include + +static int check_2d(shmemx_team_t team, int xdim) { + int me = shmemx_team_my_pe(team); + + shmemx_team_t xteam, yteam; + + int ret = shmemx_team_split_2d(team, xdim, NULL, 0, &xteam, NULL, 0, &yteam); + int errors = 0; + + if (ret == 0) { + int npes_x = shmemx_team_n_pes(xteam); + int npes_y = shmemx_team_n_pes(yteam); + + if (xteam == SHMEMX_TEAM_INVALID || yteam == SHMEMX_TEAM_INVALID) { + printf("%d: Error, received an invalid team\n", shmem_my_pe()); + ++errors; + } + + /* Try converting the PE ids from xteam and yteam to global indices and + * compare with the expected indices */ + for (int i = 0; i < npes_x; i++) { + int pe_g = shmemx_team_translate_pe(xteam, i, SHMEMX_TEAM_WORLD); + int expected_g = shmemx_team_translate_pe(team, me/xdim * xdim + i, SHMEMX_TEAM_WORLD); + + if (pe_g != expected_g) { + printf("%d: xteam pe %d expected %d, got %d\n", me, i, pe_g, expected_g); + errors++; + } + } + + for (int i = 0; i < npes_y; i++) { + int pe_g = shmemx_team_translate_pe(yteam, i, SHMEMX_TEAM_WORLD); + int expected_g = shmemx_team_translate_pe(team, me % xdim + i * xdim, SHMEMX_TEAM_WORLD); + + if (pe_g != expected_g) { + printf("%d: yteam pe %d expected %d, got %d\n", me, i, pe_g, expected_g); + errors++; + } + } + + shmemx_team_destroy(xteam); + shmemx_team_destroy(yteam); + } + + return errors != 0; +} + +int main(void) { + int errors = 0, npes, ret; + shmemx_team_t even_team; + + shmem_init(); + + npes = shmem_n_pes(); + + errors += check_2d(SHMEMX_TEAM_WORLD, 1); + errors += check_2d(SHMEMX_TEAM_WORLD, 2); + errors += check_2d(SHMEMX_TEAM_WORLD, 3); + + ret = shmemx_team_split_strided(SHMEMX_TEAM_WORLD, 0, 2, npes/2 + 1, NULL, 0, &even_team); + + if (ret == 0) { + errors += check_2d(even_team, 1); + errors += check_2d(even_team, 2); + errors += check_2d(even_team, 3); + } + + shmem_finalize(); + return errors != 0; +} From a5c922d0d7adec0511798f7061b5e2736ee7756b Mon Sep 17 00:00:00 2001 From: James Dinan Date: Sat, 21 Dec 2019 11:32:37 -0500 Subject: [PATCH 4/7] Fix bugs in team split 2d unit test Signed-off-by: James Dinan --- test/shmemx/shmemx_team_split_2d.c | 68 ++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/test/shmemx/shmemx_team_split_2d.c b/test/shmemx/shmemx_team_split_2d.c index 027fade2e..a94a4356a 100644 --- a/test/shmemx/shmemx_team_split_2d.c +++ b/test/shmemx/shmemx_team_split_2d.c @@ -29,15 +29,18 @@ #include #include -static int check_2d(shmemx_team_t team, int xdim) { - int me = shmemx_team_my_pe(team); +static int check_2d(shmemx_team_t parent_team, int xdim) { + int me = shmemx_team_my_pe(parent_team); - shmemx_team_t xteam, yteam; + shmemx_team_t xteam = SHMEMX_TEAM_INVALID; + shmemx_team_t yteam = SHMEMX_TEAM_INVALID; - int ret = shmemx_team_split_2d(team, xdim, NULL, 0, &xteam, NULL, 0, &yteam); + int ret = shmemx_team_split_2d(parent_team, xdim, NULL, 0, &xteam, NULL, 0, &yteam); int errors = 0; if (ret == 0) { + int me_x = shmemx_team_my_pe(xteam); + int me_y = shmemx_team_my_pe(yteam); int npes_x = shmemx_team_n_pes(xteam); int npes_y = shmemx_team_n_pes(yteam); @@ -46,53 +49,84 @@ static int check_2d(shmemx_team_t team, int xdim) { ++errors; } - /* Try converting the PE ids from xteam and yteam to global indices and - * compare with the expected indices */ + /* Try converting the PE ids from xteam and yteam to parent and global + * PE indices and compare with the expected indices */ for (int i = 0; i < npes_x; i++) { - int pe_g = shmemx_team_translate_pe(xteam, i, SHMEMX_TEAM_WORLD); - int expected_g = shmemx_team_translate_pe(team, me/xdim * xdim + i, SHMEMX_TEAM_WORLD); + int expected_parent = me_y * xdim + i; /* row (fixed) + column */ + int pe_parent = shmemx_team_translate_pe(xteam, i, parent_team); + int pe_world = shmemx_team_translate_pe(xteam, i, SHMEMX_TEAM_WORLD); + int expected_world = shmemx_team_translate_pe(parent_team, expected_parent, SHMEMX_TEAM_WORLD); + + if (expected_parent != pe_parent) { + printf("%d: xteam[%d] expected parent PE id %d, got %d\n", + me, i, expected_parent, pe_parent); + errors++; + } - if (pe_g != expected_g) { - printf("%d: xteam pe %d expected %d, got %d\n", me, i, pe_g, expected_g); + if (expected_world != pe_world) { + printf("%d: xteam[%d] expected world PE id %d, got %d\n", + me, i, expected_world, pe_world); errors++; } } for (int i = 0; i < npes_y; i++) { - int pe_g = shmemx_team_translate_pe(yteam, i, SHMEMX_TEAM_WORLD); - int expected_g = shmemx_team_translate_pe(team, me % xdim + i * xdim, SHMEMX_TEAM_WORLD); + int expected_parent = i * xdim + me_x; /* row + column (fixed) */ + int pe_parent = shmemx_team_translate_pe(yteam, i, parent_team); + int pe_world = shmemx_team_translate_pe(yteam, i, SHMEMX_TEAM_WORLD); + int expected_world = shmemx_team_translate_pe(parent_team, expected_parent, SHMEMX_TEAM_WORLD); + + if (expected_parent != pe_parent) { + printf("%d: yteam[%d] expected parent PE id %d, got %d\n", + me, i, expected_parent, pe_parent); + errors++; + } - if (pe_g != expected_g) { - printf("%d: yteam pe %d expected %d, got %d\n", me, i, pe_g, expected_g); + if (expected_world != pe_world) { + printf("%d: yteam[%d] expected world PE id %d, got %d\n", + me, i, expected_world, pe_world); errors++; } } + } + else { + printf("%d: 2d split failed\n", shmem_my_pe()); + } + if (xteam != SHMEMX_TEAM_INVALID) shmemx_team_destroy(xteam); + if (yteam != SHMEMX_TEAM_INVALID) shmemx_team_destroy(yteam); - } return errors != 0; } int main(void) { - int errors = 0, npes, ret; + int errors = 0, me, npes, ret; shmemx_team_t even_team; shmem_init(); + me = shmem_my_pe(); npes = shmem_n_pes(); + if (me == 0) printf("Performing 2d split test on SHMEM_TEAM_WORLD\n"); + errors += check_2d(SHMEMX_TEAM_WORLD, 1); errors += check_2d(SHMEMX_TEAM_WORLD, 2); errors += check_2d(SHMEMX_TEAM_WORLD, 3); - ret = shmemx_team_split_strided(SHMEMX_TEAM_WORLD, 0, 2, npes/2 + 1, NULL, 0, &even_team); + ret = shmemx_team_split_strided(SHMEMX_TEAM_WORLD, 0, 2, (npes-1)/2 + 1, + NULL, 0, &even_team); if (ret == 0) { + if (me == 0) printf("Performing 2d split test on even team\n"); + errors += check_2d(even_team, 1); errors += check_2d(even_team, 2); errors += check_2d(even_team, 3); + } else { + if (me == 0) printf("Unable to create even team\n"); } shmem_finalize(); From 4ecc5cd9c934e2c1e705edfc1ce47e2e691601f3 Mon Sep 17 00:00:00 2001 From: James Dinan Date: Wed, 18 Dec 2019 21:17:28 -0500 Subject: [PATCH 5/7] Add 2d split unit test Signed-off-by: James Dinan --- test/shmemx/Makefile.am | 1 + test/shmemx/shmemx_team_split_2d.c | 100 +++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 test/shmemx/shmemx_team_split_2d.c diff --git a/test/shmemx/Makefile.am b/test/shmemx/Makefile.am index 913c17af4..e92e97255 100644 --- a/test/shmemx/Makefile.am +++ b/test/shmemx/Makefile.am @@ -33,6 +33,7 @@ check_PROGRAMS += \ shmemx_test_all \ c11_test_shmemx_wait_until \ c11_test_shmemx_test \ + shmemx_team_split_2d \ shmemx_team_translate_2 \ shmemx_team_reuse_teams \ shmemx_team_collect_active_set \ diff --git a/test/shmemx/shmemx_team_split_2d.c b/test/shmemx/shmemx_team_split_2d.c new file mode 100644 index 000000000..027fade2e --- /dev/null +++ b/test/shmemx/shmemx_team_split_2d.c @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2019 Intel Corporation. All rights reserved. + * This software is available to you under the BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include + +static int check_2d(shmemx_team_t team, int xdim) { + int me = shmemx_team_my_pe(team); + + shmemx_team_t xteam, yteam; + + int ret = shmemx_team_split_2d(team, xdim, NULL, 0, &xteam, NULL, 0, &yteam); + int errors = 0; + + if (ret == 0) { + int npes_x = shmemx_team_n_pes(xteam); + int npes_y = shmemx_team_n_pes(yteam); + + if (xteam == SHMEMX_TEAM_INVALID || yteam == SHMEMX_TEAM_INVALID) { + printf("%d: Error, received an invalid team\n", shmem_my_pe()); + ++errors; + } + + /* Try converting the PE ids from xteam and yteam to global indices and + * compare with the expected indices */ + for (int i = 0; i < npes_x; i++) { + int pe_g = shmemx_team_translate_pe(xteam, i, SHMEMX_TEAM_WORLD); + int expected_g = shmemx_team_translate_pe(team, me/xdim * xdim + i, SHMEMX_TEAM_WORLD); + + if (pe_g != expected_g) { + printf("%d: xteam pe %d expected %d, got %d\n", me, i, pe_g, expected_g); + errors++; + } + } + + for (int i = 0; i < npes_y; i++) { + int pe_g = shmemx_team_translate_pe(yteam, i, SHMEMX_TEAM_WORLD); + int expected_g = shmemx_team_translate_pe(team, me % xdim + i * xdim, SHMEMX_TEAM_WORLD); + + if (pe_g != expected_g) { + printf("%d: yteam pe %d expected %d, got %d\n", me, i, pe_g, expected_g); + errors++; + } + } + + shmemx_team_destroy(xteam); + shmemx_team_destroy(yteam); + } + + return errors != 0; +} + +int main(void) { + int errors = 0, npes, ret; + shmemx_team_t even_team; + + shmem_init(); + + npes = shmem_n_pes(); + + errors += check_2d(SHMEMX_TEAM_WORLD, 1); + errors += check_2d(SHMEMX_TEAM_WORLD, 2); + errors += check_2d(SHMEMX_TEAM_WORLD, 3); + + ret = shmemx_team_split_strided(SHMEMX_TEAM_WORLD, 0, 2, npes/2 + 1, NULL, 0, &even_team); + + if (ret == 0) { + errors += check_2d(even_team, 1); + errors += check_2d(even_team, 2); + errors += check_2d(even_team, 3); + } + + shmem_finalize(); + return errors != 0; +} From bf626c4f5ea0c36b76a47b6b43ece2cebd1785df Mon Sep 17 00:00:00 2001 From: James Dinan Date: Sat, 21 Dec 2019 11:32:37 -0500 Subject: [PATCH 6/7] Fix bugs in team split 2d unit test Signed-off-by: James Dinan --- test/shmemx/shmemx_team_split_2d.c | 68 ++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/test/shmemx/shmemx_team_split_2d.c b/test/shmemx/shmemx_team_split_2d.c index 027fade2e..a94a4356a 100644 --- a/test/shmemx/shmemx_team_split_2d.c +++ b/test/shmemx/shmemx_team_split_2d.c @@ -29,15 +29,18 @@ #include #include -static int check_2d(shmemx_team_t team, int xdim) { - int me = shmemx_team_my_pe(team); +static int check_2d(shmemx_team_t parent_team, int xdim) { + int me = shmemx_team_my_pe(parent_team); - shmemx_team_t xteam, yteam; + shmemx_team_t xteam = SHMEMX_TEAM_INVALID; + shmemx_team_t yteam = SHMEMX_TEAM_INVALID; - int ret = shmemx_team_split_2d(team, xdim, NULL, 0, &xteam, NULL, 0, &yteam); + int ret = shmemx_team_split_2d(parent_team, xdim, NULL, 0, &xteam, NULL, 0, &yteam); int errors = 0; if (ret == 0) { + int me_x = shmemx_team_my_pe(xteam); + int me_y = shmemx_team_my_pe(yteam); int npes_x = shmemx_team_n_pes(xteam); int npes_y = shmemx_team_n_pes(yteam); @@ -46,53 +49,84 @@ static int check_2d(shmemx_team_t team, int xdim) { ++errors; } - /* Try converting the PE ids from xteam and yteam to global indices and - * compare with the expected indices */ + /* Try converting the PE ids from xteam and yteam to parent and global + * PE indices and compare with the expected indices */ for (int i = 0; i < npes_x; i++) { - int pe_g = shmemx_team_translate_pe(xteam, i, SHMEMX_TEAM_WORLD); - int expected_g = shmemx_team_translate_pe(team, me/xdim * xdim + i, SHMEMX_TEAM_WORLD); + int expected_parent = me_y * xdim + i; /* row (fixed) + column */ + int pe_parent = shmemx_team_translate_pe(xteam, i, parent_team); + int pe_world = shmemx_team_translate_pe(xteam, i, SHMEMX_TEAM_WORLD); + int expected_world = shmemx_team_translate_pe(parent_team, expected_parent, SHMEMX_TEAM_WORLD); + + if (expected_parent != pe_parent) { + printf("%d: xteam[%d] expected parent PE id %d, got %d\n", + me, i, expected_parent, pe_parent); + errors++; + } - if (pe_g != expected_g) { - printf("%d: xteam pe %d expected %d, got %d\n", me, i, pe_g, expected_g); + if (expected_world != pe_world) { + printf("%d: xteam[%d] expected world PE id %d, got %d\n", + me, i, expected_world, pe_world); errors++; } } for (int i = 0; i < npes_y; i++) { - int pe_g = shmemx_team_translate_pe(yteam, i, SHMEMX_TEAM_WORLD); - int expected_g = shmemx_team_translate_pe(team, me % xdim + i * xdim, SHMEMX_TEAM_WORLD); + int expected_parent = i * xdim + me_x; /* row + column (fixed) */ + int pe_parent = shmemx_team_translate_pe(yteam, i, parent_team); + int pe_world = shmemx_team_translate_pe(yteam, i, SHMEMX_TEAM_WORLD); + int expected_world = shmemx_team_translate_pe(parent_team, expected_parent, SHMEMX_TEAM_WORLD); + + if (expected_parent != pe_parent) { + printf("%d: yteam[%d] expected parent PE id %d, got %d\n", + me, i, expected_parent, pe_parent); + errors++; + } - if (pe_g != expected_g) { - printf("%d: yteam pe %d expected %d, got %d\n", me, i, pe_g, expected_g); + if (expected_world != pe_world) { + printf("%d: yteam[%d] expected world PE id %d, got %d\n", + me, i, expected_world, pe_world); errors++; } } + } + else { + printf("%d: 2d split failed\n", shmem_my_pe()); + } + if (xteam != SHMEMX_TEAM_INVALID) shmemx_team_destroy(xteam); + if (yteam != SHMEMX_TEAM_INVALID) shmemx_team_destroy(yteam); - } return errors != 0; } int main(void) { - int errors = 0, npes, ret; + int errors = 0, me, npes, ret; shmemx_team_t even_team; shmem_init(); + me = shmem_my_pe(); npes = shmem_n_pes(); + if (me == 0) printf("Performing 2d split test on SHMEM_TEAM_WORLD\n"); + errors += check_2d(SHMEMX_TEAM_WORLD, 1); errors += check_2d(SHMEMX_TEAM_WORLD, 2); errors += check_2d(SHMEMX_TEAM_WORLD, 3); - ret = shmemx_team_split_strided(SHMEMX_TEAM_WORLD, 0, 2, npes/2 + 1, NULL, 0, &even_team); + ret = shmemx_team_split_strided(SHMEMX_TEAM_WORLD, 0, 2, (npes-1)/2 + 1, + NULL, 0, &even_team); if (ret == 0) { + if (me == 0) printf("Performing 2d split test on even team\n"); + errors += check_2d(even_team, 1); errors += check_2d(even_team, 2); errors += check_2d(even_team, 3); + } else { + if (me == 0) printf("Unable to create even team\n"); } shmem_finalize(); From 65b51636586962482b83c228021a3ad8bcb5fc0d Mon Sep 17 00:00:00 2001 From: "David M. Ozog" Date: Tue, 7 Jan 2020 17:29:12 -0500 Subject: [PATCH 7/7] Fix team creation with invalid parent or xrange * Set xrange to be less than or equal to the parent_team size * Return nonzero in strided split when parent is invalid * Return nonzero in 2D split when parent is invalid * Correct shmemx_team_reuse_teams example accordingly Signed-off-by: David M. Ozog --- src/shmem_team.c | 15 ++++++++++++--- test/shmemx/shmemx_team_reuse_teams.c | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/shmem_team.c b/src/shmem_team.c index ef876bcdd..eec249500 100644 --- a/src/shmem_team.c +++ b/src/shmem_team.c @@ -249,7 +249,7 @@ int shmem_internal_team_split_strided(shmem_internal_team_t *parent_team, int PE *new_team = SHMEMX_TEAM_INVALID; if (parent_team == SHMEMX_TEAM_INVALID) { - return 0; + return 1; } int global_PE_start = shmem_internal_team_pe(parent_team, PE_start); @@ -365,6 +365,17 @@ int shmem_internal_team_split_2d(shmem_internal_team_t *parent_team, int xrange, shmem_internal_team_t **xaxis_team, const shmemx_team_config_t *yaxis_config, long yaxis_mask, shmem_internal_team_t **yaxis_team) { + *xaxis_team = SHMEMX_TEAM_INVALID; + *yaxis_team = SHMEMX_TEAM_INVALID; + + if (parent_team == SHMEMX_TEAM_INVALID) { + return 1; + } + + if (xrange > parent_team->size) { + xrange = parent_team->size; + } + const int parent_start = parent_team->start; const int parent_stride = parent_team->stride; const int parent_size = parent_team->size; @@ -373,7 +384,6 @@ int shmem_internal_team_split_2d(shmem_internal_team_t *parent_team, int xrange, int start = 0; int ret = 0; - *xaxis_team = SHMEMX_TEAM_INVALID; for (int i = 0; i < num_xteams; i++) { shmem_internal_team_t *my_xteam; @@ -393,7 +403,6 @@ int shmem_internal_team_split_2d(shmem_internal_team_t *parent_team, int xrange, } start = 0; - *yaxis_team = SHMEMX_TEAM_INVALID; for (int i = 0; i < num_yteams; i++) { shmem_internal_team_t *my_yteam; diff --git a/test/shmemx/shmemx_team_reuse_teams.c b/test/shmemx/shmemx_team_reuse_teams.c index 33f3b6120..0aeb59d06 100644 --- a/test/shmemx/shmemx_team_reuse_teams.c +++ b/test/shmemx/shmemx_team_reuse_teams.c @@ -57,7 +57,7 @@ int main(void) } ret = shmemx_team_split_strided(old_team, 1, 1, shmemx_team_n_pes(old_team)-1, NULL, 0, &new_team); - if (ret) ++errors; + if (old_team != SHMEMX_TEAM_INVALID && ret) ++errors; shmemx_team_destroy(old_team); old_team = new_team;