Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
alltoall implemented (almost opmpi algorithms)
[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  * query the size of the type
52  **/
53 int SMPI_MPI_Type_size(MPI_Datatype datatype, size_t * size)
54 {
55   int retval = MPI_SUCCESS;
56
57   smpi_bench_end();
58
59   if (NULL == datatype) {
60     retval = MPI_ERR_TYPE;
61   } else if (NULL == size) {
62     retval = MPI_ERR_ARG;
63   } else {
64     *size = datatype->size;
65   }
66
67   smpi_bench_begin();
68
69   return retval;
70 }
71
72
73
74 /**
75  * query extent and lower bound of the type 
76  **/
77 int SMPI_MPI_Type_get_extent( MPI_Datatype datatype, int *lb, int *extent) 
78 {
79         return( smpi_mpi_type_get_extent( datatype, lb, extent));
80 }
81
82 /* Deprecated Functions. 
83  * The MPI-2 standard deprecated a number of routines because MPI-2 provides better versions. 
84  * This routine is one of those that was deprecated. The routine may continue to be used, but 
85  * new code should use the replacement routine. The replacement for this routine is MPI_Type_Get_extent.
86  **/
87 int SMPI_MPI_Type_ub( MPI_Datatype datatype, MPI_Aint *displacement) 
88 {
89         if ( DT_FLAG_COMMITED != (datatype->flags & DT_FLAG_COMMITED) )
90                 return( MPI_ERR_TYPE );
91         *displacement = datatype->ub;
92         return( MPI_SUCCESS );
93 }
94 int SMPI_MPI_Type_lb( MPI_Datatype datatype, MPI_Aint *displacement) 
95 {
96         if ( DT_FLAG_COMMITED != (datatype->flags & DT_FLAG_COMMITED) )
97                 return( MPI_ERR_TYPE );
98         *displacement = datatype->lb;
99         return( MPI_SUCCESS );
100 }