[Mpi-forum] Giving up on C11 _Generic
Jim Dinan
james.dinan at gmail.com
Thu Aug 8 08:39:13 CDT 2019
The polymorphic C front-end (i.e. macros) can be bypassed by talking a
pointer to the underlying function [1]. This is the desired behavior for
backward compatibility. I agree that this could be surprising to users and
it must be clearly documented.
In the case where the user is not bypassing the C polymorphic front-end and
the compiler does not support _Generic, we can either detect or prevent
silent truncation using one of the approaches that I posted.
~Jim.
[1] The C preprocessor only invokes a function-like macro if the macro name
is followed by (. So, &MPI_Send takes the pointer of the function even
though there is a function-like macro with the same name.
On Thu, Aug 8, 2019 at 6:51 AM HOLMES Daniel <d.holmes at epcc.ed.ac.uk> wrote:
> Hi Jim,
>
> Are we sure the function pointer “worked" in your example? It silently
> truncated the large value, because the function pointer bypasses the
> redirection macro.
>
> Cheers,
> Dan.
> —
> Dr Daniel Holmes PhD
> Architect (HPC Research)
> d.holmes at epcc.ed.ac.uk
> Phone: +44 (0) 131 651 3465
> Mobile: +44 (0) 7940 524 088
> Address: Room 2.09, Bayes Centre, 47 Potterrow, Central Area, Edinburgh,
> EH8 9BT
> —
> The University of Edinburgh is a charitable body, registered in Scotland,
> with registration number SC005336.
> —
>
> On 7 Aug 2019, at 22:00, Jim Dinan via mpi-forum <
> mpi-forum at lists.mpi-forum.org> wrote:
>
> Even simpler than this, we could just forward all calls to the MPI_Count
> interface (see below). The int count argument should type convert to
> MPI_Count without issue. Note that it still needs to be a function-like
> macro so that function pointers work.
>
> Don't give up yet! :D
>
> ~Jim.
>
> #include <stdio.h>
>
>
> typedef int MPI_Datatype;
> typedef int MPI_Comm;
>
> int MPI_Send(const void* buf, int count, MPI_Datatype datatype, int dest,
> int tag, MPI_Comm comm)
> {
> printf("MPI_Send(count = %d)\n", count);
> return 0;
> }
>
> int MPI_Send_x(const void* buf, long long count, MPI_Datatype datatype,
> int dest,
> int tag, MPI_Comm comm)
> {
> printf("MPI_Send_x(count = %lld)\n", count);
> return 0;
> }
>
> #define MPI_Send(buf, count, datatype, dest, tag, comm) MPI_Send_x(buf,
> count, datatype, dest, tag, comm)
>
> int main(int argc, char *argv[]) {
> /* 8589934592LL == 2^33 */
> long long i = 8589934592LL + 11;
> int ret;
> int (*snd_ptr)(const void*, int, MPI_Datatype, int, int, MPI_Comm) =
> &MPI_Send;
> ret = MPI_Send(NULL, i, 0, 0, 0, 0);
> ret = MPI_Send(NULL, 5, 0, 0, 0, 0);
> ret = (*snd_ptr)(NULL, i, 0, 0, 0, 0);
> ret = (*snd_ptr)(NULL, 5, 0, 0, 0, 0);
> return 0;
>
> }
>
> MPI_Send_x(count = 8589934603)
> MPI_Send_x(count = 5)
> MPI_Send(count = 11)
>
> MPI_Send(count = 5)
> _______________________________________________
> mpi-forum mailing list
> mpi-forum at lists.mpi-forum.org
> https://lists.mpi-forum.org/mailman/listinfo/mpi-forum
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mpi-forum.org/pipermail/mpi-forum/attachments/20190808/9de3975c/attachment-0001.html>
More information about the mpi-forum
mailing list