Commit fd32dce7 authored by Junchao Zhang's avatar Junchao Zhang
Browse files

Add a test for MPI_BOTTOM and absolute datatypes in C/Fortran mixed code



Refs #1877
Signed-off-by: Kenneth Raffenetti's avatarKen Raffenetti <raffenet@mcs.anl.gov>
parent 0970b584
......@@ -5,6 +5,8 @@
/f90/datatype/Makefile.am
/f90/datatype/hindex1f90.f90
/f90/datatype/hindexed_blockf90.f90
/f90/datatype/bottomf90.f90
/f90/datatype/bottomc.c
/f90/ext/Makefile.am
/f90/ext/stamp-Makefile.am
/f90/io/Makefile.am
......@@ -801,6 +803,7 @@
/f77/datatype/typenamef
/f77/datatype/typesnamef
/f77/datatype/typesubf
/f77/datatype/bottom
/f77/ext/c2fmult
/f77/ext/ctypesinf
/f77/info/infotest2f
......
......@@ -13,7 +13,9 @@ EXTRA_DIST = testlist
AM_DEFAULT_SOURCE_EXT = .f
noinst_PROGRAMS = typenamef typesnamef typecntsf typesubf typem2f gaddressf \
packef allctypesf hindex1f hindexed_blockf typename3f
packef allctypesf hindex1f hindexed_blockf typename3f bottom
bottom_SOURCES=bottomc.c bottomf.f
## typeaints.h will be distributed because it's listed in AC_CONFIG_FILES/AC_OUTPUT
......
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
/*
*
* (C) 2015 by Argonne National Laboratory.
* See COPYRIGHT in top-level directory.
*/
#include <stdio.h>
#include <assert.h>
#include "mpi.h"
#include "../../include/mpitestconf.h"
/*
Name mapping. All routines are created with names that are lower case
with a single trailing underscore. This matches many compilers.
We use #define to change the name for Fortran compilers that do
not use the lowercase/underscore pattern
*/
#ifdef F77_NAME_UPPER
#define c_routine_ C_ROUTINE
#elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED)
/* Mixed is ok because we use lowercase in all uses */
#define c_routine_ c_routine
#elif defined(F77_NAME_LOWER_2USCORE) || defined(F77_NAME_LOWER_USCORE) || \
defined(F77_NAME_MIXED_USCORE)
/* Else leave name alone (routines have no underscore, so both
of these map to a lowercase, single underscore) */
#else
#error 'Unrecognized Fortran name mapping'
#endif
void c_routine_(MPI_Fint *ftype, int *errs)
{
int count = 5;
int lens[2] = {1,1};
int buf[6];
int i, rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Aint displs[2];
MPI_Datatype types[2], newtype;
/* create an absolute datatype for buffer that consists */
/* of count, followed by R(5) */
MPI_Get_address(&count, &displs[0]);
displs[1] = 0;
types[0] = MPI_INT;
types[1] = MPI_Type_f2c(*ftype);
MPI_Type_create_struct(2, lens, displs, types, &newtype);
MPI_Type_commit(&newtype);
if (rank == 0) {
/* the message sent contains an int count of 5, followed
by the 5 MPI_INTEGER entries of the Fortran array R.
Here we assume MPI_INTEGER has the same size as MPI_INT
*/
assert(sizeof(MPI_Fint) == sizeof(int));
MPI_Send(MPI_BOTTOM, 1, newtype, 1, 0, MPI_COMM_WORLD);
} else {
MPI_Recv(buf, 6, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
if (buf[0] != 5) *errs++;
for (i=1; i < 6; i++) if (buf[i] != i) *errs++;
}
MPI_Type_free(&newtype);
}
C -*- Mode: Fortran; -*-
C
C (C) 2015 by Argonne National Laboratory.
C See COPYRIGHT in top-level directory.
C
C
C This test tests absolute datatypes and MPI_BOTTOM in mixed
C Fortran and C code. MPI requires MPI_Get_address return
C the same value in all languages.
C See discussion on p.652 of MPI-3.0
program main
implicit none
include 'mpif.h'
integer :: R(5)
integer :: type, ierr, aoblen(1), aotype(1)
integer (kind=mpi_address_kind) :: aodisp(1)
integer errs
errs = 0
R = (/1, 2, 3, 4, 5/)
call mtest_init(ierr)
! create an absolute datatype for array r
aoblen(1) = 5
call MPI_Get_address(R, aodisp(1), ierr)
aotype(1) = MPI_INTEGER
call MPI_Type_create_struct(1,aoblen,aodisp,aotype, type, ierr)
call c_routine(type, errs)
call MPI_Type_free(type, ierr);
call mtest_finalize(errs)
call MPI_Finalize(ierr)
end
......@@ -9,3 +9,4 @@ gaddressf 1
allctypesf 1
hindex1f 1
hindexed_blockf 1 mpiversion=3.0
bottom 2
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