root/test/datatype/unpack_hetero.c

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

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
   2 /*
   3  * Copyright (c) 2014-2016 Research Organization for Information Science
   4  *                         and Technology (RIST). All rights reserved.
   5  * $COPYRIGHT$
   6  *
   7  * Additional copyrights may follow
   8  *
   9  * $HEADER$
  10  */
  11 
  12 #include "opal_config.h"
  13 #include "opal/runtime/opal.h"
  14 #include "opal/datatype/opal_datatype.h"
  15 #include "opal/datatype/opal_datatype_internal.h"
  16 #include "opal/datatype/opal_convertor.h"
  17 #include "opal/datatype/opal_datatype_prototypes.h"
  18 #include "opal/util/arch.h"
  19 #include <time.h>
  20 #include <stdlib.h>
  21 #ifdef HAVE_SYS_TIME_H
  22 #include <sys/time.h>
  23 #endif
  24 #include <stdio.h>
  25 #include <string.h>
  26 
  27 /* Compile with:
  28 gcc -DHAVE_CONFIG_H -I. -I../../include -I../.. -I../../include -I../../../ompi-trunk/opal -I../../../ompi-trunk/orte -g opal_datatype_test.c -o opal_datatype_test
  29 */
  30 
  31 uint32_t remote_arch = 0xffffffff;
  32 
  33 /**
  34  * Main function. Call several tests and print-out the results. It try to stress the convertor
  35  * using difficult data-type constructions as well as strange segment sizes for the conversion.
  36  * Usually, it is able to detect most of the data-type and convertor problems. Any modifications
  37  * on the data-type engine should first pass all the tests from this file, before going into other
  38  * tests.
  39  */
  40 int main( int argc, char* argv[] )
  41 {
  42     opal_init_util (NULL, NULL);
  43 
  44     /**
  45      * By default simulate homogeneous architectures.
  46      */
  47     remote_arch = opal_local_arch ^ OPAL_ARCH_ISBIGENDIAN;
  48 
  49     opal_convertor_t * pConv;
  50     int sbuf[2], rbuf[2];
  51     size_t max_data;
  52     struct iovec a;
  53     uint32_t iov_count;
  54 
  55     sbuf[0] = 0x01000000; sbuf[1] = 0x02000000;
  56 
  57     printf( "\n\n#\n * TEST UNPACKING 1 int out of 1\n#\n\n" );
  58 
  59     pConv = opal_convertor_create( remote_arch, 0 );
  60     rbuf[0] = -1; rbuf[1] = -1;
  61     if( OPAL_SUCCESS != opal_convertor_prepare_for_recv( pConv, &opal_datatype_int4, 1, rbuf ) ) {
  62         printf( "Cannot attach the datatype to a convertor\n" );
  63         return OPAL_ERROR;
  64     }
  65     
  66     a.iov_base = sbuf;
  67     a.iov_len = 4;
  68     iov_count = 1;
  69     max_data = 4;
  70     opal_unpack_general( pConv, &a, &iov_count, &max_data );
  71 
  72     assert(1 == rbuf[0]);
  73     assert(-1 == rbuf[1]);
  74     OBJ_RELEASE(pConv);
  75 
  76     printf( "\n\n#\n * TEST UNPACKING 1 int out of 2\n#\n\n" );
  77     pConv = opal_convertor_create( remote_arch, 0 );
  78     rbuf[0] = -1; rbuf[1] = -1;
  79     if( OPAL_SUCCESS != opal_convertor_prepare_for_recv( pConv, &opal_datatype_int4, 2, rbuf ) ) {
  80         printf( "Cannot attach the datatype to a convertor\n" );
  81         return OPAL_ERROR;
  82     }
  83     
  84 
  85     a.iov_base = sbuf;
  86     a.iov_len = 4;
  87     iov_count = 1;
  88     max_data = 4;
  89     opal_unpack_general( pConv, &a, &iov_count, &max_data );
  90 
  91     assert(1 == rbuf[0]);
  92     assert(-1 == rbuf[1]);
  93     OBJ_RELEASE(pConv);
  94 
  95     /* clean-ups all data allocations */
  96     opal_finalize_util ();
  97 
  98     return OPAL_SUCCESS;
  99 }

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