1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
2 /*
3 * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
4 * University Research and Technology
5 * Corporation. All rights reserved.
6 * Copyright (c) 2004-2013 The University of Tennessee and The University
7 * of Tennessee Research Foundation. All rights
8 * reserved.
9 * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
10 * University of Stuttgart. All rights reserved.
11 * Copyright (c) 2004-2006 The Regents of the University of California.
12 * All rights reserved.
13 * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
14 * Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
15 * $COPYRIGHT$
16 *
17 * Additional copyrights may follow
18 *
19 * $HEADER$
20 */
21
22 #include "ompi_config.h"
23 #include "opal/class/opal_pointer_array.h"
24 #include "ompi/datatype/ompi_datatype.h"
25 #include "ompi/datatype/ompi_datatype_internal.h"
26
27 extern int32_t ompi_datatype_number_of_predefined_data;
28
29 const ompi_datatype_t* ompi_datatype_match_size( int size, uint16_t datakind, uint16_t datalang )
30 {
31 int32_t i;
32 const ompi_datatype_t* datatype;
33
34 /* If we're not looking for a complex C++ type then set the default type to C */
35 if( datalang == OMPI_DATATYPE_FLAG_DATA_CPP ) {
36 if( datakind != OMPI_DATATYPE_FLAG_DATA_COMPLEX )
37 datalang = OMPI_DATATYPE_FLAG_DATA_C;
38 }
39
40 for( i = 0; i < ompi_datatype_number_of_predefined_data; i++ ) {
41
42 datatype = (ompi_datatype_t*)opal_pointer_array_get_item(&ompi_datatype_f_to_c_table, i);
43
44 if( (datatype->super.flags & OMPI_DATATYPE_FLAG_DATA_LANGUAGE) != datalang )
45 continue;
46 if( (datatype->super.flags & OMPI_DATATYPE_FLAG_DATA_TYPE) != datakind )
47 continue;
48 if( (size_t)size == datatype->super.size ) {
49 return datatype;
50 }
51 }
52 return &ompi_mpi_datatype_null.dt;
53 }