|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2001 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#include <mpiimpl.h>
|
|
Packit Service |
c5cf8c |
#include <stdlib.h>
|
|
Packit Service |
c5cf8c |
#include "datatype.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#undef MPID_TYPE_ALLOC_DEBUG
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*@
|
|
Packit Service |
c5cf8c |
MPIR_Type_blockindexed - create a block indexed datatype
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Input Parameters:
|
|
Packit Service |
c5cf8c |
+ count - number of blocks in type
|
|
Packit Service |
c5cf8c |
. blocklength - number of elements in each block
|
|
Packit Service |
c5cf8c |
. displacement_array - offsets of blocks from start of type (see next
|
|
Packit Service |
c5cf8c |
parameter for units)
|
|
Packit Service |
c5cf8c |
. dispinbytes - if nonzero, then displacements are in bytes, otherwise
|
|
Packit Service |
c5cf8c |
they in terms of extent of oldtype
|
|
Packit Service |
c5cf8c |
- oldtype - type (using handle) of datatype on which new type is based
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Output Parameters:
|
|
Packit Service |
c5cf8c |
. newtype - handle of new block indexed datatype
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Return Value:
|
|
Packit Service |
c5cf8c |
MPI_SUCCESS on success, MPI error on failure.
|
|
Packit Service |
c5cf8c |
@*/
|
|
Packit Service |
c5cf8c |
int MPIR_Type_blockindexed(int count,
|
|
Packit Service |
c5cf8c |
int blocklength,
|
|
Packit Service |
c5cf8c |
const void *displacement_array,
|
|
Packit Service |
c5cf8c |
int dispinbytes, MPI_Datatype oldtype, MPI_Datatype * newtype)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int mpi_errno = MPI_SUCCESS, i;
|
|
Packit Service |
c5cf8c |
int is_builtin, old_is_contig;
|
|
Packit Service |
c5cf8c |
MPI_Aint contig_count;
|
|
Packit Service |
c5cf8c |
MPI_Aint el_sz;
|
|
Packit Service |
c5cf8c |
MPI_Datatype el_type;
|
|
Packit Service |
c5cf8c |
MPI_Aint old_lb, old_ub, old_extent, old_true_lb, old_true_ub;
|
|
Packit Service |
c5cf8c |
MPI_Aint min_lb = 0, max_ub = 0, eff_disp;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_Datatype *new_dtp;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (count == 0)
|
|
Packit Service |
c5cf8c |
return MPII_Type_zerolen(newtype);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* allocate new datatype object and handle */
|
|
Packit Service |
c5cf8c |
new_dtp = (MPIR_Datatype *) MPIR_Handle_obj_alloc(&MPIR_Datatype_mem);
|
|
Packit Service |
c5cf8c |
/* --BEGIN ERROR HANDLING-- */
|
|
Packit Service |
c5cf8c |
if (!new_dtp) {
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
|
|
Packit Service |
c5cf8c |
"MPIR_Type_vector", __LINE__, MPI_ERR_OTHER, "**nomem", 0);
|
|
Packit Service |
c5cf8c |
return mpi_errno;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
/* --END ERROR HANDLING-- */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* handle is filled in by MPIR_Handle_obj_alloc() */
|
|
Packit Service |
c5cf8c |
MPIR_Object_set_ref(new_dtp, 1);
|
|
Packit Service |
c5cf8c |
new_dtp->is_permanent = 0;
|
|
Packit Service |
c5cf8c |
new_dtp->is_committed = 0;
|
|
Packit Service |
c5cf8c |
new_dtp->attributes = NULL;
|
|
Packit Service |
c5cf8c |
new_dtp->cache_id = 0;
|
|
Packit Service |
c5cf8c |
new_dtp->name[0] = 0;
|
|
Packit Service |
c5cf8c |
new_dtp->contents = NULL;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
new_dtp->dataloop = NULL;
|
|
Packit Service |
c5cf8c |
new_dtp->dataloop_size = -1;
|
|
Packit Service |
c5cf8c |
new_dtp->dataloop_depth = -1;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
is_builtin = (HANDLE_GET_KIND(oldtype) == HANDLE_KIND_BUILTIN);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (is_builtin) {
|
|
Packit Service |
c5cf8c |
el_sz = (MPI_Aint) MPIR_Datatype_get_basic_size(oldtype);
|
|
Packit Service |
c5cf8c |
el_type = oldtype;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
old_lb = 0;
|
|
Packit Service |
c5cf8c |
old_true_lb = 0;
|
|
Packit Service |
c5cf8c |
old_ub = el_sz;
|
|
Packit Service |
c5cf8c |
old_true_ub = el_sz;
|
|
Packit Service |
c5cf8c |
old_extent = el_sz;
|
|
Packit Service |
c5cf8c |
old_is_contig = 1;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
new_dtp->size = (MPI_Aint) count *(MPI_Aint) blocklength *el_sz;
|
|
Packit Service |
c5cf8c |
new_dtp->has_sticky_lb = 0;
|
|
Packit Service |
c5cf8c |
new_dtp->has_sticky_ub = 0;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
new_dtp->alignsize = el_sz; /* ??? */
|
|
Packit Service |
c5cf8c |
new_dtp->n_builtin_elements = count * blocklength;
|
|
Packit Service |
c5cf8c |
new_dtp->builtin_element_size = el_sz;
|
|
Packit Service |
c5cf8c |
new_dtp->basic_type = el_type;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
new_dtp->max_contig_blocks = count;
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
/* user-defined base type (oldtype) */
|
|
Packit Service |
c5cf8c |
MPIR_Datatype *old_dtp;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_Datatype_get_ptr(oldtype, old_dtp);
|
|
Packit Service |
c5cf8c |
el_sz = old_dtp->builtin_element_size;
|
|
Packit Service |
c5cf8c |
el_type = old_dtp->basic_type;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
old_lb = old_dtp->lb;
|
|
Packit Service |
c5cf8c |
old_true_lb = old_dtp->true_lb;
|
|
Packit Service |
c5cf8c |
old_ub = old_dtp->ub;
|
|
Packit Service |
c5cf8c |
old_true_ub = old_dtp->true_ub;
|
|
Packit Service |
c5cf8c |
old_extent = old_dtp->extent;
|
|
Packit Service |
c5cf8c |
MPIR_Datatype_is_contig(oldtype, &old_is_contig);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
new_dtp->size = (MPI_Aint) count *(MPI_Aint) blocklength *(MPI_Aint) old_dtp->size;
|
|
Packit Service |
c5cf8c |
new_dtp->has_sticky_lb = old_dtp->has_sticky_lb;
|
|
Packit Service |
c5cf8c |
new_dtp->has_sticky_ub = old_dtp->has_sticky_ub;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
new_dtp->alignsize = old_dtp->alignsize;
|
|
Packit Service |
c5cf8c |
new_dtp->n_builtin_elements = count * blocklength * old_dtp->n_builtin_elements;
|
|
Packit Service |
c5cf8c |
new_dtp->builtin_element_size = el_sz;
|
|
Packit Service |
c5cf8c |
new_dtp->basic_type = el_type;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
new_dtp->max_contig_blocks = old_dtp->max_contig_blocks * count * blocklength;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* priming for loop */
|
|
Packit Service |
c5cf8c |
eff_disp = (dispinbytes) ? ((MPI_Aint *) displacement_array)[0] :
|
|
Packit Service |
c5cf8c |
(((MPI_Aint) ((int *) displacement_array)[0]) * old_extent);
|
|
Packit Service |
c5cf8c |
MPII_DATATYPE_BLOCK_LB_UB((MPI_Aint) blocklength,
|
|
Packit Service |
c5cf8c |
eff_disp, old_lb, old_ub, old_extent, min_lb, max_ub);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* determine new min lb and max ub */
|
|
Packit Service |
c5cf8c |
for (i = 1; i < count; i++) {
|
|
Packit Service |
c5cf8c |
MPI_Aint tmp_lb, tmp_ub;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
eff_disp = (dispinbytes) ? ((MPI_Aint *) displacement_array)[i] :
|
|
Packit Service |
c5cf8c |
(((MPI_Aint) ((int *) displacement_array)[i]) * old_extent);
|
|
Packit Service |
c5cf8c |
MPII_DATATYPE_BLOCK_LB_UB((MPI_Aint) blocklength,
|
|
Packit Service |
c5cf8c |
eff_disp, old_lb, old_ub, old_extent, tmp_lb, tmp_ub);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (tmp_lb < min_lb)
|
|
Packit Service |
c5cf8c |
min_lb = tmp_lb;
|
|
Packit Service |
c5cf8c |
if (tmp_ub > max_ub)
|
|
Packit Service |
c5cf8c |
max_ub = tmp_ub;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
new_dtp->lb = min_lb;
|
|
Packit Service |
c5cf8c |
new_dtp->ub = max_ub;
|
|
Packit Service |
c5cf8c |
new_dtp->true_lb = min_lb + (old_true_lb - old_lb);
|
|
Packit Service |
c5cf8c |
new_dtp->true_ub = max_ub + (old_true_ub - old_ub);
|
|
Packit Service |
c5cf8c |
new_dtp->extent = max_ub - min_lb;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* new type is contig for N types if it is all one big block,
|
|
Packit Service |
c5cf8c |
* its size and extent are the same, and the old type was also
|
|
Packit Service |
c5cf8c |
* contiguous.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
new_dtp->is_contig = 0;
|
|
Packit Service |
c5cf8c |
if (old_is_contig) {
|
|
Packit Service |
c5cf8c |
contig_count = MPIR_Type_blockindexed_count_contig(count,
|
|
Packit Service |
c5cf8c |
blocklength,
|
|
Packit Service |
c5cf8c |
displacement_array,
|
|
Packit Service |
c5cf8c |
dispinbytes, old_extent);
|
|
Packit Service |
c5cf8c |
new_dtp->max_contig_blocks = contig_count;
|
|
Packit Service |
c5cf8c |
if ((contig_count == 1) && ((MPI_Aint) new_dtp->size == new_dtp->extent)) {
|
|
Packit Service |
c5cf8c |
new_dtp->is_contig = 1;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
*newtype = new_dtp->handle;
|
|
Packit Service |
c5cf8c |
return mpi_errno;
|
|
Packit Service |
c5cf8c |
}
|