root/test/datatype/opal_ddt_lib.c

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

DEFINITIONS

This source file includes following definitions.
  1. cache_trash
  2. test_create_twice_two_doubles
  3. test_create_blacs_type
  4. test_create_blacs_type1
  5. test_create_blacs_type2
  6. test_struct
  7. test_struct_char_double
  8. create_strange_dt
  9. create_vector_type
  10. create_contiguous_type
  11. create_struct_constant_gap_resized_ddt
  12. opal_datatype_create_indexed
  13. opal_datatype_create_hindexed
  14. opal_datatype_create_struct
  15. opal_datatype_create_vector
  16. opal_datatype_create_hvector
  17. init_random_upper_matrix
  18. check_diag_matrix
  19. upper_matrix
  20. lower_matrix
  21. test_matrix_borders
  22. test_contiguous

   1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
   2 /*
   3  * Copyright (c) 2009-2014 The University of Tennessee and The University
   4  *                         of Tennessee Research Foundation.  All rights
   5  *                         reserved.
   6  * Copyright (c) 2009      Oak Ridge National Labs.  All rights reserved.
   7  * Copyright (c) 2017      Research Organization for Information Science
   8  *                         and Technology (RIST). All rights reserved.
   9  * $COPYRIGHT$
  10  *
  11  * Additional copyrights may follow
  12  *
  13  * $HEADER$
  14  */
  15 
  16 #include "opal_config.h"
  17 
  18 #include <stdio.h>
  19 #include <string.h>
  20 #include <time.h>
  21 
  22 #include "opal_ddt_lib.h"
  23 
  24 #include "opal/constants.h"
  25 #include "opal/datatype/opal_datatype.h"
  26 
  27 
  28 uint32_t outputFlags = VALIDATE_DATA | CHECK_PACK_UNPACK | RESET_CONVERTORS | QUIT_ON_FIRST_ERROR;
  29 
  30 static int32_t opal_datatype_create_indexed( int count, const int* pBlockLength, const int* pDisp,
  31                                              const opal_datatype_t* oldType, opal_datatype_t** newType );
  32 static int32_t opal_datatype_create_hindexed( int count, const int* pBlockLength, const ptrdiff_t* pDisp,
  33                                               const opal_datatype_t* oldType, opal_datatype_t** newType );
  34 static int32_t opal_datatype_create_struct( int count, const int* pBlockLength,
  35                                             const ptrdiff_t* pDisp,
  36                                             opal_datatype_t** pTypes, opal_datatype_t** newType );
  37 static int32_t opal_datatype_create_vector( int count, int bLength, int stride,
  38                                             const opal_datatype_t* oldType, opal_datatype_t** newType );
  39 static int32_t opal_datatype_create_hvector( int count, int bLength, ptrdiff_t stride,
  40                                              const opal_datatype_t* oldType, opal_datatype_t** newType );
  41 
  42 
  43 /**
  44  * Cache cleanup.
  45  */
  46 #define CACHE_SIZE (4*1024*1024)
  47 void cache_trash( void )
  48 {
  49     char* buffer;
  50 
  51     buffer = (char*)malloc( sizeof(char) * CACHE_SIZE );
  52     memset( buffer, 1, CACHE_SIZE );
  53     memset( buffer, 0xff, CACHE_SIZE );
  54     free( buffer );
  55 }
  56 
  57 opal_datatype_t* test_create_twice_two_doubles( void )
  58 {
  59     opal_datatype_t* pdt;
  60 
  61     opal_datatype_create_vector( 2, 2, 5, &opal_datatype_float8, &pdt );
  62     opal_datatype_commit( pdt );
  63     if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
  64         opal_datatype_dump( pdt );
  65     }
  66     return pdt;
  67 }
  68 
  69 
  70 /*
  71   Datatype 0x832cf28 size 0 align 1 id 0 length 4 used 0
  72   true_lb 0 true_ub 0 (true_extent 0) lb 0 ub 0 (extent 0)
  73   nbElems 0 loops 0 flags 6 (committed contiguous )-cC--------[---][---]
  74   contain 13 disp 0x420 (1056) extent 4
  75   --C-----D*-[ C ][INT]        MPI_INT count 13 disp 0x478 (1144) extent 4
  76   --C-----D*-[ C ][INT]        MPI_INT count 13 disp 0x4d0 (1232) extent 4
  77   --C-----D*-[ C ][INT]        MPI_INT count 13 disp 0x528 (1320) extent 4
  78   --C-----D*-[ C ][INT]        MPI_INT count 13 disp 0x580 (1408) extent 4
  79   --C-----D*-[ C ][INT]        MPI_INT count 13 disp 0x5d8 (1496) extent 4
  80   --C-----D*-[ C ][INT]        MPI_INT count 13 disp 0x630 (1584) extent 4
  81   --C-----D*-[ C ][INT]        MPI_INT count 12 disp 0x68c (1676) extent 4
  82   --C-----D*-[ C ][INT]        MPI_INT count 11 disp 0x6e8 (1768) extent 4
  83   --C-----D*-[ C ][INT]        MPI_INT count 10 disp 0x744 (1860) extent 4
  84   --C-----D*-[ C ][INT]        MPI_INT count 9 disp 0x7a0 (1952) extent 4
  85   --C-----D*-[ C ][INT]        MPI_INT count 8 disp 0x7fc (2044) extent 4
  86   --C-----D*-[ C ][INT]        MPI_INT count 7 disp 0x858 (2136) extent 4
  87   --C-----D*-[ C ][INT]        MPI_INT count 6 disp 0x8b4 (2228) extent 4
  88   --C-----D*-[ C ][INT]        MPI_INT count 5 disp 0x910 (2320) extent 4
  89   --C-----D*-[ C ][INT]        MPI_INT count 4 disp 0x96c (2412) extent 4
  90   --C-----D*-[ C ][INT]        MPI_INT count 3 disp 0x9c8 (2504) extent 4
  91   --C-----D*-[ C ][INT]        MPI_INT count 2 disp 0xa24 (2596) extent 4
  92   --C-----D*-[ C ][INT]        MPI_INT count 1 disp 0xa80 (2688) extent 4
  93 */
  94 static int blacs_length[] = { 13, 13, 13, 13, 13, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
  95 static int blacs_indices[] = { 1144/4, 1232/4, 1320/4, 1408/4, 1496/4, 1584/4, 1676/4, 1768/4,
  96                                1860/4, 1952/4, 2044/4, 2136/4, 2228/4, 2320/4, 2412/4, 2504/4,
  97                                2596/4, 2688/4 };
  98 opal_datatype_t* test_create_blacs_type( void )
  99 {
 100     opal_datatype_t *pdt;
 101 
 102     opal_datatype_create_indexed( 18, blacs_length, blacs_indices, &opal_datatype_int4, &pdt );
 103     opal_datatype_commit( pdt );
 104     if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
 105         opal_datatype_dump( pdt );
 106     }
 107     return pdt;
 108 }
 109 
 110 opal_datatype_t* test_create_blacs_type1( opal_datatype_t const * const base_type )
 111 {
 112     opal_datatype_t *pdt;
 113 
 114     opal_datatype_create_vector( 7, 1, 3, base_type, &pdt );
 115     opal_datatype_commit( pdt );
 116     if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
 117         opal_datatype_dump( pdt );
 118     }
 119     return pdt;
 120 }
 121 
 122 opal_datatype_t* test_create_blacs_type2( opal_datatype_t const * const base_type )
 123 {
 124     opal_datatype_t *pdt;
 125 
 126     opal_datatype_create_vector( 7, 1, 2, base_type, &pdt );
 127     opal_datatype_commit( pdt );
 128     if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
 129         opal_datatype_dump( pdt );
 130     }
 131     return pdt;
 132 }
 133 
 134 
 135 opal_datatype_t* test_struct( void )
 136 {
 137     opal_datatype_t* types[] = { (opal_datatype_t*)&opal_datatype_float4,
 138                                  NULL,
 139                                  (opal_datatype_t*)&opal_datatype_int1 };
 140     int lengths[] = { 2, 1, 3 };
 141     ptrdiff_t disp[] = { 0, 16, 26 };
 142     opal_datatype_t* pdt, *pdt1;
 143 
 144     printf( "test struct\n" );
 145     opal_datatype_create_contiguous(0, &opal_datatype_empty, &pdt1);
 146     opal_datatype_add( pdt1, &opal_datatype_float8, 1, 0, -1 );
 147     opal_datatype_add( pdt1, &opal_datatype_int1, 1, 8, -1 );
 148     if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
 149         opal_datatype_dump( pdt1 );
 150     }
 151 
 152     types[1] = pdt1;
 153 
 154     opal_datatype_create_struct( 3, lengths, disp, types, &pdt );
 155     OBJ_RELEASE( pdt1 ); /*assert( pdt1 == NULL );*/
 156     if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
 157         opal_datatype_dump( pdt );
 158     }
 159     return pdt;
 160 }
 161 
 162 typedef struct __struct_char_double {
 163     char c;
 164     double d;
 165 } char_double_t;
 166 
 167 opal_datatype_t* test_struct_char_double( void )
 168 {
 169     char_double_t data;
 170     int lengths[] = {1, 1};
 171     ptrdiff_t displ[] = {0, 0};
 172     opal_datatype_t *pdt;
 173     opal_datatype_t* types[] = { (opal_datatype_t*)&opal_datatype_int1,
 174                                  (opal_datatype_t*)&opal_datatype_float8};
 175 
 176     displ[0] = (char*)&(data.c) - (char*)&(data);
 177     displ[1] = (char*)&(data.d) - (char*)&(data);
 178 
 179     opal_datatype_create_struct( 2, lengths, displ, types, &pdt );
 180     opal_datatype_commit( pdt );
 181     if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
 182         opal_datatype_dump( pdt );
 183     }
 184     return pdt;
 185 }
 186 
 187 typedef struct {
 188     int i1;
 189     int gap;
 190     int i2;
 191 } sdata_intern;
 192 
 193 typedef struct {
 194     int counter;
 195     sdata_intern v[10];
 196     int last;
 197 } sstrange;
 198 
 199 #define SSTRANGE_CNT 10
 200 #define USE_RESIZED
 201 
 202 opal_datatype_t* create_strange_dt( void )
 203 {
 204     sdata_intern v[2];
 205     ptrdiff_t displ[3];
 206     opal_datatype_t *pdt, *pdt1;
 207 
 208     opal_datatype_create_contiguous(0, &opal_datatype_empty, &pdt1);
 209     opal_datatype_add( pdt1, &opal_datatype_float8, 1, 0, -1 );
 210     opal_datatype_add( pdt1, &opal_datatype_int1, 1, 8, -1 );
 211 
 212 #ifdef USE_RESIZED
 213     /* optional */
 214     displ[0] = 0;
 215     displ[1] = (char*)&(v[1]) - (char*)&(v[0]);
 216     opal_datatype_resize( pdt1, displ[0], displ[1]);
 217 #endif  /* USE_RESIZED */
 218 
 219     opal_datatype_create_contiguous( SSTRANGE_CNT, pdt1, &pdt );
 220 
 221     OBJ_RELEASE( pdt1 );
 222     printf( "\nStrange datatype BEFORE COMMIT\n" );
 223     if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
 224         opal_datatype_dump( pdt );
 225     }
 226 
 227     opal_datatype_commit( pdt );
 228     printf( "\nStrange datatype AFTER COMMIT\n" );
 229     if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
 230         opal_datatype_dump( pdt );
 231     }
 232     return pdt;
 233 }
 234 
 235 opal_datatype_t* create_vector_type( const opal_datatype_t* data, int count, int length, int stride )
 236 {
 237     opal_datatype_t* vector;
 238 
 239     opal_datatype_create_vector( count, length, stride, data, &vector );
 240     opal_datatype_commit( vector );
 241     return vector;
 242 }
 243 
 244 
 245 opal_datatype_t* create_contiguous_type( const opal_datatype_t* type, int length )
 246 {
 247    opal_datatype_t* newtype;
 248 
 249    opal_datatype_create_contiguous( length, type, &newtype );
 250    opal_datatype_commit( newtype );
 251 
 252    return newtype;
 253 }
 254 
 255 /* Create a non-contiguous resized datatype */
 256 struct structure {
 257     double not_transfered;
 258     double transfered_1;
 259     double transfered_2;
 260 };
 261 
 262 opal_datatype_t* create_struct_constant_gap_resized_ddt( const opal_datatype_t* type )
 263 {
 264     opal_datatype_t *struct_type;
 265 
 266     opal_datatype_create_contiguous(0, &opal_datatype_empty, &struct_type);
 267     opal_datatype_add( struct_type, &opal_datatype_float8, 1,  8, -1 );
 268     opal_datatype_add( struct_type, &opal_datatype_float8, 1, 16, -1 );
 269 
 270     opal_datatype_resize(struct_type, 0, sizeof(struct structure));
 271     opal_datatype_commit(struct_type);
 272 
 273     return struct_type;
 274 }
 275 
 276 
 277 /*****************************************************************************/
 278 /* Copied Function to get test to work */
 279 /*****************************************************************************/
 280 static int32_t opal_datatype_create_indexed( int count, const int* pBlockLength, const int* pDisp,
 281                                              const opal_datatype_t* oldType, opal_datatype_t** newType )
 282 {
 283     opal_datatype_t* pdt;
 284     int i, dLength, endat, disp;
 285     ptrdiff_t extent;
 286 
 287     if( 0 == count ) {
 288         *newType = opal_datatype_create( 0 );
 289         opal_datatype_add( *newType, &opal_datatype_empty, 0, 0, 0);
 290         return OPAL_SUCCESS;
 291     }
 292 
 293     disp = pDisp[0];
 294     dLength = pBlockLength[0];
 295     endat = disp + dLength;
 296     opal_datatype_type_extent( oldType, &extent );
 297     if( 1 >= count ) {
 298         pdt = opal_datatype_create( oldType->desc.used + 2 );
 299         /* multiply by count to make it zero if count is zero */
 300         opal_datatype_add( pdt, oldType, count * dLength, disp * extent, extent );
 301     } else {
 302         pdt = opal_datatype_create( count * (2 + oldType->desc.used) );
 303         for( i = 1; i < count; i++ ) {
 304             if( endat == pDisp[i] ) {
 305                 /* contiguous with the previsious */
 306                 dLength += pBlockLength[i];
 307                 endat += pBlockLength[i];
 308             } else {
 309                 opal_datatype_add( pdt, oldType, dLength, disp * extent, extent );
 310                 disp = pDisp[i];
 311                 dLength = pBlockLength[i];
 312                 endat = disp + pBlockLength[i];
 313             }
 314         }
 315         opal_datatype_add( pdt, oldType, dLength, disp * extent, extent );
 316     }
 317 
 318     *newType = pdt;
 319     return OPAL_SUCCESS;
 320 }
 321 
 322 static int32_t opal_datatype_create_hindexed( int count, const int* pBlockLength, const ptrdiff_t* pDisp,
 323                                               const opal_datatype_t* oldType, opal_datatype_t** newType )
 324 {
 325     opal_datatype_t* pdt;
 326     int i, dLength;
 327     ptrdiff_t extent, disp, endat;
 328 
 329     if( 0 == count ) {
 330         *newType = opal_datatype_create( 0 );
 331         opal_datatype_add( *newType, &opal_datatype_empty, 0, 0, 0);
 332         return OPAL_SUCCESS;
 333     }
 334 
 335     opal_datatype_type_extent( oldType, &extent );
 336 
 337     pdt = opal_datatype_create( count * (2 + oldType->desc.used) );
 338     disp = pDisp[0];
 339     dLength = pBlockLength[0];
 340     endat = disp + dLength * extent;
 341     if( 1 >= count ) {
 342         pdt = opal_datatype_create( oldType->desc.used + 2 );
 343         /* multiply by count to make it zero if count is zero */
 344         opal_datatype_add( pdt, oldType, count * dLength, disp, extent );
 345     } else {
 346         for( i = 1; i < count; i++ ) {
 347             if( endat == pDisp[i] ) {
 348                 /* contiguous with the previsious */
 349                 dLength += pBlockLength[i];
 350                 endat += pBlockLength[i] * extent;
 351             } else {
 352                 opal_datatype_add( pdt, oldType, dLength, disp, extent );
 353                 disp = pDisp[i];
 354                 dLength = pBlockLength[i];
 355                 endat = disp + pBlockLength[i] * extent;
 356             }
 357         }
 358         opal_datatype_add( pdt, oldType, dLength, disp, extent );
 359     }
 360     *newType = pdt;
 361     return OPAL_SUCCESS;
 362 }
 363 
 364 
 365 static int32_t opal_datatype_create_struct( int count, const int* pBlockLength, const ptrdiff_t* pDisp,
 366                                             opal_datatype_t** pTypes, opal_datatype_t** newType )
 367 {
 368     int i;
 369     ptrdiff_t disp = 0, endto, lastExtent, lastDisp;
 370     int lastBlock;
 371     opal_datatype_t *pdt, *lastType;
 372 
 373     if( 0 == count ) {
 374         *newType = opal_datatype_create( 0 );
 375         opal_datatype_add( *newType, &opal_datatype_empty, 0, 0, 0);
 376         return OPAL_SUCCESS;
 377     }
 378 
 379     /* if we compute the total number of elements before we can
 380      * avoid increasing the size of the desc array often.
 381      */
 382     lastType = (opal_datatype_t*)pTypes[0];
 383     lastBlock = pBlockLength[0];
 384     lastExtent = lastType->ub - lastType->lb;
 385     lastDisp = pDisp[0];
 386     endto = pDisp[0] + lastExtent * lastBlock;
 387 
 388     for( i = 1; i < count; i++ ) {
 389         if( (pTypes[i] == lastType) && (pDisp[i] == endto) ) {
 390             lastBlock += pBlockLength[i];
 391             endto = lastDisp + lastBlock * lastExtent;
 392         } else {
 393             disp += lastType->desc.used;
 394             if( lastBlock > 1 ) disp += 2;
 395             lastType = (opal_datatype_t*)pTypes[i];
 396             lastExtent = lastType->ub - lastType->lb;
 397             lastBlock = pBlockLength[i];
 398             lastDisp = pDisp[i];
 399             endto = lastDisp + lastExtent * lastBlock;
 400         }
 401     }
 402     disp += lastType->desc.used;
 403     if( lastBlock != 1 ) disp += 2;
 404 
 405     lastType = (opal_datatype_t*)pTypes[0];
 406     lastBlock = pBlockLength[0];
 407     lastExtent = lastType->ub - lastType->lb;
 408     lastDisp = pDisp[0];
 409     endto = pDisp[0] + lastExtent * lastBlock;
 410 
 411     pdt = opal_datatype_create( (int32_t)disp );
 412 
 413     /* Do again the same loop but now add the elements */
 414     for( i = 1; i < count; i++ ) {
 415         if( (pTypes[i] == lastType) && (pDisp[i] == endto) ) {
 416             lastBlock += pBlockLength[i];
 417             endto = lastDisp + lastBlock * lastExtent;
 418         } else {
 419             opal_datatype_add( pdt, lastType, lastBlock, lastDisp, lastExtent );
 420             lastType = (opal_datatype_t*)pTypes[i];
 421             lastExtent = lastType->ub - lastType->lb;
 422             lastBlock = pBlockLength[i];
 423             lastDisp = pDisp[i];
 424             endto = lastDisp + lastExtent * lastBlock;
 425         }
 426     }
 427     opal_datatype_add( pdt, lastType, lastBlock, lastDisp, lastExtent );
 428 
 429      *newType = pdt;
 430     return OPAL_SUCCESS;
 431 }
 432 
 433 
 434 static int32_t opal_datatype_create_vector( int count, int bLength, int stride,
 435                                             const opal_datatype_t* oldType, opal_datatype_t** newType )
 436 {
 437     opal_datatype_t *pTempData, *pData;
 438     ptrdiff_t extent = oldType->ub - oldType->lb;
 439 
 440 
 441     if( 0 == count ) {
 442         *newType = opal_datatype_create( 0 );
 443         opal_datatype_add( *newType, &opal_datatype_empty, 0, 0, 0);
 444         return OPAL_SUCCESS;
 445     }
 446 
 447     pData = opal_datatype_create( oldType->desc.used + 2 );
 448     if( (bLength == stride) || (1 >= count) ) {  /* the elements are contiguous */
 449         opal_datatype_add( pData, oldType, count * bLength, 0, extent );
 450     } else {
 451         if( 1 == bLength ) {
 452             opal_datatype_add( pData, oldType, count, 0, extent * stride );
 453         } else {
 454             opal_datatype_add( pData, oldType, bLength, 0, extent );
 455             pTempData = pData;
 456             pData = opal_datatype_create( oldType->desc.used + 2 + 2 );
 457             opal_datatype_add( pData, pTempData, count, 0, extent * stride );
 458             OBJ_RELEASE( pTempData );
 459         }
 460     }
 461     *newType = pData;
 462     return OPAL_SUCCESS;
 463 }
 464 
 465 
 466 static int32_t opal_datatype_create_hvector( int count, int bLength, ptrdiff_t stride,
 467                                              const opal_datatype_t* oldType, opal_datatype_t** newType )
 468 {
 469     opal_datatype_t *pTempData, *pData;
 470     ptrdiff_t extent = oldType->ub - oldType->lb;
 471 
 472     if( 0 == count ) {
 473         *newType = opal_datatype_create( 0 );
 474         opal_datatype_add( *newType, &opal_datatype_empty, 0, 0, 0);
 475         return OPAL_SUCCESS;
 476     }
 477 
 478     pTempData = opal_datatype_create( oldType->desc.used + 2 );
 479     if( ((extent * bLength) == stride) || (1 >= count) ) {  /* contiguous */
 480         pData = pTempData;
 481         opal_datatype_add( pData, oldType, count * bLength, 0, extent );
 482     } else {
 483         if( 1 == bLength ) {
 484             pData = pTempData;
 485             opal_datatype_add( pData, oldType, count, 0, stride );
 486         } else {
 487             opal_datatype_add( pTempData, oldType, bLength, 0, extent );
 488             pData = opal_datatype_create( oldType->desc.used + 2 + 2 );
 489             opal_datatype_add( pData, pTempData, count, 0, stride );
 490             OBJ_RELEASE( pTempData );
 491         }
 492     }
 493     *newType = pData;
 494     return OPAL_SUCCESS;
 495 }
 496 
 497 /*****************************************************************************/
 498 int init_random_upper_matrix( unsigned int N, double* mat )
 499 {
 500     unsigned int i, j;
 501 
 502     srand( time(NULL) );
 503     for( i = 0; i < N; i++ ) {
 504         mat += i;
 505         for( j = i; j < N; j++ ) {
 506             *mat = (double)random();
 507             mat++;
 508         }
 509     }
 510     return OPAL_SUCCESS;
 511 }
 512 
 513 int check_diag_matrix( unsigned int N, double* mat1, double* mat2 )
 514 {
 515    unsigned int i, j;
 516 
 517    for( i = 0; i < N; i++ ) {
 518       mat1 += i;
 519       mat2 += i;
 520       for( j = i; j < N; j++ ) {
 521          if( *mat1 != *mat2 ) {
 522             printf( "error in position (%d, %d) expect %f and find %f\n",
 523                     i, j, *mat1, *mat2 );
 524             printf( "hex %lx != %lx\n", *(long*)mat1, *(long*)mat2 );
 525             return OPAL_ERROR;
 526          }
 527          mat1++; mat2++;
 528       }
 529    }
 530    return OPAL_SUCCESS;
 531 }
 532 
 533 
 534 opal_datatype_t* upper_matrix( unsigned int mat_size )
 535 {
 536     int *disp, *blocklen;
 537     unsigned int i;
 538     opal_datatype_t* upper;
 539 
 540     disp = (int*)malloc( sizeof(int) * mat_size );
 541     blocklen = (int*)malloc( sizeof(int) * mat_size );
 542 
 543     for( i = 0; i < mat_size; i++ ) {
 544         disp[i] = i * mat_size + i;
 545         blocklen[i] = mat_size - i;
 546     }
 547 
 548 #if SIZEOF_DOUBLE == 4
 549     opal_datatype_create_indexed( mat_size, blocklen, disp,
 550                                   &opal_datatype_float4,
 551                                   &upper );
 552 #else
 553     opal_datatype_create_indexed( mat_size, blocklen, disp,
 554                                   &opal_datatype_float8,
 555                                   &upper );
 556 #endif
 557     opal_datatype_commit( upper );
 558     if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
 559         opal_datatype_dump( upper );
 560     }
 561     free( disp );
 562     free( blocklen );
 563     return upper;
 564 }
 565 
 566 opal_datatype_t* lower_matrix( unsigned int mat_size )
 567 {
 568     int *disp, *blocklen;
 569     unsigned int i;
 570     opal_datatype_t* upper;
 571 
 572     disp = (int*)malloc( sizeof(int) * mat_size );
 573     blocklen = (int*)malloc( sizeof(int) * mat_size );
 574 
 575     for( i = 0; i < mat_size; i++ ) {
 576         disp[i] = i * mat_size;
 577         blocklen[i] = i;
 578     }
 579 #if SIZEOF_DOUBLE == 4
 580     opal_datatype_create_indexed( mat_size, blocklen, disp, &opal_datatype_float4,
 581                                   &upper );
 582 #else
 583     opal_datatype_create_indexed( mat_size, blocklen, disp, &opal_datatype_float8,
 584                                   &upper );
 585 #endif
 586     free( disp );
 587     free( blocklen );
 588     return upper;
 589 }
 590 
 591 opal_datatype_t* test_matrix_borders( unsigned int size, unsigned int width )
 592 {
 593    opal_datatype_t *pdt, *pdt_line;
 594    int disp[2];
 595    int blocklen[2];
 596 
 597    disp[0] = 0;
 598    blocklen[0] = width;
 599    disp[1] = (size - width) * sizeof(double);
 600    blocklen[1] = width;
 601 
 602    opal_datatype_create_indexed( 2, blocklen, disp, &opal_datatype_float8,
 603                                  &pdt_line );
 604    opal_datatype_create_contiguous( size, pdt_line, &pdt );
 605    OBJ_RELEASE( pdt_line ); /*assert( pdt_line == NULL );*/
 606    return pdt;
 607 }
 608 
 609 
 610 opal_datatype_t* test_contiguous( void )
 611 {
 612     opal_datatype_t *pdt, *pdt1, *pdt2;
 613 
 614     printf( "test contiguous (alignment)\n" );
 615     opal_datatype_create_contiguous(0, &opal_datatype_empty, &pdt1);
 616     opal_datatype_add( pdt1, &opal_datatype_float8, 1, 0, -1 );
 617     if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
 618         opal_datatype_dump( pdt1 );
 619     }
 620     opal_datatype_add( pdt1, &opal_datatype_int1, 1, 8, -1 );
 621     if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
 622         opal_datatype_dump( pdt1 );
 623     }
 624     opal_datatype_create_contiguous( 4, pdt1, &pdt2 );
 625     OBJ_RELEASE( pdt1 ); /*assert( pdt1 == NULL );*/
 626     if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
 627         opal_datatype_dump( pdt2 );
 628     }
 629     opal_datatype_create_contiguous( 2, pdt2, &pdt );
 630     OBJ_RELEASE( pdt2 ); /*assert( pdt2 == NULL );*/
 631     if( outputFlags & DUMP_DATA_AFTER_COMMIT ) {
 632         opal_datatype_dump( pdt );
 633     }
 634     return pdt;
 635 }
 636 
 637 

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