Commit 960c4545 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Add macros to cast const pointer parameters.

* Some MPI implementations annotate INTENT(IN) parameters with
  const, some do not.
parent c05674f2
......@@ -205,6 +205,14 @@ ACX_F90_PACKAGE([MPI],[mpi],,,
save_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS $MPI_C_INCLUDE"
TJ_FIND_INTEGRAL_TYPE([MPI_Fint],[MPI_FINT],[@%:@include <mpi.h>])
ACX_MPI_SEND_CONST_VOID_P_BUF_ARG([CAST_MPI_SEND_BUF="(buf)"
XT_MPI_SEND_BUF_CONST=const],
[CAST_MPI_SEND_BUF="((void *)(buf))"
XT_MPI_SEND_BUF_CONST=])
AC_DEFINE_UNQUOTED([CAST_MPI_SEND_BUF(buf)],[$CAST_MPI_SEND_BUF],
[Macro to cast arguments to MPI_Send-like functions (if necessary)])
AC_DEFINE_UNQUOTED([XT_MPI_SEND_BUF_CONST],[$XT_MPI_SEND_BUF_CONST],
[Defined to const, iff buf argument to MPI_Send-like functions can be const])
TJ_FIND_INTEGRAL_TYPE([MPI_Aint],[xt_mpi_aint],[@%:@include <mpi.h>])
xt_mpi_aint_kind=c_[]AS_TR_SH([$xt_mpi_aint])
FCFLAGS="$FCFLAGS ${FPP_DEFOPT}XT_MPI_AINT_KIND=$xt_mpi_aint_kind"
......
dnl acx_mpi_send_args.m4 --- check whether MPI_Send-like functions take
dnl const void * instead of void * arguments
dnl
dnl Copyright (C) 2014 Thomas Jahns <jahns@dkrz.de>
dnl
dnl Keywords: configure configure.ac autoconf MPI mpirun mpiexec
dnl Author: Thomas Jahns <jahns@dkrz.de>
dnl Maintainer: Thomas Jahns <jahns@dkrz.de>
dnl URL: https://www.dkrz.de/redmine/projects/scales-ppm
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions are
dnl met:
dnl
dnl Redistributions of source code must retain the above copyright notice,
dnl this list of conditions and the following disclaimer.
dnl
dnl Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl
dnl Neither the name of the DKRZ GmbH nor the names of its contributors
dnl may be used to endorse or promote products derived from this software
dnl without specific prior written permission.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
dnl IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
dnl TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
dnl PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
dnl OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
dnl PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
dnl LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
dnl NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
dnl SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
dnl
dnl ACX_MPI_SEND_CONST_VOID_P_BUF_ARG([ACTION-IF-ACCEPTS-CONST-VOID-P],
dnl [ACTION-IF-NOT-ACCEPTS-CONST-VOID-P])
dnl
AC_DEFUN([ACX_MPI_SEND_CONST_VOID_P_BUF_ARG],
[AC_CACHE_CHECK([whether MPI_Send accepts const void * as first argument],
[acx_cv_mpi_send_takes_const_void],
[AC_LANG_PUSH([C])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([@%:@include <stdlib.h>
@%:@include <mpi.h>
@%:@define xmpi(ret) \\
do { \\
if (ret != MPI_SUCCESS) \\
exit(EXIT_FAILURE); \\
} while (0)
extern int MPI_Send(const void *buf, int count, MPI_Datatype datatype,
int dest, int tag, MPI_Comm comm);
int main(int argc, char **argv)
{
xmpi(MPI_Init(&argc, &argv));
static const int foo = 1;
int rank, baz;
xmpi(MPI_Comm_rank(MPI_COMM_WORLD, &rank));
if (rank == 0)
xmpi(MPI_Send(&foo, 1, MPI_INT, 1, 1, MPI_COMM_WORLD));
else if (rank == 1)
xmpi(MPI_Recv(&baz, 1, MPI_INT, 0, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE));
xmpi(MPI_Finalize());
return EXIT_SUCCESS;
}
])],
[acx_cv_mpi_send_takes_const_void=yes],
[acx_cv_mpi_send_takes_const_void=no])
AC_LANG_POP([C])])
AS_IF([test x"$acx_cv_mpi_send_takes_const_void" = xyes],[$1],
[m4_ifval([$2],[$2],
[AC_MSG_FAILURE([MPI_Send does not accept const void * buf arguments])])])
])
dnl
dnl Local Variables:
dnl mode: autoconf
dnl license-project-url: "https://www.dkrz.de/redmine/projects/scales-ppm"
dnl license-default: "bsd"
dnl End:
......@@ -71,7 +71,7 @@ xt_exchanger_irecv_isend_s_exchange(const void *src_data, void *dst_data,
requests+i), comm);
for (int i = 0; i < nsend; ++i)
xt_mpi_call(MPI_Isend((void *)src_data, 1, send_msgs[i].datatype,
xt_mpi_call(MPI_Isend(CAST_MPI_SEND_BUF(src_data), 1, send_msgs[i].datatype,
send_msgs[i].rank,
tag_offset + xt_mpi_tag_exchange_msg, comm,
requests+nrecv+i), comm);
......
......@@ -71,7 +71,7 @@ xt_exchanger_irecv_send_s_exchange(const void *src_data, void *dst_data,
recv_request+i), comm);
for (int i = 0; i < nsend; ++i)
xt_mpi_call(MPI_Send((void *)src_data, 1, send_msgs[i].datatype,
xt_mpi_call(MPI_Send(CAST_MPI_SEND_BUF(src_data), 1, send_msgs[i].datatype,
send_msgs[i].rank,
tag_offset + xt_mpi_tag_exchange_msg, comm),
comm);
......
......@@ -417,7 +417,8 @@ void idxvec_pack(Xt_idxlist obj, void *buffer, int buffer_size,
xt_mpi_call(MPI_Pack(&(idxvec->parent.num_indices), 1, MPI_INT, buffer,
buffer_size, position, comm), comm);
if (idxvec->parent.num_indices != 0)
xt_mpi_call(MPI_Pack((Xt_int *)idxvec->vector, idxvec->parent.num_indices,
xt_mpi_call(MPI_Pack(CAST_MPI_SEND_BUF(idxvec->vector),
idxvec->parent.num_indices,
Xt_int_dt, buffer,
buffer_size, position, comm), comm);
}
......
......@@ -248,8 +248,10 @@ xt_xmap_dist_dir_pack_intersections(
prev_send_rank = send_rank;
// pack rank
xt_mpi_call(MPI_Pack((void *)(src_dst_intersections[i].rank + origin),
1, MPI_INT, buffer, buf_size, position,
XT_MPI_SEND_BUF_CONST int *prank
= CAST_MPI_SEND_BUF(src_dst_intersections[i].rank + origin);
xt_mpi_call(MPI_Pack(prank, 1, MPI_INT, buffer, buf_size, position,
comm), comm);
// pack intersection
xt_idxlist_pack(src_dst_intersections[i].idxlist, buffer,
......
......@@ -689,8 +689,8 @@ exchange_pos_ext_modifications(
unsigned num_active_dst = 0, num_dst_changes = 0;
for (int i = 0; i < num_dst_intersections; ++i) {
xt_mpi_call(MPI_Isend(
(int *)dst_removals_per_intersection[i], 2, MPI_INT,
dst_com[i].rank,
CAST_MPI_SEND_BUF(dst_removals_per_intersection[i]),
2, MPI_INT, dst_com[i].rank,
tag_offset + xt_mpi_tag_xmap_intersection_header_exchange,
comm, send_header_requests + i), comm);
......
......@@ -66,7 +66,7 @@ test_datatype_int(MPI_Datatype datatype, int recv_count, const int *send_data,
//datatype
xt_mpi_call(MPI_Sendrecv((void *)send_data, 1, datatype, 0, 0,
xt_mpi_call(MPI_Sendrecv(CAST_MPI_SEND_BUF(send_data), 1, datatype, 0, 0,
recv_data, recv_count, MPI_INT, 0, 0,
MPI_COMM_WORLD, &status),
MPI_COMM_WORLD);
......@@ -91,8 +91,8 @@ test_datatype_int(MPI_Datatype datatype, int recv_count, const int *send_data,
xt_mpi_call(MPI_Irecv(recv_data, recv_count, MPI_INT, 0, 0, MPI_COMM_WORLD,
&request), MPI_COMM_WORLD);
xt_mpi_call(MPI_Send((void *)send_data, 1, datatype, 0, 0, MPI_COMM_WORLD),
MPI_COMM_WORLD);
xt_mpi_call(MPI_Send(CAST_MPI_SEND_BUF(send_data), 1, datatype, 0, 0,
MPI_COMM_WORLD), MPI_COMM_WORLD);
xt_mpi_call(MPI_Wait(&request, &status), MPI_COMM_WORLD);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment