root/test/datatype/ddt_raw.c

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

DEFINITIONS

This source file includes following definitions.
  1. test_upper
  2. local_copy_ddt_raw
  3. main

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   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-2019 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) 2006      Sun Microsystems Inc. All rights reserved.
  14  * Copyright (c) 2018      Los Alamos National Security, LLC. All rights
  15  *                         reserved.
  16  * Copyright (c) 2018      Triad National Security, LLC. All rights
  17  *                         reserved.
  18  * $COPYRIGHT$
  19  *
  20  * Additional copyrights may follow
  21  *
  22  * $HEADER$
  23  */
  24 
  25 #include "ompi_config.h"
  26 #include "ddt_lib.h"
  27 #include "opal/datatype/opal_convertor.h"
  28 #include "opal/runtime/opal.h"
  29 
  30 #include <time.h>
  31 #include <stdlib.h>
  32 #ifdef HAVE_SYS_TIME_H
  33 #include <sys/time.h>
  34 #endif
  35 #include <stdio.h>
  36 
  37 /* Compile with:
  38 mpicc -DHAVE_CONFIG_H -I. -I../../include -I../../../ompi-trunk/include  -I../.. -I../../include -I../../../ompi-trunk/opal -I../../../ompi-trunk/orte -I../../../ompi-trunk/ompi -g ddt_test.c -o ddt_test
  39 */
  40 
  41 #define TIMER_DATA_TYPE struct timeval
  42 #define GET_TIME(TV)   gettimeofday( &(TV), NULL )
  43 #define ELAPSED_TIME(TSTART, TEND)  (((TEND).tv_sec - (TSTART).tv_sec) * 1000000 + ((TEND).tv_usec - (TSTART).tv_usec))
  44 
  45 #define DUMP_DATA_AFTER_COMMIT 0x00000001
  46 #define CHECK_PACK_UNPACK      0x00000002
  47 
  48 uint32_t remote_arch = 0xffffffff;
  49 
  50 static int test_upper( unsigned int length )
  51 {
  52     ompi_datatype_t *pdt;
  53     opal_convertor_t * pConv;
  54     int rc = OMPI_SUCCESS;
  55     unsigned int i, iov_count, total_length;
  56     size_t max_data;
  57     struct iovec iov[5];
  58     TIMER_DATA_TYPE start, end;
  59     long total_time;
  60 
  61     printf( "test upper matrix\n" );
  62     pdt = upper_matrix( length );
  63     /*dt_dump( pdt );*/
  64 
  65     total_length = length * (length + 1) * ( sizeof(double) / 2);
  66 
  67     pConv = opal_convertor_create( remote_arch, 0 );
  68     if( OMPI_SUCCESS != opal_convertor_prepare_for_send( pConv, &(pdt->super), 1, NULL ) ) {
  69         printf( "Cannot attach the datatype to a convertor\n" );
  70         return OMPI_ERROR;
  71     }
  72 
  73     GET_TIME( start );
  74     for( i = total_length; i > 0; ) {
  75         iov_count = 5;
  76         max_data = 0;
  77         opal_convertor_raw( pConv, iov, &iov_count, &max_data );
  78         i -= max_data;
  79     }
  80     GET_TIME( end );
  81     total_time = ELAPSED_TIME( start, end );
  82     printf( "complete raw in %ld microsec\n", total_time );
  83 
  84     /* test the automatic destruction pf the data */
  85     ompi_datatype_destroy( &pdt ); assert( pdt == NULL );
  86 
  87     OBJ_RELEASE( pConv );
  88     return rc;
  89 }
  90 
  91 /**
  92  * Conversion function. They deal with datatypes in 3 ways, always making local copies.
  93  * In order to allow performance testings, there are 3 functions:
  94  *  - one copying directly from one memory location to another one using the
  95  *    datatype copy function.
  96  *  - one which use a 2 convertors created with the same datatype
  97  *  - and one using 2 convertors created from different datatypes.
  98  *
  99  */
 100 static int local_copy_ddt_raw( ompi_datatype_t* pdt, int count, int iov_num )
 101 {
 102     struct iovec* iov;
 103     opal_convertor_t* convertor;
 104     TIMER_DATA_TYPE start, end;
 105     long total_time;
 106     uint32_t iov_count = iov_num;
 107     size_t max_data = 0, remaining_length;
 108 
 109     iov = (struct iovec*)malloc(iov_num * sizeof(struct iovec));
 110 
 111     convertor = opal_convertor_create( remote_arch, 0 );
 112     if( OMPI_SUCCESS != opal_convertor_prepare_for_send( convertor, &(pdt->super), count, NULL ) ) {
 113         printf( "Cannot attach the datatype to a convertor\n" );
 114         return OMPI_ERROR;
 115     }
 116 
 117     remaining_length = count * pdt->super.size;
 118     GET_TIME( start );
 119     while( 0 == opal_convertor_raw(convertor, iov, &iov_count, &max_data) ) {
 120 #if 0
 121         printf( "New raw extraction (iov_count = %d, max_data = %zu)\n",
 122                 iov_count, max_data );
 123         for( i = 0; i < iov_count; i++ ) {
 124             printf( "\t{%p, %d}\n", iov[i].iov_base, iov[i].iov_len );
 125         }
 126 #endif
 127         remaining_length -= max_data;
 128         iov_count = iov_num;
 129     }
 130     remaining_length -= max_data;
 131     GET_TIME( end );
 132     total_time = ELAPSED_TIME( start, end );
 133     printf( "raw extraction in %ld microsec\n", total_time );
 134     OBJ_RELEASE( convertor );
 135     if( remaining_length != 0 ) {
 136         printf( "Not all raw description was been extracted (%lu bytes missing)\n",
 137                 (unsigned long) remaining_length );
 138     }
 139     free(iov);
 140     return OMPI_SUCCESS;
 141 }
 142 
 143 /**
 144  * Go over a set of datatypes and copy them using the raw functionality provided by the
 145  * convertor. The goal of this test is to stress the convertor using several more or less
 146  * difficult datatype, with a large set of segment sizes for the conversion. It can be used
 147  * to highlight the raw capability of the convertor as well as detecting datatype convertor
 148  * problems.
 149  *
 150  * This test is part of the testing infrastructure for the core datatype engine. As such any
 151  * modifications on the datatype engine should first pass all the tests from this file,
 152  * before going into other tests.
 153  */
 154 int main( int argc, char* argv[] )
 155 {
 156     ompi_datatype_t *pdt, *pdt1, *pdt2, *pdt3;
 157     int rc, length = 500, iov_num = 5;
 158 
 159     opal_init_util (NULL, NULL);
 160     ompi_datatype_init();
 161 
 162     /**
 163      * By default simulate homogeneous architectures.
 164      */
 165     remote_arch = opal_local_arch;
 166     printf( "\n\n#\n * TEST INVERSED VECTOR\n #\n\n" );
 167     pdt = create_inversed_vector( &ompi_mpi_int.dt, 10 );
 168     if( outputFlags & CHECK_PACK_UNPACK ) {
 169         local_copy_ddt_raw(pdt, 100, iov_num);
 170     }
 171     OBJ_RELEASE( pdt ); assert( pdt == NULL );
 172     printf( "\n\n#\n * TEST STRANGE DATATYPE\n #\n\n" );
 173     pdt = create_strange_dt();
 174     if( outputFlags & CHECK_PACK_UNPACK ) {
 175         local_copy_ddt_raw(pdt, 1, iov_num);
 176     }
 177     OBJ_RELEASE( pdt ); assert( pdt == NULL );
 178 
 179     printf( "\n\n#\n * TEST UPPER TRIANGULAR MATRIX (size 100)\n #\n\n" );
 180     pdt = upper_matrix(100);
 181     if( outputFlags & CHECK_PACK_UNPACK ) {
 182         local_copy_ddt_raw(pdt, 1, iov_num);
 183     }
 184     OBJ_RELEASE( pdt ); assert( pdt == NULL );
 185 
 186     printf( "\n\n#\n * TEST UPPER MATRIX\n #\n\n" );
 187     rc = test_upper( length );
 188     if( rc == 0 )
 189         printf( "decode [PASSED]\n" );
 190     else
 191         printf( "decode [NOT PASSED]\n" );
 192 
 193     printf( "\n\n#\n * TEST MATRIX BORDERS\n #\n\n" );
 194     pdt = test_matrix_borders( length, 100 );
 195     if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
 196         ompi_datatype_dump( pdt );
 197     }
 198     OBJ_RELEASE( pdt ); assert( pdt == NULL );
 199 
 200     printf( "\n\n#\n * TEST CONTIGUOUS\n #\n\n" );
 201     pdt = test_contiguous();
 202     OBJ_RELEASE( pdt ); assert( pdt == NULL );
 203     printf( "\n\n#\n * TEST STRUCT\n #\n\n" );
 204     pdt = test_struct();
 205     OBJ_RELEASE( pdt ); assert( pdt == NULL );
 206 
 207     ompi_datatype_create_contiguous(0, &ompi_mpi_datatype_null.dt, &pdt1);
 208     ompi_datatype_create_contiguous(0, &ompi_mpi_datatype_null.dt, &pdt2);
 209     ompi_datatype_create_contiguous(0, &ompi_mpi_datatype_null.dt, &pdt3);
 210 
 211     ompi_datatype_add( pdt3, &ompi_mpi_int.dt, 10, 0, -1 );
 212     ompi_datatype_add( pdt3, &ompi_mpi_float.dt, 5, 10 * sizeof(int), -1 );
 213 
 214     ompi_datatype_add( pdt2, &ompi_mpi_float.dt, 1, 0, -1 );
 215     ompi_datatype_add( pdt2, pdt3, 3, sizeof(int) * 1, -1 );
 216 
 217     ompi_datatype_add( pdt1, &ompi_mpi_long_long_int.dt, 5, 0, -1 );
 218     ompi_datatype_add( pdt1, &ompi_mpi_long_double.dt, 2, sizeof(long long) * 5, -1 );
 219 
 220     printf( ">>--------------------------------------------<<\n" );
 221     if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
 222         ompi_datatype_dump( pdt1 );
 223     }
 224     printf( ">>--------------------------------------------<<\n" );
 225     if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
 226         ompi_datatype_dump( pdt2 );
 227     }
 228     printf( ">>--------------------------------------------<<\n" );
 229     if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
 230         ompi_datatype_dump( pdt3 );
 231     }
 232 
 233     OBJ_RELEASE( pdt1 ); assert( pdt1 == NULL );
 234     OBJ_RELEASE( pdt2 ); assert( pdt2 == NULL );
 235     OBJ_RELEASE( pdt3 ); assert( pdt3 == NULL );
 236 
 237     printf( ">>--------------------------------------------<<\n" );
 238     printf( " Contiguous datatype (MPI_DOUBLE)\n" );
 239     pdt = MPI_DOUBLE;
 240     if( outputFlags & CHECK_PACK_UNPACK ) {
 241         local_copy_ddt_raw(pdt, 4500, iov_num);
 242     }
 243     printf( ">>--------------------------------------------<<\n" );
 244 
 245     printf( ">>--------------------------------------------<<\n" );
 246     if( outputFlags & CHECK_PACK_UNPACK ) {
 247         printf( "Contiguous multiple datatype (4500*1)\n" );
 248         pdt = create_contiguous_type( MPI_DOUBLE, 4500 );
 249         local_copy_ddt_raw(pdt, 1, iov_num);
 250         OBJ_RELEASE( pdt ); assert( pdt == NULL );
 251         printf( "Contiguous multiple datatype (450*10)\n" );
 252         pdt = create_contiguous_type( MPI_DOUBLE, 450 );
 253         local_copy_ddt_raw(pdt, 10, iov_num);
 254         OBJ_RELEASE( pdt ); assert( pdt == NULL );
 255         printf( "Contiguous multiple datatype (45*100)\n" );
 256         pdt = create_contiguous_type( MPI_DOUBLE, 45 );
 257         local_copy_ddt_raw(pdt, 100, iov_num);
 258         OBJ_RELEASE( pdt ); assert( pdt == NULL );
 259         printf( "Contiguous multiple datatype (100*45)\n" );
 260         pdt = create_contiguous_type( MPI_DOUBLE, 100 );
 261         local_copy_ddt_raw(pdt, 45, iov_num);
 262         OBJ_RELEASE( pdt ); assert( pdt == NULL );
 263         printf( "Contiguous multiple datatype (10*450)\n" );
 264         pdt = create_contiguous_type( MPI_DOUBLE, 10 );
 265         local_copy_ddt_raw(pdt, 450, iov_num);
 266         OBJ_RELEASE( pdt ); assert( pdt == NULL );
 267         printf( "Contiguous multiple datatype (1*4500)\n" );
 268         pdt = create_contiguous_type( MPI_DOUBLE, 1 );
 269         local_copy_ddt_raw(pdt, 4500, iov_num);
 270         OBJ_RELEASE( pdt ); assert( pdt == NULL );
 271     }
 272     printf( ">>--------------------------------------------<<\n" );
 273     printf( ">>--------------------------------------------<<\n" );
 274     printf( "Vector datatype (450 times 10 double stride 11)\n" );
 275     pdt = create_vector_type( MPI_DOUBLE, 450, 10, 11 );
 276     if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
 277         ompi_datatype_dump( pdt );
 278     }
 279     if( outputFlags & CHECK_PACK_UNPACK ) {
 280         local_copy_ddt_raw(pdt, 1, iov_num);
 281     }
 282     printf( ">>--------------------------------------------<<\n" );
 283     OBJ_RELEASE( pdt ); assert( pdt == NULL );
 284 
 285     printf( ">>--------------------------------------------<<\n" );
 286     pdt = test_struct_char_double();
 287     if( outputFlags & CHECK_PACK_UNPACK ) {
 288         local_copy_ddt_raw(pdt, 4500, iov_num);
 289     }
 290     printf( ">>--------------------------------------------<<\n" );
 291     OBJ_RELEASE( pdt ); assert( pdt == NULL );
 292 
 293     printf( ">>--------------------------------------------<<\n" );
 294     pdt = test_create_twice_two_doubles();
 295     if( outputFlags & CHECK_PACK_UNPACK ) {
 296         local_copy_ddt_raw(pdt, 4500, iov_num);
 297     }
 298     printf( ">>--------------------------------------------<<\n" );
 299     OBJ_RELEASE( pdt ); assert( pdt == NULL );
 300 
 301     printf( ">>--------------------------------------------<<\n" );
 302     pdt = test_create_blacs_type();
 303     if( outputFlags & CHECK_PACK_UNPACK ) {
 304         if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
 305             ompi_datatype_dump( pdt );
 306         }
 307         local_copy_ddt_raw(pdt, 4500, iov_num);
 308     }
 309     printf( ">>--------------------------------------------<<\n" );
 310     OBJ_RELEASE( pdt ); assert( pdt == NULL );
 311 
 312     printf( ">>--------------------------------------------<<\n" );
 313     pdt1 = test_create_blacs_type1( &ompi_mpi_int.dt );
 314     if( outputFlags & CHECK_PACK_UNPACK ) {
 315         local_copy_ddt_raw( pdt1, 1, iov_num );
 316     }
 317     printf( ">>--------------------------------------------<<\n" );
 318     OBJ_RELEASE( pdt1 ); assert( pdt1 == NULL );
 319 
 320     /* clean-ups all data allocations */
 321     ompi_datatype_finalize();
 322     opal_finalize_util ();
 323 
 324     return OMPI_SUCCESS;
 325 }

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