-:    0:Source:/home/MPI/testing/mpich2/mpich2/src/mpid/common/datatype/mpid_ext32_segment.c
        -:    0:Graph:mpid_ext32_segment.gcno
        -:    0:Data:mpid_ext32_segment.gcda
        -:    0:Runs:510
        -:    0:Programs:137
        -:    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 <stdio.h>
        -:    9:#include <stdlib.h>
        -:   10:
        -:   11:#include <mpichconf.h>
        -:   12:#include <mpiimpl.h>
        -:   13:#include <mpid_dataloop.h>
        -:   14:
        -:   15:#undef MPID_SP_VERBOSE
        -:   16:#undef MPID_SU_VERBOSE
        -:   17:
        -:   18:#include "mpid_ext32_segment.h"
        -:   19:
        -:   20:/* MPID_Segment_piece_params
        -:   21: *
        -:   22: * This structure is used to pass function-specific parameters into our 
        -:   23: * segment processing function.  This allows us to get additional parameters
        -:   24: * to the functions it calls without changing the prototype.
        -:   25: */
        -:   26:struct MPID_Segment_piece_params {
        -:   27:    union {
        -:   28:        struct {
        -:   29:            char *pack_buffer;
        -:   30:        } pack;
        -:   31:        struct {
        -:   32:            DLOOP_VECTOR *vectorp;
        -:   33:            int index;
        -:   34:            int length;
        -:   35:        } pack_vector;
        -:   36:        struct {
        -:   37:	    int64_t *offp;
        -:   38:	    int *sizep; /* see notes in Segment_flatten header */
        -:   39:            int index;
        -:   40:            int length;
        -:   41:        } flatten;
        -:   42:	struct {
        -:   43:	    char *last_loc;
        -:   44:	    int count;
        -:   45:	} contig_blocks;
        -:   46:        struct {
        -:   47:            char *unpack_buffer;
        -:   48:        } unpack;
        -:   49:        struct {
        -:   50:            int stream_off;
        -:   51:        } print;
        -:   52:    } u;
        -:   53:};
        -:   54:
        -:   55:static inline int is_float_type(DLOOP_Type el_type)
        6:   56:{
        6:   57:    return ((el_type == MPI_FLOAT) || (el_type == MPI_DOUBLE) ||
        -:   58:            (el_type == MPI_LONG_DOUBLE) ||
        -:   59:            (el_type == MPI_DOUBLE_PRECISION) ||
        -:   60:            (el_type == MPI_COMPLEX) || (el_type == MPI_DOUBLE_COMPLEX));
        -:   61:/*             (el_type == MPI_REAL4) || (el_type == MPI_REAL8) || */
        -:   62:/*             (el_type == MPI_REAL16)); */
        -:   63:}
        -:   64:
        -:   65:static int external32_basic_convert(char *dest_buf,
        -:   66:                                    char *src_buf,
        -:   67:                                    int dest_el_size,
        -:   68:                                    int src_el_size,
        -:   69:                                    DLOOP_Offset count)
        4:   70:{
        4:   71:    char *src_ptr = src_buf, *dest_ptr = dest_buf;
        4:   72:    char *src_end = (char *)(src_buf + ((int)count * src_el_size));
        -:   73:
        4:   74:    MPIU_Assert(dest_buf && src_buf);
        -:   75:
        4:   76:    if (src_el_size == dest_el_size)
        -:   77:    {
        4:   78:        if (src_el_size == 2)
        -:   79:        {
    #####:   80:            while(src_ptr != src_end)
        -:   81:            {
    #####:   82:                BASIC_convert16((*(TWO_BYTE_BASIC_TYPE *)src_ptr),
        -:   83:                                (*(TWO_BYTE_BASIC_TYPE *)dest_ptr));
        -:   84:
    #####:   85:                src_ptr += src_el_size;
    #####:   86:                dest_ptr += dest_el_size;
        -:   87:            }
        -:   88:        }
        4:   89:        else if (src_el_size == 4)
        -:   90:        {
       38:   91:            while(src_ptr != src_end)
        -:   92:            {
       34:   93:                BASIC_convert32((*(FOUR_BYTE_BASIC_TYPE *)src_ptr),
        -:   94:                                (*(FOUR_BYTE_BASIC_TYPE *)dest_ptr));
        -:   95:
       34:   96:                src_ptr += src_el_size;
       34:   97:                dest_ptr += dest_el_size;
        -:   98:            }
        -:   99:        }
    #####:  100:        else if (src_el_size == 8)
        -:  101:        {
    #####:  102:            while(src_ptr != src_end)
        -:  103:            {
    #####:  104:                BASIC_convert64(src_ptr, dest_ptr);
        -:  105:
    #####:  106:                src_ptr += src_el_size;
    #####:  107:                dest_ptr += dest_el_size;
        -:  108:            }
        -:  109:        }
        -:  110:    }
        -:  111:    else
        -:  112:    {
        -:  113:        /* TODO */
        -:  114:    }
        4:  115:    return 0;
        -:  116:}
        -:  117:
        -:  118:static int external32_float_convert(char *dest_buf,
        -:  119:                                    char *src_buf,
        -:  120:                                    int dest_el_size,
        -:  121:                                    int src_el_size,
        -:  122:                                    int count)
        2:  123:{
        2:  124:    char *src_ptr = src_buf, *dest_ptr = dest_buf;
        2:  125:    char *src_end = (char *)(src_buf + ((int)count * src_el_size));
        -:  126:
        2:  127:    MPIU_Assert(dest_buf && src_buf);
        -:  128:
        2:  129:    if (src_el_size == dest_el_size)
        -:  130:    {
        2:  131:        if (src_el_size == 4)
        -:  132:        {
    #####:  133:            while(src_ptr != src_end)
        -:  134:            {
    #####:  135:                FLOAT_convert((*(FOUR_BYTE_FLOAT_TYPE *)src_ptr),
        -:  136:                              (*(FOUR_BYTE_FLOAT_TYPE *)dest_ptr));
        -:  137:
    #####:  138:                src_ptr += src_el_size;
    #####:  139:                dest_ptr += dest_el_size;
        -:  140:            }
        -:  141:        }
        2:  142:        else if (src_el_size == 8)
        -:  143:        {
        8:  144:            while(src_ptr != src_end)
        -:  145:            {
        6:  146:                FLOAT_convert((*(EIGHT_BYTE_FLOAT_TYPE *)src_ptr),
        -:  147:                              (*(EIGHT_BYTE_FLOAT_TYPE *)dest_ptr));
        -:  148:
        6:  149:                src_ptr += src_el_size;
        6:  150:                dest_ptr += dest_el_size;
        -:  151:            }
        -:  152:        }
        -:  153:    }
        -:  154:    else
        -:  155:    {
        -:  156:        /* TODO */
        -:  157:    }
        2:  158:    return 0;
        -:  159:}
        -:  160:
        -:  161:#undef FUNCNAME
        -:  162:#define FUNCNAME MPID_Segment_contig_pack_external32_to_buf
        -:  163:#undef FCNAME
        -:  164:#define FCNAME MPIDI_QUOTE(FUNCNAME)
        -:  165:static int MPID_Segment_contig_pack_external32_to_buf(DLOOP_Offset *blocks_p,
        -:  166:                                                      DLOOP_Type el_type,
        -:  167:                                                      DLOOP_Offset rel_off,
        -:  168:                                                      void *bufp,
        -:  169:                                                      void *v_paramp)
        4:  170:{
        -:  171:    int src_el_size, dest_el_size;
        4:  172:    struct MPID_Segment_piece_params *paramp = v_paramp;
        -:  173:    MPIDI_STATE_DECL(MPID_STATE_MPID_SEGMENT_CONTIG_PACK_EXTERNAL32_TO_BUF);
        -:  174:
        -:  175:    MPIDI_FUNC_ENTER(MPID_STATE_MPID_SEGMENT_CONTIG_PACK_EXTERNAL32_TO_BUF);
        -:  176:
        4:  177:    src_el_size = MPID_Datatype_get_basic_size(el_type);
        4:  178:    dest_el_size = MPIDI_Datatype_get_basic_size_external32(el_type);
        4:  179:    MPIU_Assert(dest_el_size);
        -:  180:
        -:  181:    /*
        -:  182:     * h  = handle value
        -:  183:     * do = datatype buffer offset
        -:  184:     * dp = datatype buffer pointer
        -:  185:     * bp = pack buffer pointer (current location, incremented as we go)
        -:  186:     * sz = size of datatype (guess we could get this from handle value if
        -:  187:     *      we wanted...)
        -:  188:     */
        -:  189:#ifdef MPID_SP_VERBOSE
        -:  190:    dbg_printf("\t[contig pack [external32]: do=%d, dp=%x, bp=%x, "
        -:  191:               "src_el_sz=%d, dest_el_sz=%d, blksz=%d]\n",
        -:  192:	       rel_off, 
        -:  193:	       (unsigned) bufp,
        -:  194:	       (unsigned) paramp->u.pack.pack_buffer,
        -:  195:	       src_el_size,
        -:  196:	       dest_el_size,
        -:  197:	       (int) *blocks_p);
        -:  198:#endif
        -:  199:
        -:  200:    /* TODO: DEAL WITH CASE WHERE ALL DATA DOESN'T FIT! */
        4:  201:    if ((src_el_size == dest_el_size) && (src_el_size == 1))
        -:  202:    {
        1:  203:        MPIU_Memcpy(paramp->u.pack.pack_buffer,
        -:  204:	       ((char *) bufp) + rel_off, *blocks_p);
        -:  205:    }
        3:  206:    else if (is_float_type(el_type))
        -:  207:    {
        1:  208:        external32_float_convert(paramp->u.pack.pack_buffer,
        -:  209:				 ((char *) bufp) + rel_off,
        -:  210:                                 dest_el_size, src_el_size, *blocks_p);
        -:  211:    }
        -:  212:    else
        -:  213:    {
        2:  214:        external32_basic_convert(paramp->u.pack.pack_buffer,
        -:  215:				 ((char *) bufp) + rel_off,
        -:  216:                                 dest_el_size, src_el_size, *blocks_p);
        -:  217:    }
        4:  218:    paramp->u.pack.pack_buffer += (dest_el_size * (*blocks_p));
        -:  219:
        -:  220:    MPIDI_FUNC_EXIT(MPID_STATE_MPID_SEGMENT_CONTIG_PACK_EXTERNAL32_TO_BUF);
        4:  221:    return 0;
        -:  222:}
        -:  223:
        -:  224:#undef FUNCNAME
        -:  225:#define FUNCNAME MPID_Segment_contig_unpack_external32_to_buf
        -:  226:#undef FCNAME
        -:  227:#define FCNAME MPIDI_QUOTE(FUNCNAME)
        -:  228:static int MPID_Segment_contig_unpack_external32_to_buf(DLOOP_Offset *blocks_p,
        -:  229:                                                        DLOOP_Type el_type,
        -:  230:                                                        DLOOP_Offset rel_off,
        -:  231:                                                        void *bufp,
        -:  232:                                                        void *v_paramp)
        4:  233:{
        -:  234:    int src_el_size, dest_el_size;
        4:  235:    struct MPID_Segment_piece_params *paramp = v_paramp;
        -:  236:    MPIDI_STATE_DECL(MPID_STATE_MPID_SEGMENT_CONTIG_UNPACK_EXTERNAL32_TO_BUF);
        -:  237:
        -:  238:    MPIDI_FUNC_ENTER(MPID_STATE_MPID_SEGMENT_CONTIG_UNPACK_EXTERNAL32_TO_BUF);
        -:  239:
        4:  240:    src_el_size = MPID_Datatype_get_basic_size(el_type);
        4:  241:    dest_el_size = MPIDI_Datatype_get_basic_size_external32(el_type);
        4:  242:    MPIU_Assert(dest_el_size);
        -:  243:
        -:  244:    /*
        -:  245:     * h  = handle value
        -:  246:     * do = datatype buffer offset
        -:  247:     * dp = datatype buffer pointer
        -:  248:     * up = unpack buffer pointer (current location, incremented as we go)
        -:  249:     * sz = size of datatype (guess we could get this from handle value if
        -:  250:     *      we wanted...)
        -:  251:     */
        -:  252:#ifdef MPID_SP_VERBOSE
        -:  253:    dbg_printf("\t[contig unpack [external32]: do=%d, dp=%x, up=%x, "
        -:  254:               "src_el_sz=%d, dest_el_sz=%d, blksz=%d]\n",
        -:  255:	       rel_off,
        -:  256:	       (unsigned) bufp,
        -:  257:	       (unsigned) paramp->u.unpack.unpack_buffer,
        -:  258:	       src_el_size,
        -:  259:	       dest_el_size,
        -:  260:	       (int) *blocks_p);
        -:  261:#endif
        -:  262:
        -:  263:    /* TODO: DEAL WITH CASE WHERE ALL DATA DOESN'T FIT! */
        4:  264:    if ((src_el_size == dest_el_size) && (src_el_size == 1))
        -:  265:    {
        1:  266:        MPIU_Memcpy(((char *)bufp) + rel_off,
        -:  267:	       paramp->u.unpack.unpack_buffer, *blocks_p);
        -:  268:    }
        3:  269:    else if (is_float_type(el_type))
        -:  270:    {
        1:  271:        external32_float_convert(((char *) bufp) + rel_off,
        -:  272:				 paramp->u.unpack.unpack_buffer,
        -:  273:                                 dest_el_size, src_el_size, *blocks_p);
        -:  274:    }
        -:  275:    else
        -:  276:    {
        2:  277:        external32_basic_convert(((char *) bufp) + rel_off,
        -:  278:				 paramp->u.unpack.unpack_buffer,
        -:  279:                                 dest_el_size, src_el_size, *blocks_p);
        -:  280:    }
        4:  281:    paramp->u.unpack.unpack_buffer += (dest_el_size * (*blocks_p));
        -:  282:
        -:  283:    MPIDI_FUNC_EXIT(MPID_STATE_MPID_SEGMENT_CONTIG_UNPACK_EXTERNAL32_TO_BUF);
        4:  284:    return 0;
        -:  285:}
        -:  286:
        -:  287:#undef FUNCNAME
        -:  288:#define FUNCNAME MPID_Segment_pack_external32
        -:  289:#undef FCNAME
        -:  290:#define FCNAME MPIDI_QUOTE(FUNCNAME)
        -:  291:void MPID_Segment_pack_external32(struct DLOOP_Segment *segp,
        -:  292:				  DLOOP_Offset first,
        -:  293:				  DLOOP_Offset *lastp, 
        -:  294:				  void *pack_buffer)
        4:  295:{
        -:  296:    struct MPID_Segment_piece_params pack_params;
        -:  297:    MPIDI_STATE_DECL(MPID_STATE_MPID_SEGMENT_PACK_EXTERNAL);
        -:  298:    
        -:  299:    MPIDI_FUNC_ENTER(MPID_STATE_MPID_SEGMENT_PACK_EXTERNAL);
        -:  300:
        4:  301:    pack_params.u.pack.pack_buffer = (DLOOP_Buffer)pack_buffer;
        4:  302:    MPID_Segment_manipulate(segp,
        -:  303:			    first,
        -:  304:			    lastp,
        -:  305:			    MPID_Segment_contig_pack_external32_to_buf,
        -:  306:                            NULL, /* MPID_Segment_vector_pack_external32_to_buf, */
        -:  307:			    NULL, /* blkidx */
        -:  308:                            NULL, /* MPID_Segment_index_pack_external32_to_buf, */
        -:  309:                            MPIDI_Datatype_get_basic_size_external32,
        -:  310:			    &pack_params);
        -:  311:
        -:  312:    MPIDI_FUNC_EXIT(MPID_STATE_MPID_SEGMENT_PACK_EXTERNAL);
        -:  313:    return;
        -:  314:}
        -:  315:
        -:  316:#undef FUNCNAME
        -:  317:#define FUNCNAME MPID_Segment_unpack_external32
        -:  318:#undef FCNAME
        -:  319:#define FCNAME MPIDI_QUOTE(FUNCNAME)
        -:  320:void MPID_Segment_unpack_external32(struct DLOOP_Segment *segp,
        -:  321:				    DLOOP_Offset first,
        -:  322:				    DLOOP_Offset *lastp,
        -:  323:				    DLOOP_Buffer unpack_buffer)
        4:  324:{
        -:  325:    struct MPID_Segment_piece_params pack_params;
        -:  326:    MPIDI_STATE_DECL(MPID_STATE_MPID_SEGMENT_UNPACK_EXTERNAL32);
        -:  327:    
        -:  328:    MPIDI_FUNC_ENTER(MPID_STATE_MPID_SEGMENT_UNPACK_EXTERNAL32);
        -:  329:
        4:  330:    pack_params.u.unpack.unpack_buffer = unpack_buffer;
        4:  331:    MPID_Segment_manipulate(segp,
        -:  332:			    first,
        -:  333:			    lastp,
        -:  334:			    MPID_Segment_contig_unpack_external32_to_buf,
        -:  335:                            NULL, /* MPID_Segment_vector_unpack_external32_to_buf, */
        -:  336:			    NULL, /* blkidx */
        -:  337:                            NULL, /* MPID_Segment_index_unpack_external32_to_buf, */
        -:  338:                            MPIDI_Datatype_get_basic_size_external32,
        -:  339:			    &pack_params);
        -:  340:
        -:  341:    MPIDI_FUNC_EXIT(MPID_STATE_MPID_SEGMENT_UNPACK_EXTERNAL32);
        -:  342:    return;
        -:  343:}