+
+/*
+Hindexed Implementation - Indexed with indices in bytes
+*/
+
+/*
+ * Copies noncontiguous data into contiguous memory.
+ * @param contiguous_hindexed - output hindexed
+ * @param noncontiguous_hindexed - input hindexed
+ * @param type - pointer contening :
+ * - stride - stride of between noncontiguous data
+ * - block_length - the width or height of blocked matrix
+ * - count - the number of rows of matrix
+ */
+void serialize_hindexed( const void *noncontiguous_hindexed,
+ void *contiguous_hindexed,
+ size_t count,
+ void *type)
+{
+ s_smpi_mpi_hindexed_t* type_c = (s_smpi_mpi_hindexed_t*)type;
+ int i;
+ char* contiguous_hindexed_char = (char*)contiguous_hindexed;
+ char* noncontiguous_hindexed_char = (char*)noncontiguous_hindexed;
+
+ for (i = 0; i < type_c->block_count * count; i++) {
+ memcpy(contiguous_hindexed_char,
+ noncontiguous_hindexed_char, type_c->block_lengths[i] * type_c->size_oldtype);
+
+ contiguous_hindexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
+ noncontiguous_hindexed_char = (char*)noncontiguous_hindexed + type_c->block_indices[i+1];
+ }
+}
+/*
+ * Copies contiguous data into noncontiguous memory.
+ * @param noncontiguous_hindexed - output hindexed
+ * @param contiguous_hindexed - input hindexed
+ * @param type - pointer contening :
+ * - stride - stride of between noncontiguous data
+ * - block_length - the width or height of blocked matrix
+ * - count - the number of rows of matrix
+ */
+void unserialize_hindexed( const void *contiguous_hindexed,
+ void *noncontiguous_hindexed,
+ size_t count,
+ void *type)
+{
+ s_smpi_mpi_hindexed_t* type_c = (s_smpi_mpi_hindexed_t*)type;
+ int i;
+
+ char* contiguous_hindexed_char = (char*)contiguous_hindexed;
+ char* noncontiguous_hindexed_char = (char*)noncontiguous_hindexed;
+
+ for (i = 0; i < type_c->block_count * count; i++) {
+ memcpy(noncontiguous_hindexed_char,
+ contiguous_hindexed_char, type_c->block_lengths[i] * type_c->size_oldtype);
+
+ contiguous_hindexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
+ noncontiguous_hindexed_char = (char*)noncontiguous_hindexed + type_c->block_indices[i+1];
+ }
+}
+
+/*
+ * Create a Sub type hindexed to be able to serialize and unserialize it
+ * the structre s_smpi_mpi_hindexed_t is derived from s_smpi_subtype which
+ * required the functions unserialize and serialize
+ */
+s_smpi_mpi_hindexed_t* smpi_datatype_hindexed_create( int* block_lengths,
+ MPI_Aint* block_indices,
+ int block_count,
+ MPI_Datatype old_type,
+ int size_oldtype){
+ s_smpi_mpi_hindexed_t *new_t= xbt_new(s_smpi_mpi_hindexed_t,1);
+ new_t->base.serialize = &serialize_hindexed;
+ new_t->base.unserialize = &unserialize_hindexed;
+ //FIXME : copy those or assume they won't be freed ?
+ new_t->block_lengths = block_lengths;
+ new_t->block_indices = block_indices;
+ new_t->block_count = block_count;
+ new_t->old_type = old_type;
+ new_t->size_oldtype = size_oldtype;
+ return new_t;
+}
+
+