create_f90_real.c 4.31 KB
Newer Older
1
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2
3
4
5
6
/*  
 *  (C) 2004 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */

7
8
#include "create_f90_util.h"

9
#include "mpiimpl.h"
10
#ifdef HAVE_FC_TYPE_ROUTINES
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "mpif90model.h"
#else
/* Assume only 4 and 8 byte IEEE reals available */
#define MPIR_F90_REAL_MODEL 6, 37
#define MPIR_F90_DOUBLE_MODEL 15, 307
#endif

/* -- Begin Profiling Symbol Block for routine MPI_Type_create_f90_real */
#if defined(HAVE_PRAGMA_WEAK)
#pragma weak MPI_Type_create_f90_real = PMPI_Type_create_f90_real
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
#pragma _HP_SECONDARY_DEF PMPI_Type_create_f90_real  MPI_Type_create_f90_real
#elif defined(HAVE_PRAGMA_CRI_DUP)
#pragma _CRI duplicate MPI_Type_create_f90_real as PMPI_Type_create_f90_real
25
26
#elif defined(HAVE_WEAK_ATTRIBUTE)
int MPI_Type_create_f90_real(int precision, int range, MPI_Datatype *newtype) __attribute__((weak,alias("PMPI_Type_create_f90_real")));
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#endif
/* -- End Profiling Symbol Block */

/* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build
   the MPI routines.  You can use USE_WEAK_SYMBOLS to see if MPICH is
   using weak symbols to implement the MPI routines. */
#ifndef MPICH_MPI_FROM_PMPI
#define MPI_Type_create_f90_real PMPI_Type_create_f90_real
#endif

typedef struct realModel { 
    int digits, exponent; 
    MPI_Datatype dtype; 
} realModel;

#undef FUNCNAME
#define FUNCNAME MPI_Type_create_f90_real

/*@
   MPI_Type_create_f90_real - Return a predefined type that matches 
   the specified range

49
Input Parameters:
50
51
52
+  precision - Number of decimal digits in mantissa
-  range - Decimal exponent range desired

53
Output Parameters:
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
.  newtype - A predefine MPI Datatype that matches the range.

   Notes:
If there is no corresponding type for the specified range, the call is 
erroneous.  This implementation sets 'newtype' to 'MPI_DATATYPE_NULL' and
returns an error of class 'MPI_ERR_ARG'.

.N Fortran

.N Errors
.N MPI_SUCCESS
.N MPI_ERR_ARG
@*/
int MPI_Type_create_f90_real( int precision, int range, MPI_Datatype *newtype )
{
    static const char FCNAME[] = "MPI_Type_create_f90_real";
    int i;
    int mpi_errno = MPI_SUCCESS;
72
73
    MPI_Datatype basetype;
    static int setupPredefTypes = 1;
74
75
76
    static realModel f90_real_model[2] = { 
	{ MPIR_F90_REAL_MODEL, MPI_REAL},
	{ MPIR_F90_DOUBLE_MODEL, MPI_DOUBLE_PRECISION } };
77
    MPIU_THREADPRIV_DECL;
78
79
    MPID_MPI_STATE_DECL(MPID_STATE_MPI_TYPE_CREATE_F90_REAL);

80
81
82
    MPIR_ERRTEST_INITIALIZED_ORDIE();

    MPIU_THREAD_CS_ENTER(ALLFUNC,);
83
84
85
    MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_TYPE_CREATE_F90_REAL);

    /* ... body of routine ...  */
86
87
88
89
90
91
    /* MPI 2.1, Section 16.2, page 473 lines 12-27 make it clear that
       these types must returned the combiner version. */
    if (setupPredefTypes) {
	setupPredefTypes = 0;
	for (i=0; i<2; i++) {
	    MPI_Datatype oldType = f90_real_model[i].dtype;
92
93
	    mpi_errno = MPIR_Create_unnamed_predefined( oldType, 
					    MPI_COMBINER_F90_REAL,
94
95
96
					    f90_real_model[i].digits, 
					    f90_real_model[i].exponent, 
					    &f90_real_model[i].dtype );
97
	    if (mpi_errno) MPIU_ERR_POP(mpi_errno);
98
99
100
101
	}
    }

    basetype = MPI_DATATYPE_NULL;
102
103
104
    for (i=0; i<2; i++) {
	if (f90_real_model[i].digits >= precision &&
	    f90_real_model[i].exponent >= range) {
105
	    basetype = f90_real_model[i].dtype;
106
107
108
109
	    break;
	}
    }

110
111
112
113
114
115
116
117
118
119
120
121
    if (basetype == MPI_DATATYPE_NULL) {
	mpi_errno = MPIR_Err_create_code( MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
					  "MPI_Type_create_f90_real",
					  __LINE__, MPI_ERR_OTHER,
 					  "**f90typerealnone", 
					  "**f90typerealnone %d %d", 
					  precision, range );
    }
    else {
	mpi_errno = MPIR_Create_unnamed_predefined( basetype, 
			    MPI_COMBINER_F90_REAL, range, precision, newtype );
    }
122
    if (mpi_errno) MPIU_ERR_POP(mpi_errno);
123
124
    /* ... end of body of routine ... */

125
126
 fn_exit:
    MPIU_THREAD_CS_EXIT(ALLFUNC,);
127
    MPID_MPI_FUNC_EXIT(MPID_STATE_MPI_TYPE_CREATE_F90_REAL);
128
129
130
131
132
133
134
135
136
137
138
139
140
    return mpi_errno;
 fn_fail:
    /* --BEGIN ERROR HANDLING-- */
#   ifdef HAVE_ERROR_CHECKING
    {
	mpi_errno = MPIR_Err_create_code(
	    mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER, "**mpi_type_create_f90_real",
	    "**mpi_type_create_f90_real %d %d", precision, range );
    }
#   endif
    mpi_errno = MPIR_Err_return_comm( 0, FCNAME, mpi_errno );
    goto fn_exit;
    /* --END ERROR HANDLING-- */
141
}