Ejemplo n.º 1
0
void seissol::checkpoint::h5::Fault::write(int timestepFault)
{
	EPIK_TRACER("CheckPointFault_write");
	SCOREP_USER_REGION("CheckPointFault_write", SCOREP_USER_REGION_TYPE_FUNCTION);

	if (numSides() == 0)
		return;

	logInfo(rank()) << "Writing fault check point.";

	// Create array with all pointers
	EPIK_USER_REG(r_write_fault, "checkpoint_write_fault");
	SCOREP_USER_REGION_DEFINE(r_write_fault);
	EPIK_USER_START(r_write_fault);
	SCOREP_USER_REGION_BEGIN(r_write_fault, "checkpoint_write_fault", SCOREP_USER_REGION_TYPE_COMMON);

	// Attributes
	checkH5Err(H5Awrite(m_h5timestepFault[odd()], H5T_NATIVE_INT, &timestepFault));

	// Set memory and file space
	hsize_t fStart[2] = {fileOffset(), 0};
	hsize_t count[2] = {numSides(), numBndGP()};
	hid_t h5memSpace = H5Screate_simple(2, count, 0L);
	checkH5Err(h5memSpace);
	checkH5Err(H5Sselect_all(h5memSpace));
	checkH5Err(H5Sselect_hyperslab(m_h5fSpaceData, H5S_SELECT_SET, fStart, 0L, count, 0L));

	for (unsigned int i = 0; i < NUM_VARIABLES; i++) {
		checkH5Err(H5Dwrite(m_h5data[odd()][i], H5T_NATIVE_DOUBLE, h5memSpace, m_h5fSpaceData,
				h5XferList(), data(i)));
	}

	checkH5Err(H5Sclose(h5memSpace));

	EPIK_USER_END(r_write_fault);
	SCOREP_USER_REGION_END(r_write_fault);

	// Finalize the checkpoint
	finalizeCheckpoint();

	logInfo(rank()) << "Writing fault check point. Done.";
}
Ejemplo n.º 2
0
void seissol::checkpoint::h5::Wavefield::write(double time, int waveFieldTimeStep)
{
	EPIK_TRACER("CheckPoint_write");
	SCOREP_USER_REGION("CheckPoint_write", SCOREP_USER_REGION_TYPE_FUNCTION);

	logInfo(rank()) << "Writing check point.";

	EPIK_USER_REG(r_header, "checkpoint_write_header");
	SCOREP_USER_REGION_DEFINE(r_header);
	EPIK_USER_START(r_header);
	SCOREP_USER_REGION_BEGIN(r_header, "checkpoint_write_header", SCOREP_USER_REGION_TYPE_COMMON);

	// Time
	checkH5Err(H5Awrite(m_h5time[odd()], H5T_NATIVE_DOUBLE, &time));

	// Wavefield writer
	checkH5Err(H5Awrite(m_h5timestepWavefield[odd()], H5T_NATIVE_INT, &waveFieldTimeStep));

	EPIK_USER_END(r_header);
	SCOREP_USER_REGION_END(r_header);

	// Save data
	EPIK_USER_REG(r_write_wavefield, "checkpoint_write_wavefield");
	SCOREP_USER_REGION_DEFINE(r_write_wavefield);
	EPIK_USER_START(r_write_wavefield);
	SCOREP_USER_REGION_BEGIN(r_write_wavefield, "checkpoint_write_wavefield", SCOREP_USER_REGION_TYPE_COMMON);

	// Write the wave field
	unsigned int offset = 0;
	hsize_t fStart = fileOffset();
	hsize_t count = dofsPerIteration();
	hid_t h5memSpace = H5Screate_simple(1, &count, 0L);
	checkH5Err(h5memSpace);
	checkH5Err(H5Sselect_all(h5memSpace));
	for (unsigned int i = 0; i < totalIterations()-1; i++) {
		checkH5Err(H5Sselect_hyperslab(m_h5fSpaceData, H5S_SELECT_SET, &fStart, 0L, &count, 0L));

		checkH5Err(H5Dwrite(m_h5data[odd()], H5T_NATIVE_DOUBLE, h5memSpace, m_h5fSpaceData,
				h5XferList(), &const_cast<real*>(dofs())[offset]));

		// We are finished in less iterations, read data twice
		// so everybody needs the same number of iterations
		if (i < iterations()-1) {
			fStart += count;
			offset += count;
		}
	}
	checkH5Err(H5Sclose(h5memSpace));

	// Save reminding data in the last iteration
	count = numDofs() - (iterations() - 1) * count;
	h5memSpace = H5Screate_simple(1, &count, 0L);
	checkH5Err(h5memSpace);
	checkH5Err(H5Sselect_all(h5memSpace));
	checkH5Err(H5Sselect_hyperslab(m_h5fSpaceData, H5S_SELECT_SET, &fStart, 0L, &count, 0L));
	checkH5Err(H5Dwrite(m_h5data[odd()], H5T_NATIVE_DOUBLE, h5memSpace, m_h5fSpaceData,
			h5XferList(), &dofs()[offset]));
	checkH5Err(H5Sclose(h5memSpace));

	EPIK_USER_END(r_write_wavefield);
	SCOREP_USER_REGION_END(r_write_wavefield);

	// Finalize the checkpoint
	finalizeCheckpoint();

	logInfo(rank()) << "Writing check point. Done.";
}
Ejemplo n.º 3
0
void seissol::checkpoint::h5::Wavefield::load(double &time, int &timestepWavefield, real* dofs)
{
	logInfo(rank()) << "Loading wave field checkpoint";

	seissol::checkpoint::CheckPoint::setLoaded();

	hid_t h5file = open(linkFile());
	checkH5Err(h5file);

	// Attributes
	hid_t h5attr = H5Aopen(h5file, "time", H5P_DEFAULT);
	checkH5Err(h5attr);
	checkH5Err(H5Aread(h5attr, H5T_NATIVE_DOUBLE, &time));
	checkH5Err(H5Aclose(h5attr));

	h5attr = H5Aopen(h5file, "timestep_wavefield", H5P_DEFAULT);
	checkH5Err(h5attr);
	checkH5Err(H5Aread(h5attr, H5T_NATIVE_INT, &timestepWavefield));
	checkH5Err(H5Aclose(h5attr));

	// Get dataset
	hid_t h5data = H5Dopen(h5file, "values", H5P_DEFAULT);
	checkH5Err(h5data);
	hid_t h5fSpace = H5Dget_space(h5data);
	checkH5Err(h5fSpace);

	// Read the data
	unsigned int offset = 0;
	hsize_t fStart = fileOffset();
	hsize_t count = dofsPerIteration();
	hid_t h5memSpace = H5Screate_simple(1, &count, 0L);
	checkH5Err(h5memSpace);
	checkH5Err(H5Sselect_all(h5memSpace));
	for (unsigned int i = 0; i < totalIterations()-1; i++) {
		checkH5Err(H5Sselect_hyperslab(h5fSpace, H5S_SELECT_SET, &fStart, 0L, &count, 0L));

		checkH5Err(H5Dread(h5data, H5T_NATIVE_DOUBLE, h5memSpace, h5fSpace,
				h5XferList(), &dofs[offset]));

		// We are finished in less iterations, read data twice
		// so everybody needs the same number of iterations
		if (i < iterations()-1) {
			fStart += count;
			offset += count;
		}
	}
	checkH5Err(H5Sclose(h5memSpace));

	// Read reminding data in the last iteration
	count = numDofs() - (iterations() - 1) * count;
	h5memSpace = H5Screate_simple(1, &count, 0L);
	checkH5Err(h5memSpace);
	checkH5Err(H5Sselect_all(h5memSpace));
	checkH5Err(H5Sselect_hyperslab(h5fSpace, H5S_SELECT_SET, &fStart, 0L, &count, 0L));
	checkH5Err(H5Dread(h5data, H5T_NATIVE_DOUBLE, h5memSpace, h5fSpace,
			h5XferList(), &dofs[offset]));
	checkH5Err(H5Sclose(h5memSpace));

	checkH5Err(H5Sclose(h5fSpace));
	checkH5Err(H5Dclose(h5data));
	checkH5Err(H5Fclose(h5file));
}
Ejemplo n.º 4
0
void SelectionVisitor::apply( const xdm::AllDataSelection& selection ) {
  H5Sselect_all( mIdent );
}
Ejemplo n.º 5
0
/*-------------------------------------------------------------------------
* Function: diff_datasetid
*
* Purpose: check for comparable datasets and read into a compatible
*  memory type
*
* Return: Number of differences found
*
* Programmer: Pedro Vicente, [email protected]
*
* Date: May 9, 2003
*
* Modifications:
*
*
* October 2006:  Read by hyperslabs for big datasets.
*
*  A threshold of H5TOOLS_MALLOCSIZE (128 MB) is the limit upon which I/O hyperslab is done
*  i.e., if the memory needed to read a dataset is greater than this limit,
*  then hyperslab I/O is done instead of one operation I/O
*  For each dataset, the memory needed is calculated according to
*
*  memory needed = number of elements * size of each element
*
*  if the memory needed is lower than H5TOOLS_MALLOCSIZE, then the following operations
*  are done
*
*  H5Dread( input_dataset1 )
*  H5Dread( input_dataset2 )
*
*  with all elements in the datasets selected. If the memory needed is greater than
*  H5TOOLS_MALLOCSIZE, then the following operations are done instead:
*
*  a strip mine is defined for each dimension k (a strip mine is defined as a
*  hyperslab whose size is memory manageable) according to the formula
*
*  (1) strip_mine_size[k ] = MIN(dimension[k ], H5TOOLS_BUFSIZE / size of memory type)
*
*  where H5TOOLS_BUFSIZE is a constant currently defined as 1MB. This formula assures
*  that for small datasets (small relative to the H5TOOLS_BUFSIZE constant), the strip
*  mine size k is simply defined as its dimension k, but for larger datasets the
*  hyperslab size is still memory manageable.
*  a cycle is done until the number of elements in the dataset is reached. In each
*  iteration, two parameters are defined for the function H5Sselect_hyperslab,
*  the start and size of each hyperslab, according to
*
*  (2) hyperslab_size [k] = MIN(dimension[k] - hyperslab_offset[k], strip_mine_size [k])
*
*  where hyperslab_offset [k] is initially set to zero, and later incremented in
*  hyperslab_size[k] offsets. The reason for the operation
*
*  dimension[k] - hyperslab_offset[k]
*
*  in (2) is that, when using the strip mine size, it assures that the "remaining" part
*  of the dataset that does not fill an entire strip mine is processed.
*
*-------------------------------------------------------------------------
*/
hsize_t diff_datasetid( hid_t did1,
                        hid_t did2,
                        const char *obj1_name,
                        const char *obj2_name,
                        diff_opt_t *options)
{
    hid_t      sid1=-1;
    hid_t      sid2=-1;
    hid_t      f_tid1=-1;
    hid_t      f_tid2=-1;
    hid_t      m_tid1=-1;
    hid_t      m_tid2=-1;
    size_t     m_size1;
    size_t     m_size2;
    H5T_sign_t sign1;
    H5T_sign_t sign2;
    int        rank1;
    int        rank2;
    hsize_t    nelmts1;
    hsize_t    nelmts2;
    hsize_t    dims1[H5S_MAX_RANK];
    hsize_t    dims2[H5S_MAX_RANK];
    hsize_t    maxdim1[H5S_MAX_RANK];
    hsize_t    maxdim2[H5S_MAX_RANK];
    const char *name1=NULL;            /* relative names */
    const char *name2=NULL;
    hsize_t    storage_size1;
    hsize_t    storage_size2;
    hsize_t    nfound=0;               /* number of differences found */
    int        can_compare=1;          /* do diff or not */
    void       *buf1=NULL;
    void       *buf2=NULL;
    void       *sm_buf1=NULL;
    void       *sm_buf2=NULL;
    size_t     need;                   /* bytes needed for malloc */
    int        i;
    
    /* Get the dataspace handle */
    if ( (sid1 = H5Dget_space(did1)) < 0 )
        goto error;
    
    /* Get rank */
    if ( (rank1 = H5Sget_simple_extent_ndims(sid1)) < 0 )
        goto error;
    
    /* Get the dataspace handle */
    if ( (sid2 = H5Dget_space(did2)) < 0 )
        goto error;
    
    /* Get rank */
    if ( (rank2 = H5Sget_simple_extent_ndims(sid2)) < 0 )
        goto error;
    
    /* Get dimensions */
    if ( H5Sget_simple_extent_dims(sid1,dims1,maxdim1) < 0 )
        goto error;
    
    /* Get dimensions */
    if ( H5Sget_simple_extent_dims(sid2,dims2,maxdim2) < 0 )
    {
        goto error;
    }
    
    /*-------------------------------------------------------------------------
    * get the file data type
    *-------------------------------------------------------------------------
    */
    
    /* Get the data type */
    if ( (f_tid1 = H5Dget_type(did1)) < 0 )
        goto error;
    
    /* Get the data type */
    if ( (f_tid2 = H5Dget_type(did2)) < 0 )
    {
        goto error;
    }
    
    /*-------------------------------------------------------------------------
    * check for empty datasets
    *-------------------------------------------------------------------------
    */
    
    storage_size1=H5Dget_storage_size(did1);
    storage_size2=H5Dget_storage_size(did2);
    
    if (storage_size1==0 || storage_size2==0)
    {
        if ( (options->m_verbose||options->m_list_not_cmp) && obj1_name && obj2_name)
            parallel_print("Not comparable: <%s> or <%s> is an empty dataset\n", obj1_name, obj2_name);
        can_compare=0;
        options->not_cmp=1;
    }
    
    /*-------------------------------------------------------------------------
    * check for comparable TYPE and SPACE
    *-------------------------------------------------------------------------
    */
    
    if (diff_can_type(f_tid1,
        f_tid2,
        rank1,
        rank2,
        dims1,
        dims2,
        maxdim1,
        maxdim2,
        obj1_name,
        obj2_name,
        options,
        0)!=1)
    {
        can_compare=0;
    }
    
    /*-------------------------------------------------------------------------
    * memory type and sizes
    *-------------------------------------------------------------------------
    */
    if ((m_tid1=h5tools_get_native_type(f_tid1)) < 0)
        goto error;
    
    if ((m_tid2=h5tools_get_native_type(f_tid2)) < 0)
        goto error;
    
    m_size1 = H5Tget_size( m_tid1 );
    m_size2 = H5Tget_size( m_tid2 );
    
    /*-------------------------------------------------------------------------
    * check for different signed/unsigned types
    *-------------------------------------------------------------------------
    */
    
    sign1=H5Tget_sign(m_tid1);
    sign2=H5Tget_sign(m_tid2);
    if ( sign1 != sign2 )
    {
        if ((options->m_verbose||options->m_list_not_cmp) && obj1_name && obj2_name) 
        {
            parallel_print("Not comparable: <%s> has sign %s ", obj1_name, get_sign(sign1));
            parallel_print("and <%s> has sign %s\n", obj2_name, get_sign(sign2));
        }
        
        can_compare=0;
        options->not_cmp=1;
    }
    
    /*-------------------------------------------------------------------------
    * only attempt to compare if possible
    *-------------------------------------------------------------------------
    */
    if (can_compare ) /* it is possible to compare */
    {
        
        /*-------------------------------------------------------------------------
        * get number of elements
        *-------------------------------------------------------------------------
        */
        nelmts1 = 1;
        for (i = 0; i < rank1; i++)
        {
            nelmts1 *= dims1[i];
        }
        
        nelmts2 = 1;
        for (i = 0; i < rank2; i++)
        {
            nelmts2 *= dims2[i];
        }
        
        assert(nelmts1==nelmts2);
        
        /*-------------------------------------------------------------------------
        * "upgrade" the smaller memory size
        *-------------------------------------------------------------------------
        */
        
        if ( m_size1 != m_size2 )
        {
            if ( m_size1 < m_size2 )
            {
                H5Tclose(m_tid1);
                
                if ((m_tid1=h5tools_get_native_type(f_tid2)) < 0)
                    goto error;
                
                m_size1 = H5Tget_size( m_tid1 );
            }
            else
            {
                H5Tclose(m_tid2);
                
                if ((m_tid2=h5tools_get_native_type(f_tid1)) < 0)
                    goto error;
                
                m_size2 = H5Tget_size( m_tid2 );
            }
        }
        assert(m_size1==m_size2);
        
        /* print names */
        if (obj1_name) {
            name1=diff_basename(obj1_name);
        }
        if (obj2_name) {
            name2=diff_basename(obj2_name);
        }
        
        
        /*-------------------------------------------------------------------------
        * read/compare
        *-------------------------------------------------------------------------
        */
        
        need = (size_t)(nelmts1*m_size1);  /* bytes needed */
        if ( need < H5TOOLS_MALLOCSIZE)
        {
            buf1 = HDmalloc(need);
            buf2 = HDmalloc(need);
        }
        
        if ( buf1!=NULL && buf2!=NULL)
        {
            if ( H5Dread(did1,m_tid1,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf1) < 0 )
                goto error;
            if ( H5Dread(did2,m_tid2,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf2) < 0 )
                goto error;
            
            /* array diff */
            nfound = diff_array(buf1,
                buf2,
                nelmts1,
                (hsize_t)0,
                rank1,
                dims1,
                options,
                name1,
                name2,
                m_tid1,
                did1,
                did2);
        }
        
        else /* possibly not enough memory, read/compare by hyperslabs */
            
        {
            size_t        p_type_nbytes = m_size1; /*size of memory type */
            hsize_t       p_nelmts = nelmts1;      /*total selected elmts */
            hsize_t       elmtno;                  /*counter  */
            int           carry;                   /*counter carry value */
            unsigned int  vl_data = 0;             /*contains VL datatypes */
            
            /* stripmine info */
            hsize_t       sm_size[H5S_MAX_RANK];   /*stripmine size */
            hsize_t       sm_nbytes;               /*bytes per stripmine */
            hsize_t       sm_nelmts;               /*elements per stripmine*/
            hid_t         sm_space;                /*stripmine data space */
            
            /* hyperslab info */
            hsize_t       hs_offset[H5S_MAX_RANK]; /*starting offset */
            hsize_t       hs_size[H5S_MAX_RANK];   /*size this pass */
            hsize_t       hs_nelmts;               /*elements in request */
            hsize_t       zero[8];                 /*vector of zeros */
            
            /* check if we have VL data in the dataset's datatype */
            if (H5Tdetect_class(m_tid1, H5T_VLEN) == TRUE)
                vl_data = TRUE;
            
                /*
                * determine the strip mine size and allocate a buffer. The strip mine is
                * a hyperslab whose size is manageable.
            */
            sm_nbytes = p_type_nbytes;
            
            for (i = rank1; i > 0; --i) 
            {
                hsize_t size = H5TOOLS_BUFSIZE / sm_nbytes;
                if ( size == 0) /* datum size > H5TOOLS_BUFSIZE */
                    size = 1;
                sm_size[i - 1] = MIN(dims1[i - 1], size);
                sm_nbytes *= sm_size[i - 1];
                assert(sm_nbytes > 0);
            }
            
            sm_buf1 = malloc((size_t)sm_nbytes);
            sm_buf2 = malloc((size_t)sm_nbytes);
            
            sm_nelmts = sm_nbytes / p_type_nbytes;
            sm_space = H5Screate_simple(1, &sm_nelmts, NULL);
            
            /* the stripmine loop */
            memset(hs_offset, 0, sizeof hs_offset);
            memset(zero, 0, sizeof zero);
            
            for (elmtno = 0; elmtno < p_nelmts; elmtno += hs_nelmts)
            {
                /* calculate the hyperslab size */
                if (rank1 > 0)
                {
                    for (i = 0, hs_nelmts = 1; i < rank1; i++)
                    {
                        hs_size[i] = MIN(dims1[i] - hs_offset[i], sm_size[i]);
                        hs_nelmts *= hs_size[i];
                    }
                    if (H5Sselect_hyperslab(sid1, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL) < 0)
                        goto error;
                    if (H5Sselect_hyperslab(sid2, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL) < 0)
                        goto error;
                    if (H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, zero, NULL, &hs_nelmts, NULL) < 0)
                        goto error;
                }
                else
                {
                    H5Sselect_all(sid1);
                    H5Sselect_all(sid2);
                    H5Sselect_all(sm_space);
                    hs_nelmts = 1;
                } /* rank */
                
                if ( H5Dread(did1,m_tid1,sm_space,sid1,H5P_DEFAULT,sm_buf1) < 0 )
                    goto error;
                if ( H5Dread(did2,m_tid2,sm_space,sid2,H5P_DEFAULT,sm_buf2) < 0 )
                    goto error;
                
                /* get array differences. in the case of hyperslab read, increment the number of differences
                found in each hyperslab and pass the position at the beggining for printing */
                nfound += diff_array(sm_buf1,
                    sm_buf2,
                    hs_nelmts,
                    elmtno,
                    rank1,
                    dims1,
                    options,
                    name1,
                    name2,
                    m_tid1,
                    did1,
                    did2);
                
                /* reclaim any VL memory, if necessary */
                if(vl_data)
                {
                    H5Dvlen_reclaim(m_tid1, sm_space, H5P_DEFAULT, sm_buf1);
                    H5Dvlen_reclaim(m_tid1, sm_space, H5P_DEFAULT, sm_buf2);
                }
                
                /* calculate the next hyperslab offset */
                for (i = rank1, carry = 1; i > 0 && carry; --i)
                {
                    hs_offset[i - 1] += hs_size[i - 1];
                    if (hs_offset[i - 1] == dims1[i - 1])
                        hs_offset[i - 1] = 0;
                    else
                        carry = 0;
                } /* i */
            } /* elmtno */
            
            H5Sclose(sm_space);
            /* free */
            if (sm_buf1!=NULL)
            {
                free(sm_buf1);
                sm_buf1=NULL;
            }
            if (sm_buf2!=NULL)
            {
                free(sm_buf2);
                sm_buf2=NULL;
            }
            
 } /* hyperslab read */
 }/*can_compare*/
 
  /*-------------------------------------------------------------------------
  * compare attributes
  * the if condition refers to cases when the dataset is a referenced object
  *-------------------------------------------------------------------------
  */
  
  if (obj1_name)
  {
      nfound += diff_attr(did1,did2,obj1_name,obj2_name,options);
  }
  
  /*-------------------------------------------------------------------------
  * close
  *-------------------------------------------------------------------------
  */
  
  /* free */
  if (buf1!=NULL)
  {
      free(buf1);
      buf1=NULL;
  }
  if (buf2!=NULL)
  {
      free(buf2);
      buf2=NULL;
  }
  if (sm_buf1!=NULL)
  {
      free(sm_buf1);
      sm_buf1=NULL;
  }
  if (sm_buf2!=NULL)
  {
      free(sm_buf2);
      sm_buf2=NULL;
  }
  
  H5E_BEGIN_TRY {
      H5Sclose(sid1);
      H5Sclose(sid2);
      H5Tclose(f_tid1);
      H5Tclose(f_tid2);
      H5Tclose(m_tid1);
      H5Tclose(m_tid2);
  } H5E_END_TRY;
  
  return nfound;
  
error:
  options->err_stat=1;
  
  /* free */
  if (buf1!=NULL)
  {
      free(buf1);
      buf1=NULL;
  }
  if (buf2!=NULL)
  {
      free(buf2);
      buf2=NULL;
  }
  if (sm_buf1!=NULL)
  {
      free(sm_buf1);
      sm_buf1=NULL;
  }
  if (sm_buf2!=NULL)
  {
      free(sm_buf2);
      sm_buf2=NULL;
  }
  
  /* disable error reporting */
  H5E_BEGIN_TRY {
      H5Sclose(sid1);
      H5Sclose(sid2);
      H5Tclose(f_tid1);
      H5Tclose(f_tid2);
      H5Tclose(m_tid1);
      H5Tclose(m_tid2);
      /* enable error reporting */
  } H5E_END_TRY;
  
  return nfound;
}
Ejemplo n.º 6
0
/***********************************************************
**
** test_singleEnd_selElements(): Test element selection of only
** one block.
**
*************************************************************/
static void test_singleEnd_selElements(hid_t file, hbool_t is_chunked)
{
    hid_t sid, plid, did, msid;
    char dset_name[NAME_LEN];        /* Dataset name */
    size_t elmts_numb;
    herr_t ret;                 /* Generic error return */
    int i, j, k;
    hsize_t da_dims[4] = { 2, 3, 6, 2 };
    hsize_t da_chunksize[4] = { 1, 3, 3, 2 };

    /* For testing the full selection in the fastest-growing end */
    int mem1_buffer[1][1][6][2];
    hsize_t mem1_dims[4] = { 1, 1, 6, 2 };
    hsize_t da_elmts1[12][4] = { {0, 0, 0, 0},
                                 {0, 0, 0, 1},
                                 {0, 0, 1, 0},
                                 {0, 0, 1, 1},
                                 {0, 0, 2, 0},
                                 {0, 0, 2, 1},
                                 {0, 0, 3, 0},
                                 {0, 0, 3, 1},
                                 {0, 0, 4, 0},
                                 {0, 0, 4, 1},
                                 {0, 0, 5, 0},
                                 {0, 0, 5, 1} };

    /* For testing the full selection in the slowest-growing end */
    int mem2_buffer[2][3][1][1];
    hsize_t mem2_dims[4] = { 2, 3, 1, 1 };
    hsize_t da_elmts2[6][4] = { {0, 0, 0, 0},
                                {0, 1, 0, 0},
                                {0, 2, 0, 0},
                                {1, 0, 0, 0},
                                {1, 1, 0, 0},
                                {1, 2, 0, 0} };

    /* For testing the full selection in the middle dimensions */
    int mem3_buffer[1][3][6][1];
    hsize_t mem3_dims[4] = { 1, 3, 6, 1 };
    hsize_t da_elmts3[18][4] = { {0, 0, 0, 0},
                                 {0, 0, 1, 0},
                                 {0, 0, 2, 0},
                                 {0, 0, 3, 0},
                                 {0, 0, 4, 0},
                                 {0, 0, 5, 0},
                                 {0, 1, 0, 0},
                                 {0, 1, 1, 0},
                                 {0, 1, 2, 0},
                                 {0, 1, 3, 0},
                                 {0, 1, 4, 0},
                                 {0, 1, 5, 0},
                                 {0, 2, 0, 0},
                                 {0, 2, 1, 0},
                                 {0, 2, 2, 0},
                                 {0, 2, 3, 0},
                                 {0, 2, 4, 0},
                                 {0, 2, 5, 0} };

    /* Create and write the dataset */
    sid = H5Screate_simple(4, da_dims, da_dims);
    CHECK(sid, FAIL, "H5Screate_simple");

    plid = H5Pcreate(H5P_DATASET_CREATE);
    CHECK(plid, FAIL, "H5Pcreate");

    if(is_chunked) {
        ret = H5Pset_chunk(plid, 4, da_chunksize);
        CHECK(ret, FAIL, "H5Pset_chunk");
    }

    /* Construct dataset's name */
    memset(dset_name, 0, (size_t)NAME_LEN);
    strcat(dset_name, SINGLE_END_DSET);
    if(is_chunked)
        strcat(dset_name, "_chunked");

    did = H5Dcreate2(file, dset_name, H5T_NATIVE_INT, sid, H5P_DEFAULT, plid, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dcreate2");

    /* Initialize the data to be written to file */
    for(i=0; i<2; i++) {
        for(j=0; j<3; j++) {
            for(k=0; k<6; k++) {
                da_buffer[i][j][k][0] = i*100 + j*10 + k;
                da_buffer[i][j][k][1] = i*100 + j*10 + k + 1;
            }
        }
    }

    ret = H5Dwrite(did, H5T_NATIVE_INT, sid, sid, H5P_DEFAULT, da_buffer);
    CHECK(ret, FAIL, "H5Dwrite");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");


    /* ****** Case 1: ******
     * Testing the full selection in the fastest-growing end */
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen");

    /* Select the elements in the dataset */
    elmts_numb = 12;

    ret = H5Sselect_elements(sid, H5S_SELECT_SET, elmts_numb, (const hsize_t *)da_elmts1);
    CHECK(ret, FAIL, "H5Sselect_elements");

    /* Dataspace for memory buffer */
    msid = H5Screate_simple(4, mem1_dims, mem1_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem1_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<6; i++)
        for(j=0; j<2; j++)
            if(da_buffer[0][0][i][j] != mem1_buffer[0][0][i][j]) {
                TestErrPrintf("%u: Read different values than written at index 0,0,%d,%d\n", __LINE__, i, j);
            }

    /* ****** Case 2: ******
     * Testing the full selection in the slowest-growing end */
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen");

    /* Select the elements in the dataset */
    elmts_numb = 6;

    ret = H5Sselect_elements(sid, H5S_SELECT_SET, elmts_numb, (const hsize_t *)da_elmts2);
    CHECK(ret, FAIL, "H5Sselect_elements");

    /* Dataspace for memory buffer */
    msid = H5Screate_simple(4, mem2_dims, mem2_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem2_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<2; i++)
        for(j=0; j<3; j++)
            if(da_buffer[i][j][0][0] != mem2_buffer[i][j][0][0]) {
                TestErrPrintf("%u: Read different values than written at index %d,%d,0,0, da_buffer = %d, mem2_buffer = %d\n", __LINE__, i, j, da_buffer[i][j][0][0], mem2_buffer[i][j][0][0]);
            }

    /* ****** Case 3: ******
     * Testing the full selection in the middle dimensions */
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen");

    /* Select the elements in the dataset */
    elmts_numb = 18;

    ret = H5Sselect_elements(sid, H5S_SELECT_SET, elmts_numb, (const hsize_t *)da_elmts3);
    CHECK(ret, FAIL, "H5Sselect_elements");

    /* Dataspace for memory buffer */
    msid = H5Screate_simple(4, mem3_dims, mem3_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem3_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<3; i++)
        for(j=0; j<6; j++)
            if(da_buffer[0][i][j][0] != mem3_buffer[0][i][j][0]) {
                TestErrPrintf("%u: Read different values than written at index 0,%d,%d,0\n", __LINE__, i, j);
            }


    ret = H5Sclose(sid);
    CHECK(ret, FAIL, "H5Sclose");

    ret = H5Pclose(plid);
    CHECK(ret, FAIL, "H5Pclose");
}
Ejemplo n.º 7
0
/***********************************************************
**
** test_multiple_end(): Test full hyperslab selection of
** multiple blocks.
**
*************************************************************/
static void test_multiple_ends(hid_t file, hbool_t is_chunked)
{
    hid_t sid, plid, did, msid;
    char dset_name[NAME_LEN];        /* Dataset name */
    herr_t ret;                 /* Generic error return */
    int i, j, k, l, m, n, p;
    hsize_t da_dims[8] = { 4, 5, 3, 4, 2, 3, 6, 2 };
    hsize_t da_chunksize[8] = { 1, 5, 3, 2, 2, 3, 3, 2 };
    int data_buf[4][5][3][4][2][3][6][2];

    /* For testing the full selections in the fastest-growing end and in the middle dimensions */
    int mem1_buffer[1][1][1][4][2][1][6][2];
    hsize_t mem1_dims[8] = { 1, 1, 1, 4, 2, 1, 6, 2 };
    hsize_t mem1_start[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
    hsize_t mem1_count[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
    hsize_t mem1_stride[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
    hsize_t mem1_block[8] = { 1, 1, 1, 4, 2, 1, 6, 2 };

    /* For testing the full selections in the slowest-growing end and in the middle dimensions */
    int mem2_buffer[4][5][1][4][2][1][1][1];
    hsize_t mem2_dims[8] = { 4, 5, 1, 4, 2, 1, 1, 1 };
    hsize_t mem2_start[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
    hsize_t mem2_count[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
    hsize_t mem2_stride[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
    hsize_t mem2_block[8] = { 4, 5, 1, 4, 2, 1, 1, 1 };

    /* For testing two unadjacent full selections in the middle dimensions */
    int mem3_buffer[1][5][3][1][1][3][6][1];
    hsize_t mem3_dims[8] = { 1, 5, 3, 1, 1, 3, 6, 1 };
    hsize_t mem3_start[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
    hsize_t mem3_count[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
    hsize_t mem3_stride[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
    hsize_t mem3_block[8] = { 1, 5, 3, 1, 1, 3, 6, 1 };

    /* For testing the full selections in the fastest-growing end and the slowest-growing end */
    int mem4_buffer[4][5][1][1][1][1][6][2];
    hsize_t mem4_dims[8] = { 4, 5, 1, 1, 1, 1, 6, 2 };
    hsize_t mem4_start[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
    hsize_t mem4_count[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
    hsize_t mem4_stride[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
    hsize_t mem4_block[8] = { 4, 5, 1, 1, 1, 1, 6, 2 };

    /* For testing the full selections in the fastest-growing end and slowest-growing end,
     * also in the middle dimensions */
    int mem5_buffer[4][5][1][4][2][1][6][2];
    hsize_t mem5_dims[8] = { 4, 5, 1, 4, 2, 1, 6, 2 };
    hsize_t mem5_start[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
    hsize_t mem5_count[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
    hsize_t mem5_stride[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
    hsize_t mem5_block[8] = { 4, 5, 1, 4, 2, 1, 6, 2 };

    /* Create and write the dataset */
    sid = H5Screate_simple(8, da_dims, da_dims);
    CHECK(sid, FAIL, "H5Screate_simple");

    plid = H5Pcreate(H5P_DATASET_CREATE);
    CHECK(plid, FAIL, "H5Pcreate");

    if(is_chunked) {
        ret = H5Pset_chunk(plid, 8, da_chunksize);
        CHECK(ret, FAIL, "H5Pset_chunk");
    }

    /* Construct dataset's name */
    memset(dset_name, 0, NAME_LEN);
    strcat(dset_name, MULTI_ENDS_SEL_HYPER_DSET);
    if(is_chunked)
        strcat(dset_name, "_chunked");

    did = H5Dcreate2(file, dset_name, H5T_NATIVE_INT, sid, H5P_DEFAULT, plid, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dcreate2");

    for(i=0; i<4; i++)
        for(j=0; j<5; j++)
            for(k=0; k<3; k++)
                for(l=0; l<4; l++)
                    for(m=0; m<2; m++)
                        for(n=0; n<3; n++)
                            for(p=0; p<6; p++) {
                                data_buf[i][j][k][l][m][n][p][0] = i*1000000 + j*100000 + k*10000 + l*1000 + m*100 + n*10 + p;
                                data_buf[i][j][k][l][m][n][p][1] = i*1000000 + j*100000 + k*10000 + l*1000 + m*100 + n*10 + p + 1;
                            }

    ret = H5Dwrite(did, H5T_NATIVE_INT, sid, sid, H5P_DEFAULT, data_buf);
    CHECK(ret, FAIL, "H5Dwrite");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    /* ****** Case 1: ******
     * Testing the full selections in the fastest-growing end and in the middle dimensions*/
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen");

    /* Select the elements in the dataset */
    ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem1_start, mem1_stride, mem1_count, mem1_block);
    CHECK(ret, FAIL, "H5Sselect_hyperslab");

    msid = H5Screate_simple(8, mem1_dims, mem1_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem1_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<4; i++)
        for(j=0; j<2; j++)
            for(k=0; k<6; k++)
                for(l=0; l<2; l++)
                    if(data_buf[0][0][0][i][j][0][k][l] != mem1_buffer[0][0][0][i][j][0][k][l]) {
                        TestErrPrintf("%u: Read different values than written at index 0,0,0,%d,%d,0,%d,%d\n", __LINE__, i, j, k, l);
                    }

    /* ****** Case 2: ******
     * Testing the full selections in the slowest-growing end and in the middle dimensions*/
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen");

    /* Select the elements in the dataset */
    ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem2_start, mem2_stride, mem2_count, mem2_block);
    CHECK(ret, FAIL, "H5Sselect_hyperslab");

    msid = H5Screate_simple(8, mem2_dims, mem2_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem2_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<4; i++)
        for(j=0; j<5; j++)
            for(k=0; k<4; k++)
                for(l=0; l<2; l++)
                    if(data_buf[i][j][0][k][l][0][0][0] != mem2_buffer[i][j][0][k][l][0][0][0]) {
                        TestErrPrintf("%u: Read different values than written at index %d,%d,0,%d,%d,0,0,0\n", __LINE__, i, j, k, l);
                    }

    /* ****** Case 3: ******
     * Testing two unadjacent full selections in the middle dimensions */
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen");

    /* Select the elements in the dataset */
    ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem3_start, mem3_stride, mem3_count, mem3_block);
    CHECK(ret, FAIL, "H5Sselect_hyperslab");

    msid = H5Screate_simple(8, mem3_dims, mem3_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem3_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<5; i++)
        for(j=0; j<3; j++)
            for(k=0; k<3; k++)
                for(l=0; l<6; l++)
                    if(data_buf[0][i][j][0][0][k][l][0] != mem3_buffer[0][i][j][0][0][k][l][0]) {
                        TestErrPrintf("%u: Read different values than written at index 0,%d,%d,0,0,%d,%d,0\n", __LINE__, i, j, k, l);
                    }

    /* ****** Case 4: ******
     * Testing the full selections in the fastest-growing end and the slowest-growing end */
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen");

    /* Select the elements in the dataset */
    ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem4_start, mem4_stride, mem4_count, mem4_block);
    CHECK(ret, FAIL, "H5Sselect_hyperslab");

    msid = H5Screate_simple(8, mem4_dims, mem4_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem4_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<4; i++)
        for(j=0; j<5; j++)
            for(k=0; k<6; k++)
                for(l=0; l<2; l++)
                    if(data_buf[i][j][0][0][0][0][k][l] != mem4_buffer[i][j][0][0][0][0][k][l]) {
                        TestErrPrintf("%u: Read different values than written at index %d,%d,0,0,0,0,%d,%d\n", __LINE__, i, j, k, l);
                    }


    /* ****** Case 5: ******
     * Testing the full selections in the fastest-growing end and the slowest-growing end,
     * and also in the middle dimensions */
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen");

    /* Select the elements in the dataset */
    ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem5_start, mem5_stride, mem5_count, mem5_block);
    CHECK(ret, FAIL, "H5Sselect_hyperslab");

    msid = H5Screate_simple(8, mem5_dims, mem5_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem5_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<4; i++)
        for(j=0; j<5; j++)
            for(k=0; k<4; k++)
                for(l=0; l<2; l++)
                    for(m=0; m<6; m++)
                        for(n=0; n<2; n++)
                            if(data_buf[i][j][0][k][l][0][m][n] != mem5_buffer[i][j][0][k][l][0][m][n]) {
                                TestErrPrintf("%u: Read different values than written at index %d,%d,0,%d,%d,0,%d,%d\n", __LINE__, i, j, k, l, m, n);
                            }


    ret = H5Sclose(sid);
    CHECK(ret, FAIL, "H5Sclose");

    ret = H5Pclose(plid);
    CHECK(ret, FAIL, "H5Pclose");
}
Ejemplo n.º 8
0
/***********************************************************
**
** test_singleEnd_selHyperslab(): Test full hyperslab selection
** of only one block.
**
*************************************************************/
static void test_singleEnd_selHyperslab(hid_t file, hbool_t is_chunked)
{
    hid_t sid, did, msid;
    char dset_name[NAME_LEN];        /* Dataset name */
    herr_t ret;                 /* Generic error return */
    int i, j;
    hsize_t da_dims[4] = { 2, 3, 6, 2 };

    /* For testing the full selection in the fastest-growing end */
    int mem1_buffer[1][1][6][2];
    hsize_t mem1_dims[4] = { 1, 1, 6, 2 };
    hsize_t mem1_start[4] = { 0, 0, 0, 0 };
    hsize_t mem1_count[4] = { 1, 1, 1, 1 };
    hsize_t mem1_stride[4] = { 1, 1, 1, 1 };
    hsize_t mem1_block[4] = { 1, 1, 6, 2 };

    /* For testing the full selection in the slowest-growing end */
    int mem2_buffer[2][3][1][1];
    hsize_t mem2_dims[4] = { 2, 3, 1, 1 };
    hsize_t mem2_start[4] = { 0, 0, 0, 0 };
    hsize_t mem2_count[4] = { 1, 1, 1, 1 };
    hsize_t mem2_stride[4] = { 1, 1, 1, 1 };
    hsize_t mem2_block[4] = { 2, 3, 1, 1 };

    /* For testing the full selection in the middle dimensions */
    int mem3_buffer[1][3][6][1];
    hsize_t mem3_dims[4] = { 1, 3, 6, 1 };
    hsize_t mem3_start[4] = { 0, 0, 0, 0 };
    hsize_t mem3_count[4] = { 1, 1, 1, 1 };
    hsize_t mem3_stride[4] = { 1, 1, 1, 1 };
    hsize_t mem3_block[4] = { 1, 3, 6, 1 };

    /* Construct dataset's name */
    memset(dset_name, 0, NAME_LEN);
    strcat(dset_name, SINGLE_END_DSET);
    if(is_chunked)
        strcat(dset_name, "_chunked");

    /* Dataspace for the dataset in file */
    sid = H5Screate_simple(4, da_dims, da_dims);
    CHECK(sid, FAIL, "H5Screate_simple");

    /* ****** Case 1: ******
     * Testing the full selection in the fastest-growing end */
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen");

    /* Select the elements in the dataset */
    ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem1_start, mem1_stride, mem1_count, mem1_block);
    CHECK(ret, FAIL, "H5Sselect_hyperslab");

    /* Dataspace for memory buffer */
    msid = H5Screate_simple(4, mem1_dims, mem1_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem1_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<6; i++)
        for(j=0; j<2; j++)
            if(da_buffer[0][0][i][j] != mem1_buffer[0][0][i][j]) {
                TestErrPrintf("%u: Read different values than written at index 0,0,%d,%d\n", __LINE__, i, j);
            }

    /* ****** Case 2: ******
     * Testing the full selection in the slowest-growing end */
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen");

    /* Select the elements in the dataset */
    ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem2_start, mem2_stride, mem2_count, mem2_block);
    CHECK(ret, FAIL, "H5Sselect_hyperslab");

    /* Dataspace for memory buffer */
    msid = H5Screate_simple(4, mem2_dims, mem2_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem2_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<2; i++)
        for(j=0; j<3; j++)
            if(da_buffer[i][j][0][0] != mem2_buffer[i][j][0][0]) {
                TestErrPrintf("%u: Read different values than written at index %d,%d,0,0\n", __LINE__, i, j);
            }

    /* ****** Case 3: ******
     * Testing the full selection in the middle dimensions */
    did = H5Dopen2(file, dset_name, H5P_DEFAULT);
    CHECK(did, FAIL, "H5Dopen");

    /* Select the elements in the dataset */
    ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, mem3_start, mem3_stride, mem3_count, mem3_block);
    CHECK(ret, FAIL, "H5Sselect_hyperslab");

    /* Dataspace for memory buffer */
    msid = H5Screate_simple(4, mem3_dims, mem3_dims);
    CHECK(msid, FAIL, "H5Screate_simple");

    ret = H5Sselect_all(msid);
    CHECK(ret, FAIL, "H5Sselect_all");

    ret = H5Dread(did, H5T_NATIVE_INT, msid, sid, H5P_DEFAULT, mem3_buffer);
    CHECK(ret, FAIL, "H5Dread");

    ret = H5Dclose(did);
    CHECK(ret, FAIL, "H5Dclose");

    ret = H5Sclose(msid);
    CHECK(ret, FAIL, "H5Sclose");

    for(i=0; i<3; i++)
        for(j=0; j<6; j++)
            if(da_buffer[0][i][j][0] != mem3_buffer[0][i][j][0]) {
                TestErrPrintf("%u: Read different values than written at index 0,%d,%d,0\n", __LINE__, i, j);
            }


    ret = H5Sclose(sid);
    CHECK(ret, FAIL, "H5Sclose");
}
Ejemplo n.º 9
0
escdf_errno_t utils_hdf5_read_dataset(hid_t dtset_id,
                                      void *buf,
                                      hid_t mem_type_id,
                                      const hsize_t *start,
                                      const hsize_t *count,
                                      const hsize_t *stride)
{
    hid_t memspace_id, diskspace_id, plist;
    herr_t err_id;
    hssize_t len;

    /* disk use the start, count and stride. */
    if ((diskspace_id = H5Dget_space(dtset_id)) < 0) {
        RETURN_WITH_ERROR(diskspace_id);
    }
    
    if (start && count) {
        if ((err_id = H5Sselect_hyperslab(diskspace_id, H5S_SELECT_SET,
                                          start, stride, count, NULL)) < 0) {
            H5Sclose(diskspace_id);
            RETURN_WITH_ERROR(err_id);
        }
    } else {
        if ((err_id = H5Sselect_all(diskspace_id)) < 0) {
            H5Sclose(diskspace_id);
            RETURN_WITH_ERROR(err_id);
        }
    }
    if ((len = H5Sget_select_npoints(diskspace_id)) < 0) {
        H5Sclose(diskspace_id);
        RETURN_WITH_ERROR(len);
    }
    if (!len) {
        if ((err_id = H5Sselect_none(diskspace_id)) < 0) {
            H5Sclose(diskspace_id);
            RETURN_WITH_ERROR(err_id);
        }
    }

    /* create dataspace for memory and disk. */
    /* memory is a flat array with the size on the slice. */
    if ((memspace_id = H5Screate_simple(1, &len, NULL)) < 0) {
        H5Sclose(diskspace_id);
        RETURN_WITH_ERROR(memspace_id);
    }

    /* Read */
    plist = H5Pcreate(H5P_DATASET_XFER);
    /* H5Pset_dxpl_mpio(plist, H5FD_MPIO_COLLECTIVE); */
    if ((err_id = H5Dread(dtset_id, mem_type_id, memspace_id, diskspace_id, plist, buf)) < 0) {
        H5Pclose(plist);
        H5Sclose(diskspace_id);
        H5Sclose(memspace_id);
        RETURN_WITH_ERROR(err_id);
    }

    H5Pclose(plist);
    H5Sclose(diskspace_id);
    H5Sclose(memspace_id);

    return ESCDF_SUCCESS;
}
Ejemplo n.º 10
0
void io_mode_confusion(void)
{
    /*
     * HDF5 APIs definitions
     */

    const int   rank = 1;
    const char *dataset_name = "IntArray";

    hid_t       file_id, dset_id;         /* file and dataset identifiers */
    hid_t       filespace, memspace;      /* file and memory dataspace */
                                          /* identifiers               */
    hsize_t     dimsf[1];                 /* dataset dimensions */
    int         data[N] = {1};            /* pointer to data buffer to write */
    hsize_t     coord[N] = {0L,1L,2L,3L};
    hsize_t     start[1];
    hsize_t     stride[1];
    hsize_t     count[1];
    hsize_t     block[1];
    hid_t       plist_id;                 /* property list identifier */
    herr_t      status;


    /*
     * MPI variables
     */

    int mpi_size, mpi_rank;


    /*
     * test bed related variables
     */

    const char *	fcn_name = "io_mode_confusion";
    const hbool_t	verbose = FALSE;
    const H5Ptest_param_t *	pt;
    char *		filename;


    pt = GetTestParameters();
    filename = pt->name;

    MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
    MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);

    /*
     * Set up file access property list with parallel I/O access
     */

    if ( verbose )
        HDfprintf(stdout, "%0d:%s: Setting up property list.\n",
                  mpi_rank, fcn_name);

    plist_id = H5Pcreate(H5P_FILE_ACCESS);

    VRFY((plist_id != -1), "H5Pcreate() failed");

    status = H5Pset_fapl_mpio(plist_id, MPI_COMM_WORLD, MPI_INFO_NULL);

    VRFY(( status >= 0 ), "H5Pset_fapl_mpio() failed");


    /*
     * Create a new file collectively and release property list identifier.
     */

    if ( verbose )
        HDfprintf(stdout, "%0d:%s: Creating new file.\n", mpi_rank, fcn_name);

    file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, plist_id);

    VRFY(( file_id >= 0 ), "H5Fcreate() failed");

    status = H5Pclose(plist_id);

    VRFY(( status >= 0 ), "H5Pclose() failed");


    /*
     * Create the dataspace for the dataset.
     */

    if ( verbose )
        HDfprintf(stdout, "%0d:%s: Creating the dataspace for the dataset.\n",
                  mpi_rank, fcn_name);

    dimsf[0] = N;

    filespace = H5Screate_simple(rank, dimsf, NULL);

    VRFY(( filespace >= 0 ), "H5Screate_simple() failed.");


    /*
     * Create the dataset with default properties and close filespace.
     */

    if ( verbose )
        HDfprintf(stdout,
                  "%0d:%s: Creating the dataset, and closing filespace.\n",
                  mpi_rank, fcn_name);

    dset_id = H5Dcreate(file_id, dataset_name, H5T_NATIVE_INT, filespace,
                        H5P_DEFAULT);

    VRFY(( dset_id >= 0 ), "H5Dcreate() failed");

    status = H5Sclose(filespace);

    VRFY(( status >= 0 ), "H5Sclose() failed");


    if ( verbose )
        HDfprintf(stdout, "%0d:%s: Calling H5Screate_simple().\n",
                  mpi_rank, fcn_name);

    memspace = H5Screate_simple(rank, dimsf, NULL);

    VRFY(( memspace >= 0 ), "H5Screate_simple() failed.");


    if( mpi_rank == 0 ) {

        if ( verbose )
            HDfprintf(stdout, "%0d:%s: Calling H5Sselect_all(memspace).\n",
                      mpi_rank, fcn_name);

        status = H5Sselect_all(memspace);

        VRFY(( status >= 0 ), "H5Sselect_all() failed");

    } else {

        if ( verbose )
            HDfprintf(stdout, "%0d:%s: Calling H5Sselect_none(memspace).\n",
                      mpi_rank, fcn_name);

        status = H5Sselect_none(memspace);

        VRFY(( status >= 0 ), "H5Sselect_none() failed");

    }


    if ( verbose )
        HDfprintf(stdout, "%0d:%s: Calling MPI_Barrier().\n",
                  mpi_rank, fcn_name);

    MPI_Barrier(MPI_COMM_WORLD);


    if ( verbose )
        HDfprintf(stdout, "%0d:%s: Calling H5Dget_space().\n",
                  mpi_rank, fcn_name);

    filespace = H5Dget_space(dset_id);

    VRFY(( filespace >= 0 ), "H5Dget_space() failed");


    start[0] = 0L;
    stride[0] = 1;
    count[0] = 1;
    block[0] = N;

    if ( mpi_rank == 0 ) {

        /* select all */

        if ( verbose )
             HDfprintf(stdout,
                       "%0d:%s: Calling H5Sselect_elements() -- set up hang?\n",
                       mpi_rank, fcn_name);

        status = H5Sselect_elements(filespace, H5S_SELECT_SET, N,
                                    (const hsize_t **)&coord);

        VRFY(( status >= 0 ), "H5Sselect_elements() failed");

    } else {

        /* select nothing */

        if ( verbose )
            HDfprintf(stdout, "%0d:%s: Calling H5Sselect_none().\n",
                      mpi_rank, fcn_name);

        status = H5Sselect_none(filespace);

        VRFY(( status >= 0 ), "H5Sselect_none() failed");

    }


    if ( verbose )
        HDfprintf(stdout, "%0d:%s: Calling MPI_Barrier().\n",
                  mpi_rank, fcn_name);

    MPI_Barrier(MPI_COMM_WORLD);


    if ( verbose )
        HDfprintf(stdout, "%0d:%s: Calling H5Pcreate().\n", mpi_rank, fcn_name);

    plist_id = H5Pcreate(H5P_DATASET_XFER);

    VRFY(( plist_id != -1 ), "H5Pcreate() failed");


    if ( verbose )
        HDfprintf(stdout, "%0d:%s: Calling H5Pset_dxpl_mpio().\n",
                  mpi_rank, fcn_name);

    status = H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);

    VRFY(( status >= 0 ), "H5Pset_dxpl_mpio() failed");


    if ( verbose )
        HDfprintf(stdout, "%0d:%s: Calling H5Dwrite() -- hang here?.\n",
                  mpi_rank, fcn_name);

    status = H5Dwrite(dset_id, H5T_NATIVE_INT, memspace, filespace,
                      plist_id, data);

    if ( verbose )
        HDfprintf(stdout, "%0d:%s: Returned from H5Dwrite(), status=%d.\n",
                  mpi_rank, fcn_name, status);

    VRFY(( status >= 0 ), "H5Dwrite() failed");

    /*
     * Close/release resources.
     */

    if ( verbose )
        HDfprintf(stdout, "%0d:%s: Cleaning up from test.\n",
                  mpi_rank, fcn_name);

    status = H5Dclose(dset_id);
    VRFY(( status >= 0 ), "H5Dclose() failed");

    status = H5Sclose(filespace);
    VRFY(( status >= 0 ), "H5Dclose() failed");

    status = H5Sclose(memspace);
    VRFY(( status >= 0 ), "H5Sclose() failed");

    status = H5Pclose(plist_id);
    VRFY(( status >= 0 ), "H5Pclose() failed");

    status = H5Fclose(file_id);
    VRFY(( status >= 0 ), "H5Fclose() failed");


    if ( verbose )
        HDfprintf(stdout, "%0d:%s: Done.\n", mpi_rank, fcn_name);

    return;

} /* io_mode_confusion() */