create_f90_int.c 3.85 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
#include "mpif90model.h"
#else
/* Assume only 4 byte integers available */
14
#define MPIR_F90_INTEGER_MODEL_MAP { 9, 4, 4 },
15
16
17
18
19
20
21
22
23
#endif

/* -- Begin Profiling Symbol Block for routine MPI_Type_create_f90_integer */
#if defined(HAVE_PRAGMA_WEAK)
#pragma weak MPI_Type_create_f90_integer = PMPI_Type_create_f90_integer
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
#pragma _HP_SECONDARY_DEF PMPI_Type_create_f90_integer  MPI_Type_create_f90_integer
#elif defined(HAVE_PRAGMA_CRI_DUP)
#pragma _CRI duplicate MPI_Type_create_f90_integer as PMPI_Type_create_f90_integer
24
25
#elif defined(HAVE_WEAK_ATTRIBUTE)
int MPI_Type_create_f90_integer(int range, MPI_Datatype *newtype) __attribute__((weak,alias("PMPI_Type_create_f90_integer")));
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#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_integer PMPI_Type_create_f90_integer

#endif

typedef struct intModel {
    int range, kind, bytes; } intModel;

#undef FUNCNAME
#define FUNCNAME MPI_Type_create_f90_integer

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

47
Input Parameters:
48
49
.  range - Decimal range (number of digits) desired

50
Output Parameters:
51
52
53
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_integer( int range, MPI_Datatype *newtype )
{
    static const char FCNAME[] = "MPI_Type_create_f90_integer";
    int i, bytes;
    int mpi_errno = MPI_SUCCESS;
    MPI_Datatype basetype = MPI_DATATYPE_NULL;
    static intModel f90_integer_map[] = { MPIR_F90_INTEGER_MODEL_MAP
					  {0, 0, 0 } };
72
    MPIU_THREADPRIV_DECL;
73
74
    MPID_MPI_STATE_DECL(MPID_STATE_MPI_TYPE_CREATE_F90_INTEGER);

75
76
77
    MPIR_ERRTEST_INITIALIZED_ORDIE();

    MPIU_THREAD_CS_ENTER(ALLFUNC,);
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
    MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_TYPE_CREATE_F90_INTEGER);

    /* ... body of routine ...  */
    for (i=0; f90_integer_map[i].range > 0; i++) {
	if (f90_integer_map[i].range >= range) {
	    /* Find the corresponding INTEGER type */
	    bytes = f90_integer_map[i].bytes;
	    switch (bytes) {
	    case 1: basetype = MPI_INTEGER1; break;
	    case 2: basetype = MPI_INTEGER2; break;
	    case 4: basetype = MPI_INTEGER4; break;
	    case 8: basetype = MPI_INTEGER8; break;
	    default: break;
	    }
	    break;
	}
    }

    if (basetype == MPI_DATATYPE_NULL) {
	mpi_errno = MPIR_Err_create_code( MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
					  "MPI_Type_create_f90_integer",
					  __LINE__, MPI_ERR_OTHER,
 					  "**f90typeintnone", 
					  "**f90typeintnone %d", range );
    }
    else {
	mpi_errno = MPIR_Create_unnamed_predefined( basetype, 
			    MPI_COMBINER_F90_INTEGER, range, -1, newtype );
    }
107
    if (mpi_errno) goto fn_fail;
108
109

    /* ... end of body of routine ... */
110
 fn_exit:
111
    MPID_MPI_FUNC_EXIT(MPID_STATE_MPI_TYPE_CREATE_F90_INTEGER);
112
    MPIU_THREAD_CS_EXIT(ALLFUNC,);
113
    return mpi_errno;
114
115
116
117
118
119
120
121
122
123
124
125
 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_int",
	    "**mpi_type_create_f90_int %d", range );
    }
#   endif
    mpi_errno = MPIR_Err_return_comm( 0, FCNAME, mpi_errno );
    goto fn_exit;
    /* --END ERROR HANDLING-- */
126
}