-:    0:Source:/home/MPI/testing/mpich2/mpich2/src/mpid/common/datatype/mpir_type_flatten.c
        -:    0:Graph:mpir_type_flatten.gcno
        -:    0:Data:-
        -:    0:Runs:0
        -:    0:Programs:0
        -:    1:/* -*- Mode: C; c-basic-offset:4 ; -*- */
        -:    2:
        -:    3:/*
        -:    4: *  (C) 2001 by Argonne National Laboratory.
        -:    5: *      See COPYRIGHT in top-level directory.
        -:    6: */
        -:    7:
        -:    8:#include <mpiimpl.h>
        -:    9:#include <mpid_dataloop.h>
        -:   10:#include <stdlib.h>
        -:   11:
        -:   12:/*@
        -:   13:  MPIR_Type_flatten
        -:   14: 
        -:   15:  Input Parameters:
        -:   16:. type - MPI Datatype (must have been committed)
        -:   17:
        -:   18:  Output Parameters:
        -:   19:. nr_blocks_p - pointer to int in which to store the number of contiguous blocks in the type
        -:   20:
        -:   21:
        -:   22:  Return Value:
        -:   23:  0 on success, -1 on failure.
        -:   24:@*/
        -:   25:
        -:   26:int MPIR_Type_flatten(MPI_Datatype type,
        -:   27:		      MPI_Aint *off_array,
        -:   28:		      int *size_array,
        -:   29:		      MPI_Aint *array_len_p)
    #####:   30:{
        -:   31:    int err;
        -:   32:    MPI_Aint first, last;
        -:   33:    MPID_Datatype *datatype_ptr;
        -:   34:    MPID_Segment *segp;
        -:   35:
    #####:   36:    if (HANDLE_GET_KIND(type) == HANDLE_KIND_BUILTIN) {
    #####:   37:	off_array[0] = 0;
    #####:   38:	MPID_Datatype_get_size_macro(type, size_array[0]);
    #####:   39:	*array_len_p = 1;
    #####:   40:	return 0;
        -:   41:    }
        -:   42:
    #####:   43:    MPID_Datatype_get_ptr(type, datatype_ptr);
    #####:   44:    MPIU_Assert(datatype_ptr->is_committed);
    #####:   45:    MPIU_Assert(*array_len_p >= datatype_ptr->max_contig_blocks);
        -:   46:
    #####:   47:    segp = MPID_Segment_alloc();
    #####:   48:    err = MPID_Segment_init(0, 1, type, segp, 0); /* first 0 is bufptr,
        -:   49:                                                   * 1 is count
        -:   50:                                                   * last 0 is homogeneous
        -:   51:                                                   */
    #####:   52:    if (err) return err;
        -:   53:
    #####:   54:    first = 0;
    #####:   55:    last  = SEGMENT_IGNORE_LAST;
        -:   56:
    #####:   57:    MPID_Segment_flatten(segp,
        -:   58:			 first,
        -:   59:			 &last,
        -:   60:			 off_array,
        -:   61:			 size_array,
        -:   62:			 array_len_p);
        -:   63:
    #####:   64:    MPID_Segment_free(segp);
        -:   65:
    #####:   66:    return 0;
        -:   67:}