Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
SMPI: Fix the prototype of SMPI_MPI_Type_get_extent (use MPI_Aint instead of int...
[simgrid.git] / src / smpi / smpi_mpi_dt.c
1 /* $Id$tag */
2
3 /* smpi_mpi_dt.c -- MPI primitives to handle datatypes                        */
4  
5 /* Note: a very incomplete implementation                                     */
6
7 /* Copyright (c) 2009 Stephane Genaud.                                        */
8 /* All rights reserved.                                                       */
9
10 /* This program is free software; you can redistribute it and/or modify it
11  *  * under the terms of the license (GNU LGPL) which comes with this package. */
12
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17
18 #include "private.h"
19 #include "smpi_mpi_dt_private.h"
20
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_mpi_dt, smpi,
22                                 "Logging specific to SMPI (datatype)");
23
24
25 /**
26  * Get the lower bound and extent for a Datatype 
27  * The  extent of a datatype is defined to be the span from the first byte to the last byte 
28  * occupied by entries in this datatype, rounded up to satisfy alignment requirements (epsilon).
29  *
30  * For typemap T = {(t_0,disp_0), ...,  (t_n-1,disp_n-1)}
31  * lb(T)     = min_j disp_j
32  * ub(T)     = max_j (disp_j+sizeof(t_j)) + epsilon
33  * extent(T) = ub(T) - lb(T)
34  *
35  * FIXME: this an incomplete implementation as we do not support yet MPI_Type_commit.
36  * Hence, this can be called only for primitive type MPI_INT, MPI_DOUBLE, ...
37  *
38  * remark: MPI-1 has also the deprecated 
39  * int MPI_Type_extent(MPI_Datatype datatype, *MPI_Aint *extent);
40  *
41  **/
42 int smpi_mpi_type_get_extent(MPI_Datatype datatype, MPI_Aint *lb, MPI_Aint *extent) {
43         
44         if ( DT_FLAG_COMMITED != (datatype-> flags & DT_FLAG_COMMITED) )
45                 return( MPI_ERR_TYPE );
46         *lb =  datatype->lb;
47         *extent =  datatype->ub - datatype->lb;
48         return( MPI_SUCCESS );
49 }
50
51
52 /**
53  * query extent and lower bound of the type 
54  **/
55 int SMPI_MPI_Type_get_extent( MPI_Datatype datatype, MPI_Aint *lb, MPI_Aint *extent)
56 {
57         return( smpi_mpi_type_get_extent( datatype, lb, extent));
58 }
59
60 /**
61  * query the size of the type
62  **/
63 int SMPI_MPI_Type_size(MPI_Datatype datatype, size_t * size)
64 {
65   int retval = MPI_SUCCESS;
66
67   smpi_bench_end();
68
69   if (NULL == datatype) {
70     retval = MPI_ERR_TYPE;
71   } else if (NULL == size) {
72     retval = MPI_ERR_ARG;
73   } else {
74     *size = datatype->size;
75   }
76
77   smpi_bench_begin();
78
79   return retval;
80 }
81
82
83 /* Deprecated Functions. 
84  * The MPI-2 standard deprecated a number of routines because MPI-2 provides better versions. 
85  * This routine is one of those that was deprecated. The routine may continue to be used, but 
86  * new code should use the replacement routine. The replacement for this routine is MPI_Type_Get_extent.
87  **/
88 int SMPI_MPI_Type_ub( MPI_Datatype datatype, MPI_Aint *displacement) 
89 {
90         if ( DT_FLAG_COMMITED != (datatype->flags & DT_FLAG_COMMITED) )
91                 return( MPI_ERR_TYPE );
92         *displacement = datatype->ub;
93         return( MPI_SUCCESS );
94 }
95 int SMPI_MPI_Type_lb( MPI_Datatype datatype, MPI_Aint *displacement) 
96 {
97         if ( DT_FLAG_COMMITED != (datatype->flags & DT_FLAG_COMMITED) )
98                 return( MPI_ERR_TYPE );
99         *displacement = datatype->lb;
100         return( MPI_SUCCESS );
101 }