root/ompi/mca/io/romio321/romio/adio/common/ad_subarray.c

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

DEFINITIONS

This source file includes following definitions.
  1. ADIO_Type_create_subarray

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
   2 /* 
   3  *
   4  *   Copyright (C) 1997 University of Chicago. 
   5  *   See COPYRIGHT notice in top-level directory.
   6  */
   7 
   8 #include "adio.h"
   9 #include "adio_extern.h"
  10 
  11 int ADIO_Type_create_subarray(int ndims,
  12                               int *array_of_sizes, 
  13                               int *array_of_subsizes,
  14                               int *array_of_starts,
  15                               int order,
  16                               MPI_Datatype oldtype, 
  17                               MPI_Datatype *newtype)
  18 {
  19     MPI_Aint extent, disp, size, lb, ub;
  20     int i, blklen;
  21     MPI_Datatype tmp1, tmp2, inttype;
  22 
  23     MPI_Type_get_extent(oldtype, &lb, &extent);
  24 
  25     if (order == MPI_ORDER_FORTRAN) {
  26         /* dimension 0 changes fastest */
  27         if (ndims == 1) {
  28             MPI_Type_contiguous(array_of_subsizes[0], oldtype, &tmp1);
  29         }
  30         else {
  31             MPI_Type_vector(array_of_subsizes[1],
  32                             array_of_subsizes[0],
  33                             array_of_sizes[0], oldtype, &tmp1);
  34             
  35             size = (MPI_Aint)array_of_sizes[0]*extent;
  36             for (i=2; i<ndims; i++) {
  37                 size *= (MPI_Aint)array_of_sizes[i-1];
  38                 MPI_Type_create_hvector(array_of_subsizes[i], 1, size, tmp1, &tmp2);
  39                 MPI_Type_free(&tmp1);
  40                 tmp1 = tmp2;
  41             }
  42         }
  43         
  44         /* add displacement and UB */
  45         disp = array_of_starts[0];
  46         size = 1;
  47         for (i=1; i<ndims; i++) {
  48             size *= (MPI_Aint)array_of_sizes[i-1];
  49             disp += size*(MPI_Aint)array_of_starts[i];
  50         }  
  51         /* rest done below for both Fortran and C order */
  52     }
  53 
  54     else /* order == MPI_ORDER_C */ {
  55         /* dimension ndims-1 changes fastest */
  56         if (ndims == 1) {
  57             MPI_Type_contiguous(array_of_subsizes[0], oldtype, &tmp1);
  58         }
  59         else {
  60             MPI_Type_vector(array_of_subsizes[ndims-2],
  61                             array_of_subsizes[ndims-1],
  62                             array_of_sizes[ndims-1], oldtype, &tmp1);
  63             
  64             size = (MPI_Aint)array_of_sizes[ndims-1]*extent;
  65             for (i=ndims-3; i>=0; i--) {
  66                 size *= (MPI_Aint)array_of_sizes[i+1];
  67                 MPI_Type_create_hvector(array_of_subsizes[i], 1, size, tmp1, &tmp2);
  68                 MPI_Type_free(&tmp1);
  69                 tmp1 = tmp2;
  70             }
  71         }
  72         
  73         /* add displacement and UB */
  74         disp = array_of_starts[ndims-1];
  75         size = 1;
  76         for (i=ndims-2; i>=0; i--) {
  77             size *= (MPI_Aint)array_of_sizes[i+1];
  78             disp += size*(MPI_Aint)array_of_starts[i];
  79         }
  80     }
  81     
  82     disp *= extent;
  83     
  84     ub = extent;
  85     for (i=0; i<ndims; i++) ub *= (MPI_Aint)array_of_sizes[i];
  86     
  87     blklen = 1;
  88  
  89     MPI_Type_create_struct(1, &blklen, &disp, &tmp1, &inttype);
  90     MPI_Type_create_resized (inttype, 0, ub, newtype);
  91     MPI_Type_free(&inttype);
  92 
  93     MPI_Type_free(&tmp1);
  94 
  95     return MPI_SUCCESS;
  96 }

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