2003-04-01 01:59:04 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2007-02-07 22:56:24 +08:00
|
|
|
* Copyright by The HDF Group. *
|
2003-04-01 01:59:04 +08:00
|
|
|
* Copyright by the Board of Trustees of the University of Illinois. *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
2017-04-15 00:54:16 +08:00
|
|
|
* the COPYING file, which can be found at the root of the source code *
|
|
|
|
* distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
|
|
|
|
* If you do not have access to either file, you may request a copy from *
|
|
|
|
* help@hdfgroup.org. *
|
2003-04-01 01:59:04 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
2000-05-19 03:13:33 +08:00
|
|
|
/********************************************************************
|
|
|
|
*
|
|
|
|
* Testing thread safety in dataset creation in the HDF5 library
|
|
|
|
* -------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* Set of tests to run multiple threads so that each creates a different
|
|
|
|
* dataset. This is likely to cause race-conditions if run in a non
|
|
|
|
* threadsafe environment.
|
|
|
|
*
|
|
|
|
* Temporary files generated:
|
2000-05-20 07:00:03 +08:00
|
|
|
* ttsafe_dcreate.h5
|
2000-05-19 03:13:33 +08:00
|
|
|
*
|
|
|
|
* HDF5 APIs exercised in thread:
|
[svn-r14199] Description:
Add H5Dcreate to API versioned routines, replacing internal usage with
H5Dcreate2
Fix thread-safe error stack initialization for API versioned error
stack printing routines.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-12 00:24:11 +08:00
|
|
|
* H5Screate_simple, H5Tcopy, H5Tset_order, H5Dcreate2, H5Dwrite, H5Dclose,
|
2000-05-19 03:13:33 +08:00
|
|
|
* H5Tclose, H5Sclose.
|
|
|
|
*
|
|
|
|
* Created: Apr 28 2000
|
|
|
|
* Programmer: Chee Wai LEE
|
|
|
|
*
|
|
|
|
* Modification History
|
|
|
|
* --------------------
|
|
|
|
*
|
2000-05-20 07:00:03 +08:00
|
|
|
* 19 May 2000, Bill Wendling
|
|
|
|
* Changed so that it creates its own HDF5 file and removes it at cleanup
|
2004-01-10 09:41:13 +08:00
|
|
|
* time.
|
2000-05-20 07:00:03 +08:00
|
|
|
*
|
2000-05-19 03:13:33 +08:00
|
|
|
********************************************************************/
|
|
|
|
#include "ttsafe.h"
|
|
|
|
|
2003-06-26 10:10:33 +08:00
|
|
|
#ifdef H5_HAVE_THREADSAFE
|
2000-05-19 03:13:33 +08:00
|
|
|
|
2000-05-20 07:00:03 +08:00
|
|
|
#define FILENAME "ttsafe_dcreate.h5"
|
|
|
|
#define NUM_THREAD 16
|
|
|
|
|
2000-05-19 03:13:33 +08:00
|
|
|
void *tts_dcreate_creator(void *);
|
|
|
|
|
2000-05-20 07:00:03 +08:00
|
|
|
typedef struct thread_info {
|
|
|
|
int id;
|
|
|
|
hid_t file;
|
|
|
|
const char *dsetname;
|
2005-08-14 04:53:35 +08:00
|
|
|
} thread_info;
|
2000-05-20 07:00:03 +08:00
|
|
|
|
2003-02-08 05:14:19 +08:00
|
|
|
/*
|
|
|
|
* Set individual dataset names (rather than generated the names
|
|
|
|
* automatically)
|
|
|
|
*/
|
|
|
|
const char *dsetname[NUM_THREAD]={
|
|
|
|
"zero",
|
|
|
|
"one",
|
|
|
|
"two",
|
|
|
|
"three",
|
|
|
|
"four",
|
|
|
|
"five",
|
|
|
|
"six",
|
|
|
|
"seven",
|
|
|
|
"eight",
|
|
|
|
"nine",
|
|
|
|
"ten",
|
|
|
|
"eleven",
|
|
|
|
"twelve",
|
|
|
|
"thirteen",
|
|
|
|
"fourteen",
|
|
|
|
"fifteen"
|
|
|
|
};
|
|
|
|
|
|
|
|
thread_info thread_out[NUM_THREAD];
|
|
|
|
|
2000-05-19 03:13:33 +08:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
|
|
|
* Thread safe test - multiple dataset creation
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
2000-05-20 07:00:03 +08:00
|
|
|
void tts_dcreate(void)
|
|
|
|
{
|
2010-09-11 00:15:34 +08:00
|
|
|
/* thread definitions */
|
|
|
|
H5TS_thread_t threads[NUM_THREAD];
|
2003-02-08 05:14:19 +08:00
|
|
|
|
|
|
|
/* HDF5 data definitions */
|
|
|
|
hid_t file, dataset;
|
|
|
|
int datavalue, i;
|
2010-09-11 00:15:34 +08:00
|
|
|
H5TS_attr_t attribute;
|
2003-02-08 05:14:19 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* set pthread attribute to perform global scheduling */
|
2010-09-11 00:15:34 +08:00
|
|
|
H5TS_attr_init(&attribute);
|
|
|
|
|
|
|
|
/* set thread scope to system */
|
2003-02-10 23:38:52 +08:00
|
|
|
#ifdef H5_HAVE_SYSTEM_SCOPE_THREADS
|
2010-09-11 00:15:34 +08:00
|
|
|
H5TS_attr_setscope(&attribute, H5TS_SCOPE_SYSTEM);
|
2003-02-10 23:38:52 +08:00
|
|
|
#endif /* H5_HAVE_SYSTEM_SCOPE_THREADS */
|
2003-02-08 05:14:19 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a hdf5 file using H5F_ACC_TRUNC access, default file
|
|
|
|
* creation plist and default file access plist
|
|
|
|
*/
|
|
|
|
file = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
[svn-r14193] Description:
Make H5Dopen versioned and change all internal usage to use H5Dopen2
Add simple regression test for H5Dopen1
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-09 03:59:36 +08:00
|
|
|
assert(file >= 0);
|
2003-02-08 05:14:19 +08:00
|
|
|
|
|
|
|
/* simultaneously create a large number of datasets within the file */
|
[svn-r14193] Description:
Make H5Dopen versioned and change all internal usage to use H5Dopen2
Add simple regression test for H5Dopen1
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-09 03:59:36 +08:00
|
|
|
for(i = 0; i < NUM_THREAD; i++) {
|
2003-02-08 05:14:19 +08:00
|
|
|
thread_out[i].id = i;
|
|
|
|
thread_out[i].file = file;
|
|
|
|
thread_out[i].dsetname = dsetname[i];
|
2010-09-11 00:15:34 +08:00
|
|
|
threads[i] = H5TS_create_thread(tts_dcreate_creator, NULL, &thread_out[i]);
|
[svn-r14193] Description:
Make H5Dopen versioned and change all internal usage to use H5Dopen2
Add simple regression test for H5Dopen1
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-09 03:59:36 +08:00
|
|
|
} /* end for */
|
2003-02-08 05:14:19 +08:00
|
|
|
|
[svn-r14193] Description:
Make H5Dopen versioned and change all internal usage to use H5Dopen2
Add simple regression test for H5Dopen1
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-09 03:59:36 +08:00
|
|
|
for(i = 0;i < NUM_THREAD; i++) {
|
2010-09-11 00:15:34 +08:00
|
|
|
H5TS_wait_for_thread(threads[i]);
|
2003-02-08 05:14:19 +08:00
|
|
|
} /* end for */
|
|
|
|
|
|
|
|
/* compare data to see if it is written correctly */
|
|
|
|
|
[svn-r14193] Description:
Make H5Dopen versioned and change all internal usage to use H5Dopen2
Add simple regression test for H5Dopen1
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-09 03:59:36 +08:00
|
|
|
for(i = 0; i < NUM_THREAD; i++) {
|
|
|
|
if((dataset = H5Dopen2(file, dsetname[i], H5P_DEFAULT)) < 0) {
|
2004-01-10 09:41:13 +08:00
|
|
|
TestErrPrintf("Dataset name not found - test failed\n");
|
2003-02-08 05:14:19 +08:00
|
|
|
H5Fclose(file);
|
|
|
|
return;
|
|
|
|
} else {
|
[svn-r14193] Description:
Make H5Dopen versioned and change all internal usage to use H5Dopen2
Add simple regression test for H5Dopen1
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-09 03:59:36 +08:00
|
|
|
ret = H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &datavalue);
|
|
|
|
assert(ret >= 0);
|
2003-02-08 05:14:19 +08:00
|
|
|
|
[svn-r14193] Description:
Make H5Dopen versioned and change all internal usage to use H5Dopen2
Add simple regression test for H5Dopen1
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-09 03:59:36 +08:00
|
|
|
if(datavalue != i) {
|
2004-12-29 22:26:20 +08:00
|
|
|
TestErrPrintf("Wrong value read %d for dataset name %s - test failed\n",
|
2003-02-08 05:14:19 +08:00
|
|
|
datavalue, dsetname[i]);
|
[svn-r14193] Description:
Make H5Dopen versioned and change all internal usage to use H5Dopen2
Add simple regression test for H5Dopen1
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-09 03:59:36 +08:00
|
|
|
ret = H5Dclose(dataset);
|
|
|
|
assert(ret >= 0);
|
|
|
|
ret = H5Fclose(file);
|
|
|
|
assert(ret >= 0);
|
2003-02-08 05:14:19 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
[svn-r14193] Description:
Make H5Dopen versioned and change all internal usage to use H5Dopen2
Add simple regression test for H5Dopen1
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-09 03:59:36 +08:00
|
|
|
ret = H5Dclose(dataset);
|
|
|
|
assert(ret >= 0);
|
2003-02-08 05:14:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* close remaining resources */
|
[svn-r14193] Description:
Make H5Dopen versioned and change all internal usage to use H5Dopen2
Add simple regression test for H5Dopen1
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-09 03:59:36 +08:00
|
|
|
ret = H5Fclose(file);
|
|
|
|
assert(ret >= 0);
|
2003-02-08 05:14:19 +08:00
|
|
|
|
|
|
|
/* Destroy the thread attribute */
|
2010-09-11 00:15:34 +08:00
|
|
|
H5TS_attr_destroy(&attribute);
|
2000-05-19 03:13:33 +08:00
|
|
|
}
|
|
|
|
|
2003-02-08 05:14:19 +08:00
|
|
|
void *tts_dcreate_creator(void *_thread_data)
|
2000-05-20 07:00:03 +08:00
|
|
|
{
|
[svn-r14199] Description:
Add H5Dcreate to API versioned routines, replacing internal usage with
H5Dcreate2
Fix thread-safe error stack initialization for API versioned error
stack printing routines.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-12 00:24:11 +08:00
|
|
|
hid_t dataspace, dataset;
|
|
|
|
herr_t ret;
|
|
|
|
hsize_t dimsf[1]; /* dataset dimensions */
|
|
|
|
struct thread_info thread_data;
|
|
|
|
|
|
|
|
memcpy(&thread_data, _thread_data, sizeof(struct thread_info));
|
|
|
|
|
|
|
|
/* define dataspace for dataset */
|
|
|
|
dimsf[0] = 1;
|
|
|
|
dataspace = H5Screate_simple(1, dimsf, NULL);
|
|
|
|
assert(dataspace >= 0);
|
|
|
|
|
|
|
|
/* create a new dataset within the file */
|
|
|
|
dataset = H5Dcreate2(thread_data.file, thread_data.dsetname,
|
|
|
|
H5T_NATIVE_INT, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
|
|
|
assert(dataset >= 0);
|
|
|
|
|
|
|
|
/* initialize data for dataset and write value to dataset */
|
|
|
|
ret = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
|
|
|
|
H5P_DEFAULT, &thread_data.id);
|
|
|
|
assert(ret >= 0);
|
|
|
|
|
|
|
|
/* close dataset and dataspace resources */
|
|
|
|
ret = H5Dclose(dataset);
|
|
|
|
assert(ret >= 0);
|
|
|
|
ret = H5Sclose(dataspace);
|
|
|
|
assert(ret >= 0);
|
|
|
|
|
|
|
|
return NULL;
|
2000-05-19 03:13:33 +08:00
|
|
|
}
|
|
|
|
|
2000-05-20 07:00:03 +08:00
|
|
|
void cleanup_dcreate(void)
|
|
|
|
{
|
[svn-r14199] Description:
Add H5Dcreate to API versioned routines, replacing internal usage with
H5Dcreate2
Fix thread-safe error stack initialization for API versioned error
stack printing routines.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-12 00:24:11 +08:00
|
|
|
HDunlink(FILENAME);
|
2000-05-19 03:13:33 +08:00
|
|
|
}
|
|
|
|
#endif /*H5_HAVE_THREADSAFE*/
|
[svn-r14199] Description:
Add H5Dcreate to API versioned routines, replacing internal usage with
H5Dcreate2
Fix thread-safe error stack initialization for API versioned error
stack printing routines.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-12 00:24:11 +08:00
|
|
|
|