Skip to content

Commit 129f82b

Browse files
committed
test/f90: fix f90/attr/attrlangc
It appears the old interpretation of how we store an integer value in attribute is to store a pointer (address) to an interger. This creates the ridiculous case when we retrieve a attribute value set in Fortran, we need *guess* whether the integer attr is set in F77 or F90 and cast the returned attr from (void *) to either (int *) or (MPI_Aint *). In an alternate interpretation, we simply store an integer as a scalar. If we retrieve the integer from C, simply cast the (void *) into an integer. Integer cast is always safe! Simply, the new interpretation always treats an attribute as a scalar value (including ptr address). There is no way to implement the old interpretation with a C MPI ABI. Note, the new interpretation only affects applications that want to retrieve an attribute set in Fortran but get in C. I don't think we have any real applications involving such case.
1 parent 3aa9d8d commit 129f82b

File tree

1 file changed

+3
-62
lines changed

1 file changed

+3
-62
lines changed

test/mpi/f90/attr/attrlangc.c

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -574,74 +574,15 @@ void csetmpiwin_(MPI_Fint * fwin, MPI_Fint * fkey, MPI_Aint * val, MPI_Fint * er
574574
/* ----------------------------------------------------------------------- */
575575
void ccompareint2aint_(MPI_Fint * in1, MPI_Aint * in2, MPI_Fint * result)
576576
{
577-
static int idx = -1;
578-
if (sizeof(MPI_Fint) == sizeof(MPI_Aint)) {
579-
*result = *in1 == *in2;
580-
} else if (sizeof(MPI_Fint) < sizeof(MPI_Aint)) {
581-
/* Assume Aint no smaller than Fint, and that size of aint
582-
* is a multiple of the size of fint) */
583-
MPI_Fint *v2 = (MPI_Fint *) in2;
584-
if (idx < 0) {
585-
MPI_Aint av = 1;
586-
MPI_Fint *fa = (MPI_Fint *) & av;
587-
if ((sizeof(MPI_Aint) % sizeof(MPI_Fint)) != 0) {
588-
fprintf(stderr,
589-
"PANIC: size of MPI_Aint = %d not a multiple of MPI_Fint = %d\n",
590-
(int) sizeof(MPI_Aint), (int) sizeof(MPI_Fint));
591-
MPI_Abort(MPI_COMM_WORLD, 1);
592-
}
593-
for (idx = sizeof(MPI_Aint) / sizeof(MPI_Fint); idx >= 0; idx--)
594-
if (fa[idx])
595-
break;
596-
if (idx < 0) {
597-
fprintf(stderr, "Unable to determine low word of Fint in Aint\n");
598-
MPI_Abort(MPI_COMM_WORLD, 1);
599-
}
600-
*result = *in1 == v2[idx];
601-
}
602-
} else {
603-
fprintf(stderr, "PANIC: sizeof(MPI_Fint) = %d > sizeof(MPI_Aint) %d\n",
604-
(int) sizeof(MPI_Fint), (int) sizeof(MPI_Aint));
605-
MPI_Abort(MPI_COMM_WORLD, 1);
606-
}
577+
*result = *in1 == *in2;
607578
}
608579

609580
void ccompareint2void_(MPI_Fint * in1, void *in2, MPI_Fint * result)
610581
{
611-
static int idx = -1;
612-
if (sizeof(MPI_Fint) == sizeof(void *)) {
613-
*result = *in1 == *(MPI_Fint *) in2;
614-
} else if (sizeof(MPI_Fint) < sizeof(void *)) {
615-
/* Assume void* no smaller than Fint, and that size of aint
616-
* is a multiple of the size of fint) */
617-
MPI_Fint *v2 = (MPI_Fint *) in2;
618-
if (idx < 0) {
619-
void *av = (void *) 1;
620-
MPI_Fint *fa = (MPI_Fint *) & av;
621-
if ((sizeof(void *) % sizeof(MPI_Fint)) != 0) {
622-
fprintf(stderr,
623-
"PANIC: size of void * = %d not a multiple of MPI_Fint = %d\n",
624-
(int) sizeof(void *), (int) sizeof(MPI_Fint));
625-
MPI_Abort(MPI_COMM_WORLD, 1);
626-
}
627-
for (idx = sizeof(void *) / sizeof(MPI_Fint); idx >= 0; idx--)
628-
if (fa[idx])
629-
break;
630-
if (idx < 0) {
631-
fprintf(stderr, "Unable to determine low word of Fint in void*\n");
632-
MPI_Abort(MPI_COMM_WORLD, 1);
633-
}
634-
*result = *in1 == v2[idx];
635-
}
636-
} else {
637-
fprintf(stderr, "PANIC: sizeof(MPI_Fint) = %d > sizeof(void*) %d\n",
638-
(int) sizeof(MPI_Fint), (int) sizeof(void *));
639-
MPI_Abort(MPI_COMM_WORLD, 1);
640-
}
582+
*result = *in1 == (MPI_Fint) (intptr_t) in2;
641583
}
642584

643585
void ccompareaint2void_(MPI_Aint * in1, void *in2, MPI_Fint * result)
644586
{
645-
/* Note that an aint must be >= void * by definition */
646-
*result = *in1 == *(MPI_Aint *) in2;
587+
*result = *in1 == (MPI_Aint) (intptr_t) in2;
647588
}

0 commit comments

Comments
 (0)