root/opal/datatype/opal_datatype_clone.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. opal_datatype_clone

   1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
   2 /*
   3  * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2017 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2006 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2009      Sun Microsystems, Inc. All rights reserved.
  14  * Copyright (c) 2009      Oak Ridge National Labs.  All rights reserved.
  15  * Copyright (c) 2019      Research Organization for Information Science
  16  *                         and Technology (RIST).  All rights reserved.
  17  * $COPYRIGHT$
  18  *
  19  * Additional copyrights may follow
  20  *
  21  * $HEADER$
  22  */
  23 
  24 #include "opal_config.h"
  25 #include "opal/constants.h"
  26 #include "opal/datatype/opal_datatype.h"
  27 #include "opal/datatype/opal_datatype_internal.h"
  28 
  29 /*
  30  * As the new type has the same commit state as the old one, I have to copy the fake
  31  * OPAL_DATATYPE_END_LOOP from the description (both normal and optimized).
  32  *
  33  * Clone all the values from oldType into newType without allocating a new datatype.
  34  */
  35 int32_t opal_datatype_clone( const opal_datatype_t * src_type, opal_datatype_t * dest_type )
  36 {
  37     int32_t desc_length = src_type->desc.used + 1;  /* +1 because of the fake OPAL_DATATYPE_END_LOOP entry */
  38     dt_elem_desc_t* temp = dest_type->desc.desc;    /* temporary copy of the desc pointer */
  39 
  40     /* copy _excluding_ the super object, we want to keep the cls_destruct_array */
  41     memcpy( (char*)dest_type + sizeof(opal_object_t),
  42             (char*)src_type + sizeof(opal_object_t),
  43             sizeof(opal_datatype_t)-sizeof(opal_object_t) );
  44 
  45     dest_type->flags &= (~OPAL_DATATYPE_FLAG_PREDEFINED);
  46     dest_type->ptypes = NULL;
  47     dest_type->desc.desc = temp;
  48 
  49     /**
  50      * Allow duplication of MPI_UB and MPI_LB.
  51      */
  52     if( 0 != src_type->desc.used ) {
  53         memcpy( dest_type->desc.desc, src_type->desc.desc, sizeof(dt_elem_desc_t) * desc_length );
  54         if( 0 != src_type->opt_desc.used ) {
  55             if( src_type->opt_desc.desc == src_type->desc.desc) {
  56                 dest_type->opt_desc = dest_type->desc;
  57             } else {
  58                 desc_length = dest_type->opt_desc.used + 1;
  59                 dest_type->opt_desc.desc = (dt_elem_desc_t*)malloc( desc_length * sizeof(dt_elem_desc_t) );
  60                 /*
  61                  * Yes, the dest_type->opt_desc.length is just the opt_desc.used of the old Type.
  62                  */
  63                 dest_type->opt_desc.length = src_type->opt_desc.used;
  64                 dest_type->opt_desc.used = src_type->opt_desc.used;
  65                 memcpy( dest_type->opt_desc.desc, src_type->opt_desc.desc, desc_length * sizeof(dt_elem_desc_t) );
  66             }
  67         } else {
  68             assert( NULL == dest_type->opt_desc.desc );
  69             assert( 0 == dest_type->opt_desc.length );
  70         }
  71     }
  72     dest_type->id  = src_type->id;  /* preserve the default id. This allow us to
  73                                      * copy predefined types. */
  74     return OPAL_SUCCESS;
  75 }

/* [<][>][^][v][top][bottom][index][help] */