Skip to content

Commit 648699d

Browse files
Address MPI API inconsistencies. (#76)
Our user-facing APIs have a convention of having the output parameters near or at the end of the function argument list. In the MPI API this wasn't the case with qvi_mpi_context_create(). Signed-off-by: Samuel K. Gutierrez <[email protected]>
1 parent 8d44be0 commit 648699d

20 files changed

+371
-366
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2020-2023 Triad National Security, LLC
2+
# Copyright (c) 2020-2024 Triad National Security, LLC
33
# All rights reserved.
44
#
55
# Copyright (c) 2020-2021 Lawrence Livermore National Security, LLC

cmake/QVFortranSupport.cmake

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2022-2023 Triad National Security, LLC
2+
# Copyright (c) 2022-2024 Triad National Security, LLC
33
# All rights reserved.
44
#
55
# This file is part of the quo-vadis project. See the LICENSE file at the
@@ -32,6 +32,8 @@ if(QV_FORTRAN_SUPPORT)
3232
FortranCInterface_VERIFY()
3333
# Make sure we found a Fortran compiler.
3434
if(NOT CMAKE_Fortran_COMPILER STREQUAL "")
35+
# TODO(skg) Improve
36+
set(CMAKE_FORTRAN_FLAGS "${CMAKE_FORTRAN_FLAGS} -Wall -Wextra -pedantic")
3537
set(QV_FORTRAN_HAPPY TRUE)
3638
set(
3739
CMAKE_Fortran_MODULE_DIRECTORY

include/quo-vadis-mpi.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode: C; c-basic-offset:4; indent-tabs-mode:nil -*- */
22
/*
3-
* Copyright (c) 2020-2022 Triad National Security, LLC
3+
* Copyright (c) 2020-2024 Triad National Security, LLC
44
* All rights reserved.
55
*
66
* Copyright (c) 2020-2021 Lawrence Livermore National Security, LLC
@@ -34,8 +34,8 @@ extern "C" {
3434
*/
3535
int
3636
qv_mpi_context_create(
37-
qv_context_t **ctx,
38-
MPI_Comm comm
37+
MPI_Comm comm,
38+
qv_context_t **ctx
3939
);
4040

4141
/**

include/quo-vadis.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ qv_scope_nobjs(
223223
qv_context_t *ctx,
224224
qv_scope_t *scope,
225225
qv_hw_obj_type_t obj,
226-
int *n
226+
int *nobjs
227227
);
228228

229229
/**

src/fortran/quo-vadis-mpif.f90

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
!
2-
! Copyright (c) 2013-2022 Triad National Security, LLC
2+
! Copyright (c) 2013-2024 Triad National Security, LLC
33
! All rights reserved.
44
!
55
! This file is part of the quo-vadis project. See the LICENSE file at the
@@ -12,7 +12,7 @@ module quo_vadis_mpif
1212

1313
interface
1414
integer(c_int) &
15-
function qv_mpi_context_create_c(ctx, comm) &
15+
function qv_mpi_context_create_c(comm, ctx) &
1616
bind(c, name='qvi_mpi_context_create_f2c')
1717
use, intrinsic :: iso_c_binding, only: c_ptr, c_int
1818
implicit none
@@ -41,13 +41,13 @@ end function qv_mpi_context_free_c
4141

4242
contains
4343

44-
subroutine qv_mpi_context_create(ctx, comm, info)
44+
subroutine qv_mpi_context_create(comm, ctx, info)
4545
use, intrinsic :: iso_c_binding, only: c_ptr, c_int
4646
implicit none
4747
type(c_ptr), intent(out) :: ctx
4848
integer, value :: comm
4949
integer(c_int), intent(out) :: info
50-
info = qv_mpi_context_create_c(ctx, comm)
50+
info = qv_mpi_context_create_c(comm, ctx)
5151
end subroutine qv_mpi_context_create
5252

5353
subroutine qv_mpi_scope_comm_dup(ctx, scope, comm, info)

src/quo-vadis-mpi.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ extern "C" {
3333

3434
int
3535
qvi_mpi_context_create_f2c(
36-
qv_context_t **ctx,
37-
MPI_Fint comm
36+
MPI_Fint comm,
37+
qv_context_t **ctx
3838
) {
3939
MPI_Comm c_comm = MPI_Comm_f2c(comm);
40-
return qv_mpi_context_create(ctx, c_comm);
40+
return qv_mpi_context_create(c_comm, ctx);
4141
}
4242

4343
int
@@ -58,8 +58,8 @@ qvi_mpi_scope_comm_dup_f2c(
5858

5959
int
6060
qv_mpi_context_create(
61-
qv_context_t **ctx,
62-
MPI_Comm comm
61+
MPI_Comm comm,
62+
qv_context_t **ctx
6363
) {
6464
if (!ctx || comm == MPI_COMM_NULL) {
6565
return QV_ERR_INVLD_ARG;

src/quo-vadis-process.cc

+10-10
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,6 @@
1818
#include "qvi-context.h"
1919
#include "qvi-zgroup-process.h"
2020

21-
int
22-
qv_process_context_free(
23-
qv_context_t *ctx
24-
) {
25-
if (!ctx) return QV_ERR_INVLD_ARG;
26-
delete ctx->zgroup;
27-
qvi_context_free(&ctx);
28-
return QV_SUCCESS;
29-
}
30-
3121
int
3222
qv_process_context_create(
3323
qv_context_t **ctx
@@ -76,6 +66,16 @@ qv_process_context_create(
7666
return rc;
7767
}
7868

69+
int
70+
qv_process_context_free(
71+
qv_context_t *ctx
72+
) {
73+
if (!ctx) return QV_ERR_INVLD_ARG;
74+
delete ctx->zgroup;
75+
qvi_context_free(&ctx);
76+
return QV_SUCCESS;
77+
}
78+
7979
/*
8080
* vim: ft=cpp ts=4 sts=4 sw=4 expandtab
8181
*/

src/quo-vadis.cc

+26-26
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ qv_scope_nobjs(
123123
qv_context_t *ctx,
124124
qv_scope_t *scope,
125125
qv_hw_obj_type_t obj,
126-
int *n
126+
int *nobjs
127127
) {
128-
if (!ctx || !scope || !n) {
128+
if (!ctx || !scope || !nobjs) {
129129
return QV_ERR_INVLD_ARG;
130130
}
131131

132-
return qvi_scope_nobjs(scope, obj, n);
132+
return qvi_scope_nobjs(scope, obj, nobjs);
133133
}
134134

135135
int
@@ -191,25 +191,23 @@ qv_scope_barrier(
191191
return qvi_scope_barrier(scope);
192192
}
193193

194+
// TODO(skg) Add Fortran interface.
194195
int
195-
qv_scope_split(
196+
qv_scope_create(
196197
qv_context_t *ctx,
197198
qv_scope_t *scope,
198-
int npieces,
199-
int color,
199+
qv_hw_obj_type_t type,
200+
int nobjs,
201+
qv_scope_create_hint_t hint,
200202
qv_scope_t **subscope
201203
) {
202-
if (!ctx || !scope || (npieces <= 0) | !subscope) {
204+
if (!ctx || !scope || (nobjs < 0) || !subscope) {
203205
return QV_ERR_INVLD_ARG;
204206
}
205207

206208
qv_scope_t *isubscope = nullptr;
207-
// We use the sentinel value QV_HW_OBJ_LAST to differentiate between calls
208-
// from split() and split_at(). Since this call doesn't have a hardware type
209-
// argument, we use QV_HW_OBJ_LAST as the hardware type.
210-
int rc = qvi_scope_split(
211-
scope, npieces, color,
212-
QV_HW_OBJ_LAST, &isubscope
209+
int rc = qvi_scope_create(
210+
scope, type, nobjs, hint, &isubscope
213211
);
214212
if (rc != QV_SUCCESS) {
215213
qvi_scope_free(&isubscope);
@@ -219,20 +217,24 @@ qv_scope_split(
219217
}
220218

221219
int
222-
qv_scope_split_at(
220+
qv_scope_split(
223221
qv_context_t *ctx,
224222
qv_scope_t *scope,
225-
qv_hw_obj_type_t type,
226-
int group_id,
223+
int npieces,
224+
int color,
227225
qv_scope_t **subscope
228226
) {
229-
if (!ctx || !scope || !subscope) {
227+
if (!ctx || !scope || (npieces <= 0) | !subscope) {
230228
return QV_ERR_INVLD_ARG;
231229
}
232230

233231
qv_scope_t *isubscope = nullptr;
234-
int rc = qvi_scope_split_at(
235-
scope, type, group_id, &isubscope
232+
// We use the sentinel value QV_HW_OBJ_LAST to differentiate between calls
233+
// from split() and split_at(). Since this call doesn't have a hardware type
234+
// argument, we use QV_HW_OBJ_LAST as the hardware type.
235+
int rc = qvi_scope_split(
236+
scope, npieces, color,
237+
QV_HW_OBJ_LAST, &isubscope
236238
);
237239
if (rc != QV_SUCCESS) {
238240
qvi_scope_free(&isubscope);
@@ -241,23 +243,21 @@ qv_scope_split_at(
241243
return rc;
242244
}
243245

244-
// TODO(skg) Add Fortran interface.
245246
int
246-
qv_scope_create(
247+
qv_scope_split_at(
247248
qv_context_t *ctx,
248249
qv_scope_t *scope,
249250
qv_hw_obj_type_t type,
250-
int nobjs,
251-
qv_scope_create_hint_t hint,
251+
int group_id,
252252
qv_scope_t **subscope
253253
) {
254-
if (!ctx || !scope || (nobjs < 0) || !subscope) {
254+
if (!ctx || !scope || !subscope) {
255255
return QV_ERR_INVLD_ARG;
256256
}
257257

258258
qv_scope_t *isubscope = nullptr;
259-
int rc = qvi_scope_create(
260-
scope, type, nobjs, hint, &isubscope
259+
int rc = qvi_scope_split_at(
260+
scope, type, group_id, &isubscope
261261
);
262262
if (rc != QV_SUCCESS) {
263263
qvi_scope_free(&isubscope);

tests/test-mpi-api.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode: C; c-basic-offset:4; indent-tabs-mode:nil -*- */
22
/*
3-
* Copyright (c) 2022-2023 Triad National Security, LLC
3+
* Copyright (c) 2022-2024 Triad National Security, LLC
44
* All rights reserved.
55
*
66
* This file is part of the quo-vadis project. See the LICENSE file at the
@@ -54,7 +54,7 @@ main(
5454
}
5555

5656
qv_context_t *ctx = NULL;
57-
rc = qv_mpi_context_create(&ctx, comm);
57+
rc = qv_mpi_context_create(comm, &ctx);
5858
if (rc != QV_SUCCESS) {
5959
ers = "qv_scope_free() failed";
6060
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));

tests/test-mpi-fortapi.f90

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
!
2-
! Copyright (c) 2013-2022 Triad National Security, LLC
2+
! Copyright (c) 2013-2024 Triad National Security, LLC
33
! All rights reserved.
44
!
55
! This file is part of the quo-vadis project. See the LICENSE file at the
@@ -53,7 +53,7 @@ program mpi_fortapi
5353
print *, 'cwsize', cwsize
5454
end if
5555

56-
call qv_mpi_context_create(ctx, MPI_COMM_WORLD, info)
56+
call qv_mpi_context_create(MPI_COMM_WORLD, ctx, info)
5757
if (info .ne. QV_SUCCESS) then
5858
error stop
5959
end if

tests/test-mpi-getdev.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ main(
8888

8989
/* Create a QV context */
9090
qv_context_t *ctx;
91-
rc = qv_mpi_context_create(&ctx, comm);
91+
rc = qv_mpi_context_create(comm, &ctx);
9292
if (rc != QV_SUCCESS) {
9393
ers = "qv_mpi_context_create() failed";
9494
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));

tests/test-mpi-init.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode: C; c-basic-offset:4; indent-tabs-mode:nil -*- */
22
/*
3-
* Copyright (c) 2020-2023 Triad National Security, LLC
3+
* Copyright (c) 2020-2024 Triad National Security, LLC
44
* All rights reserved.
55
*
66
* Copyright (c) 2020-2021 Lawrence Livermore National Security, LLC
@@ -46,7 +46,7 @@ main(
4646
}
4747

4848
qv_context_t *ctx = NULL;
49-
rc = qv_mpi_context_create(&ctx, comm);
49+
rc = qv_mpi_context_create(comm, &ctx);
5050
if (rc != QV_SUCCESS) {
5151
ers = "qv_mpi_context_create() failed";
5252
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));

tests/test-mpi-phases.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode: C; c-basic-offset:4; indent-tabs-mode:nil -*- */
22
/*
3-
* Copyright (c) 2020-2023 Triad National Security, LLC
3+
* Copyright (c) 2020-2024 Triad National Security, LLC
44
* All rights reserved.
55
*
66
* Copyright (c) 2020-2021 Lawrence Livermore National Security, LLC
@@ -70,7 +70,7 @@ main(
7070

7171
/* Create a QV context */
7272
qv_context_t *ctx;
73-
rc = qv_mpi_context_create(&ctx, comm);
73+
rc = qv_mpi_context_create(comm, &ctx);
7474
if (rc != QV_SUCCESS) {
7575
ers = "qv_mpi_context_create() failed";
7676
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));

tests/test-mpi-pthreads-layout.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode: C; c-basic-offset:4; indent-tabs-mode:nil -*- */
22
/*
3-
* Copyright (c) 2020-2023 Triad National Security, LLC
3+
* Copyright (c) 2020-2024 Triad National Security, LLC
44
* All rights reserved.
55
*
66
* Copyright (c) 2020 Lawrence Livermore National Security, LLC
@@ -91,7 +91,7 @@ main(void)
9191
}
9292

9393
qv_context_t *mpi_ctx;
94-
rc = qv_mpi_context_create(&mpi_ctx, comm);
94+
rc = qv_mpi_context_create(comm, &mpi_ctx);
9595
if (rc != QV_SUCCESS) {
9696
ers = "qv_mpi_context_create() failed";
9797
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));

tests/test-mpi-scope-create.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode: C; c-basic-offset:4; indent-tabs-mode:nil -*- */
22
/*
3-
* Copyright (c) 2020-2023 Triad National Security, LLC
3+
* Copyright (c) 2020-2024 Triad National Security, LLC
44
* All rights reserved.
55
*
66
* Copyright (c) 2020-2021 Lawrence Livermore National Security, LLC
@@ -133,7 +133,7 @@ main(
133133

134134
/* Create a QV context */
135135
qv_context_t *ctx;
136-
rc = qv_mpi_context_create(&ctx, comm);
136+
rc = qv_mpi_context_create(comm, &ctx);
137137
if (rc != QV_SUCCESS) {
138138
ers = "qv_mpi_context_create() failed";
139139
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));

tests/test-mpi-scopes-affinity-preserving.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode: C; c-basic-offset:4; indent-tabs-mode:nil -*- */
22
/*
3-
* Copyright (c) 2022-2023 Triad National Security, LLC
3+
* Copyright (c) 2022-2024 Triad National Security, LLC
44
* All rights reserved.
55
*
66
* This file is part of the quo-vadis project. See the LICENSE file at the
@@ -49,7 +49,7 @@ main(
4949
}
5050

5151
qv_context_t *ctx;
52-
rc = qv_mpi_context_create(&ctx, comm);
52+
rc = qv_mpi_context_create(comm, &ctx);
5353
if (rc != QV_SUCCESS) {
5454
ers = "qv_mpi_context_create() failed";
5555
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));

tests/test-mpi-scopes.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode: C; c-basic-offset:4; indent-tabs-mode:nil -*- */
22
/*
3-
* Copyright (c) 2020-2023 Triad National Security, LLC
3+
* Copyright (c) 2020-2024 Triad National Security, LLC
44
* All rights reserved.
55
*
66
* Copyright (c) 2020-2021 Lawrence Livermore National Security, LLC
@@ -61,7 +61,7 @@ main(
6161
setbuf(stdout, NULL);
6262

6363
qv_context_t *ctx;
64-
rc = qv_mpi_context_create(&ctx, comm);
64+
rc = qv_mpi_context_create(comm, &ctx);
6565
if (rc != QV_SUCCESS) {
6666
ers = "qv_mpi_context_create() failed";
6767
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));

0 commit comments

Comments
 (0)