h5_init.c 17.9 KB
Newer Older
gsell's avatar
h5core:  
gsell committed
1
/*
gsell's avatar
gsell committed
2
  Copyright (c) 2006-2016, The Regents of the University of California,
gsell's avatar
h5core:  
gsell committed
3 4 5 6 7 8 9
  through Lawrence Berkeley National Laboratory (subject to receipt of any
  required approvals from the U.S. Dept. of Energy) and the Paul Scherrer
  Institut (Switzerland).  All rights reserved.

  License: see file COPYING in top level of source distribution.
*/

10 11 12 13 14
#include <stdlib.h>
#include <stdarg.h>     /* va_arg - System dependent ?! */
#include <string.h>
#include <assert.h>

gsell's avatar
h5core:  
gsell committed
15 16
#include "config.h"

gsell's avatar
gsell committed
17
#include "private/h5_hdf5.h"
18

gsell's avatar
gsell committed
19 20 21
#include "private/h5_mpi.h"
#include "private/h5t_types.h"
#include "private/h5t_tags.h"
22 23 24 25

int h5_initialized = 0;
h5_dta_types_t h5_dta_types;            // type ids' for base & compound data types
int h5_myproc = 0;                      // proc id
gsell's avatar
h5core:  
gsell committed
26
const char* H5_VER_STRING = PACKAGE_VERSION;
27 28 29 30 31 32 33 34 35 36 37 38
/*
   create several HDF5 types
 */
static inline h5_err_t
create_array_types (
        void
        ) {
	H5_PRIV_FUNC_ENTER (h5_err_t, "%s", "void");

	hsize_t dims[1] = { 3 };
	TRY(
	        h5_dta_types.h5_coord3d_t = hdf5_create_array_type (
39
	                H5_FLOAT64,
40 41 42 43 44
	                1,
	                dims)
	        );
	TRY(
	        h5_dta_types.h5_3glb_idx_t = hdf5_create_array_type (
45
	                H5_ID,
46 47 48 49 50 51
	                1,
	                dims)
	        );
	dims[0] = 4;
	TRY(
	        h5_dta_types.h5_4glb_idx_t = hdf5_create_array_type (
52
	                H5_ID,
53 54 55 56 57
	                1,
	                dims)
	        );
	TRY(
	        h5_dta_types.h5_4chk_idx_t = hdf5_create_array_type (
58
	                H5_INT32,
59 60 61 62 63 64
	                1,
	                dims)
	        );
	dims[0] = 6;
	TRY(
	        h5_dta_types.h5_coord6d_t = hdf5_create_array_type (
65
	                H5_FLOAT64,
66 67 68
	                1,
	                dims)
	        );
gsell's avatar
gsell committed
69
	H5_RETURN (H5_SUCCESS);
70 71 72 73 74 75 76 77 78 79
}

static inline h5_err_t
create_vertex_type (
        void
        ) {
	H5_PRIV_FUNC_ENTER (h5_err_t, "%s", "void");

	TRY(
	        h5_dta_types.h5_vertex_t = hdf5_create_type (
gsell's avatar
gsell committed
80
	                H5T_COMPOUND,
81 82 83 84 85 86
	                sizeof (h5_glb_vertex_t)) );
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_vertex_t,
	                "idx",
	                HOFFSET (h5_glb_vertex_t, idx),
87
	                H5_ID) );
88 89 90 91 92 93 94
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_vertex_t,
	                "P",
	                HOFFSET (h5_glb_vertex_t, P),
	                h5_dta_types.h5_coord3d_t) );

gsell's avatar
gsell committed
95
	H5_RETURN (H5_SUCCESS);
96 97 98 99 100 101 102 103 104 105
}

static inline h5_err_t
create_triangle_type (
        void
        ) {
	H5_PRIV_FUNC_ENTER (h5_err_t, "%s", "void");

	TRY(
	        h5_dta_types.h5_triangle_t = hdf5_create_type (
gsell's avatar
gsell committed
106
	                H5T_COMPOUND,
107 108 109 110 111 112
	                sizeof (h5_glb_tri_t)) );
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_triangle_t,
	                "idx",
	                HOFFSET (h5_glb_tri_t, idx),
113
	                H5_ID) );
114 115 116 117 118
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_triangle_t,
	                "parent_idx",
	                HOFFSET (h5_glb_tri_t, parent_idx),
119
	                H5_ID) );
120 121 122 123 124
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_triangle_t,
	                "child_idx",
	                HOFFSET(h5_glb_tri_t, child_idx),
125
	                H5_ID) );
126 127 128 129 130
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_triangle_t,
	                "level_idx",
	                HOFFSET(h5_glb_tri_t, level_idx),
131
	                H5_INT16) );
132 133 134 135 136
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_triangle_t,
	                "refinement",
	                HOFFSET(h5_glb_tri_t, refinement),
137
	                H5_INT16) );
138 139 140 141 142
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_triangle_t,
	                "flags",
	                HOFFSET(h5_glb_tri_t, flags),
143
	                H5_INT32) );
144 145 146 147 148 149 150 151 152 153 154 155 156
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_triangle_t,
	                "vertex_indices",
	                HOFFSET (h5_glb_tri_t, vertex_indices),
	                h5_dta_types.h5_3glb_idx_t) );
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_triangle_t,
	                "neighbor_indices",
	                HOFFSET(h5_glb_tri_t, neighbor_indices),
	                h5_dta_types.h5_3glb_idx_t) );

gsell's avatar
gsell committed
157
	H5_RETURN (H5_SUCCESS);
158 159 160 161 162 163 164 165 166 167
}

static inline h5_err_t
create_tag_types (
        void
        ) {
	H5_PRIV_FUNC_ENTER (h5_err_t, "%s", "void");

	TRY (
	        h5_dta_types.h5t_glb_tag_idx_t = hdf5_create_type (
gsell's avatar
gsell committed
168
	                H5T_COMPOUND,
169 170 171 172 173 174
	                sizeof (h5t_glb_tag_idx_t)) );
	TRY (
	        hdf5_insert_type (
	                h5_dta_types.h5t_glb_tag_idx_t,
	                "eid",
	                HOFFSET (h5t_glb_tag_idx_t, eid),
175
	                H5_ID) );
176 177 178 179 180
	TRY (
	        hdf5_insert_type (
	                h5_dta_types.h5t_glb_tag_idx_t,
	                "idx",
	                HOFFSET (h5t_glb_tag_idx_t, idx),
181
	                H5_ID) );
182

gsell's avatar
gsell committed
183
	H5_RETURN (H5_SUCCESS);
184 185 186 187 188 189 190 191 192 193
}

static inline h5_err_t
create_tet_type (
        void
        ) {
	H5_PRIV_FUNC_ENTER (h5_err_t, "%s", "void");

	TRY(
	        h5_dta_types.h5_tet_t = hdf5_create_type (
gsell's avatar
gsell committed
194
	                H5T_COMPOUND,
195 196 197 198 199 200
	                sizeof (h5_glb_tet_t)) );
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_tet_t,
	                "idx",
	                HOFFSET (h5_glb_tet_t, idx),
201
	                H5_ID) );
202 203 204 205 206
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_tet_t,
	                "parent_idx",
	                HOFFSET (h5_glb_tet_t, parent_idx),
207
	                H5_ID) );
208 209 210 211 212
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_tet_t,
	                "child_idx",
	                HOFFSET (h5_glb_tet_t, child_idx),
213
	                H5_INT32) );
214 215 216 217 218
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_tet_t,
	                "level_idx",
	                HOFFSET(h5_glb_tet_t, level_idx),
219
	                H5_INT16) );
220 221 222 223 224
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_tet_t,
	                "refinement",
	                HOFFSET(h5_glb_tet_t, refinement),
225
	                H5_INT16) );
226 227 228 229 230
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_tet_t,
	                "flags",
	                HOFFSET(h5_glb_tet_t, flags),
231
	                H5_INT32) );
232 233 234 235 236 237 238 239 240 241 242 243 244
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_tet_t,
	                "vertex_indices",
	                HOFFSET (h5_glb_tet_t, vertex_indices),
	                h5_dta_types.h5_4glb_idx_t) );
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_tet_t,
	                "neighbor_indices",
	                HOFFSET (h5_glb_tet_t, neighbor_indices),
	                h5_dta_types.h5_4glb_idx_t) );

gsell's avatar
gsell committed
245
	H5_RETURN (H5_SUCCESS);
246 247
}

gsell's avatar
gsell committed
248 249
#if defined(WITH_PARALLEL_H5GRID)

250 251
static inline h5_err_t
create_chunk_type (
gsell's avatar
gsell committed
252 253
	void
	) {
254 255 256
	H5_PRIV_FUNC_ENTER (h5_err_t, "%s", "void");
	TRY(
	        h5_dta_types.h5_chunk_t = hdf5_create_type (
gsell's avatar
gsell committed
257
	                H5T_COMPOUND,
258 259 260 261 262 263
	                sizeof (h5t_chunk_t)) );
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_chunk_t,
	                "idx",
	                HOFFSET (h5t_chunk_t, idx),
264
	                H5_INT32) );
265 266 267 268 269
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_chunk_t,
	                "oct_idx",
	                HOFFSET (h5t_chunk_t, oct_idx),
270
	                H5_INT32) );
271 272 273 274 275
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_chunk_t,
	                "elem",
	                HOFFSET (h5t_chunk_t, elem),
276
	                H5_ID) );
277 278 279 280 281
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_chunk_t,
	                "weight",
	                HOFFSET (h5t_chunk_t, weight),
282
	                H5_ID) );
283 284 285 286 287
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_chunk_t,
	                "num_elems",
	                HOFFSET (h5t_chunk_t, num_elems),
288
	                H5_UINT16) );
289 290 291 292 293
//	TRY(
//	        hdf5_insert_type (
//	                h5_dta_types.h5_chunk_t,
//	                "vtx",
//	                HOFFSET (h5t_chunk_t, vtx),
294
//	                H5_INT64) );
295 296 297 298 299
//	TRY(
//	        hdf5_insert_type (
//	                h5_dta_types.h5_chunk_t,
//	                "num_vtx",
//	                HOFFSET (h5t_chunk_t, num_vtx),
300
//	                H5_INT64) );
gsell's avatar
gsell committed
301
	H5_RETURN (H5_SUCCESS);
302 303 304 305 306 307 308 309 310
}

static inline h5_err_t
create_octree_type (
		void
		) {
	H5_PRIV_FUNC_ENTER (h5_err_t, "%s", "void");
	TRY(
	        h5_dta_types.h5_octree_t = hdf5_create_type (
gsell's avatar
gsell committed
311
	                H5T_COMPOUND,
312 313 314 315 316 317
	                sizeof (h5t_octant_t)) );
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_octree_t,
	                "idx",
	                HOFFSET (h5t_octant_t, idx),
318
	                H5_INT32) );
319 320 321 322 323
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_octree_t,
	                "parent_idx",
	                HOFFSET (h5t_octant_t, parent_idx),
324
	                H5_INT32) );
325 326 327 328 329
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_octree_t,
	                "child_idx",
	                HOFFSET (h5t_octant_t, child_idx),
330
	                H5_INT32) );
331 332 333 334 335
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_octree_t,
	                "level_idx",
	                HOFFSET (h5t_octant_t, level_idx),
336
	                H5_INT16) );
337 338 339 340 341 342 343 344 345 346 347
//	TRY(
//	        hdf5_insert_type (
//	                h5_dta_types.h5_octree_t,
//	                "bounding_box",
//	                HOFFSET (h5t_octant_t, bounding_box),
//	                h5_dta_types.h5_coord6d_t) );
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_octree_t,
	                "userlevels",
	                HOFFSET (h5t_octant_t, userlevels),
348
	                H5_INT32) );
349

gsell's avatar
gsell committed
350
	H5_RETURN (H5_SUCCESS);
351
}
gsell's avatar
gsell committed
352

353 354 355 356 357 358 359
static inline h5_err_t
create_userdata_type (
		void
		) {
	H5_PRIV_FUNC_ENTER (h5_err_t, "%s", "void");
	TRY(
		        h5_dta_types.h5_userdata_t = hdf5_create_type (
gsell's avatar
gsell committed
360
		                H5T_COMPOUND,
361 362 363 364 365 366 367 368
		                sizeof (h5t_oct_userdata_t)) );
	TRY(
	        hdf5_insert_type (
	                h5_dta_types.h5_userdata_t,
	                "idx",
	                HOFFSET (h5t_oct_userdata_t, idx),
	                h5_dta_types.h5_4chk_idx_t) );

gsell's avatar
gsell committed
369
	H5_RETURN (H5_SUCCESS);
370
}
gsell's avatar
gsell committed
371

372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
static inline h5_err_t
create_mpi_type_glb_tet (
        void
        ) {
	h5_glb_tet_t glb_elem;
	H5_PRIV_FUNC_ENTER (h5_err_t, "%s", "void");
	int i = 0;
	const int count = 8;
	int blocklens[count];
	MPI_Aint indices[count];
	MPI_Datatype old_types[count];
	MPI_Aint base;
	MPI_Aint addr;
	TRY (mpi_get_address (&glb_elem, &base));

	// idx
	blocklens[i] = 1;
	TRY (mpi_get_address (&glb_elem.idx, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_LONG_LONG;

	// parent_idx
	blocklens[i] = 1;
	TRY (mpi_get_address (&glb_elem.parent_idx, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_LONG_LONG;

	// child_idx
	blocklens[i] = 1;
	TRY (mpi_get_address (&glb_elem.child_idx, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_LONG_LONG;

	// level_idx
	blocklens[i] = 1;
	TRY (mpi_get_address (&glb_elem.level_idx, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_SHORT;

	// refinement
	blocklens[i] = 1;
	TRY (mpi_get_address (&glb_elem.refinement, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_SHORT;

	// flags
	blocklens[i] = 1;
	TRY (mpi_get_address (&glb_elem.flags, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_UNSIGNED;

	// vertex_indices
	blocklens[i] = 4;
	TRY (mpi_get_address (&glb_elem.vertex_indices, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_LONG_LONG;

	// neighbor_indices
	blocklens[i] = 4;
	TRY (mpi_get_address (&glb_elem.neighbor_indices, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_LONG_LONG;

	// create new type
	assert (i==count);
	TRY (mpi_create_type_struct (count, blocklens, indices, old_types,
	                             &h5_dta_types.mpi_glb_tet));
	// commit new type
	TRY (h5priv_mpi_type_commit (&h5_dta_types.mpi_glb_tet));

gsell's avatar
gsell committed
442
	H5_RETURN (H5_SUCCESS);
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
}

static inline h5_err_t
create_mpi_type_glb_tri (
        void
        ) {
	h5_glb_tri_t glb_elem;
	H5_PRIV_FUNC_ENTER (h5_err_t, "%s", "void");
	int i = 0;
	const int count = 8;
	int blocklens[count];
	MPI_Aint indices[count];
	MPI_Datatype old_types[count];
	MPI_Aint base;
	MPI_Aint addr;
	TRY (mpi_get_address (&glb_elem, &base));

	// idx
	blocklens[i] = 1;
	TRY (mpi_get_address (&glb_elem.idx, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_LONG_LONG;

	// parent_idx
	blocklens[i] = 1;
	TRY (mpi_get_address (&glb_elem.parent_idx, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_LONG_LONG;

	// child_idx
	blocklens[i] = 1;
	TRY (mpi_get_address (&glb_elem.child_idx, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_LONG_LONG;

	// level_idx
	blocklens[i] = 1;
	TRY (mpi_get_address (&glb_elem.level_idx, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_SHORT;

	// refinement
	blocklens[i] = 1;
	TRY (mpi_get_address (&glb_elem.refinement, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_SHORT;

	// flags
	blocklens[i] = 1;
	TRY (mpi_get_address (&glb_elem.flags, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_UNSIGNED;

	// vertex_indices
	blocklens[i] = 3;
	TRY (mpi_get_address (&glb_elem.vertex_indices, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_LONG_LONG;

	// neighbor_indices
	blocklens[i] = 3;
	TRY (mpi_get_address (&glb_elem.neighbor_indices, &addr));
	indices[i] = addr - base;
	old_types[i++] =  MPI_LONG_LONG;

	// create new type
	assert (i==count);
	TRY (mpi_create_type_struct (count, blocklens, indices, old_types,
	                             &h5_dta_types.mpi_glb_triangle));
	// commit new type
	TRY (h5priv_mpi_type_commit (&h5_dta_types.mpi_glb_triangle));

gsell's avatar
gsell committed
515
	H5_RETURN (H5_SUCCESS);
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
}
static inline h5_err_t
create_mpi_type_glb_vtx (
        void
        ) {
	h5_glb_vertex_t glb_vtx;
	H5_PRIV_FUNC_ENTER (h5_err_t, "%s", "void");
	int i = 0;
	const int count = 2;
	int blocklens[count];
	MPI_Aint indices[count];
	MPI_Datatype old_types[count];
	MPI_Aint base;
	MPI_Aint addr;
	TRY (mpi_get_address (&glb_vtx, &base));

	// idx
	blocklens[i] = 1;
	TRY (mpi_get_address (&glb_vtx.idx, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_LONG_LONG;

	// P
	blocklens[i] = 3;
	TRY (mpi_get_address (&glb_vtx.P, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_DOUBLE;

	// create new type
	assert (i==count);
	TRY (mpi_create_type_struct (count, blocklens, indices, old_types,
	                             &h5_dta_types.mpi_glb_vtx));
	// commit new type
	TRY (h5priv_mpi_type_commit (&h5_dta_types.mpi_glb_vtx));

gsell's avatar
gsell committed
551
	H5_RETURN (H5_SUCCESS);
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
}

static inline h5_err_t
create_mpi_type_edge_list_elem (
        void
        ) {
	h5t_edge_list_elem_t elem;
	H5_PRIV_FUNC_ENTER (h5_err_t, "%s", "void");
	int i = 0;
	const int count = 4;
	int blocklens[count];
	MPI_Aint indices[count];
	MPI_Datatype old_types[count];
	MPI_Aint base;
	MPI_Aint addr;
	TRY (mpi_get_address (&elem, &base));

	// vtx1
	blocklens[i] = 1;
	TRY (mpi_get_address (&elem.vtx1, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_LONG_LONG;

	// vtx2
	blocklens[i] = 1;
	TRY (mpi_get_address (&elem.vtx2, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_LONG_LONG;

	// new_vtx
	blocklens[i] = 1;
	TRY (mpi_get_address (&elem.new_vtx, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_LONG_LONG;

	// proc
	blocklens[i] = 1;
	TRY (mpi_get_address (&elem.proc, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_INT;

	// create new type
	assert (i==count);
	TRY (mpi_create_type_struct (count, blocklens, indices, old_types,
	                             &h5_dta_types.mpi_edge_list_elem));
	// commit new type
	TRY (h5priv_mpi_type_commit (&h5_dta_types.mpi_edge_list_elem));

gsell's avatar
gsell committed
600
	H5_RETURN (H5_SUCCESS);
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
}
static inline h5_err_t
create_mpi_type_chunk (
        void
        ) {
	h5t_chunk_t chunk;
	H5_PRIV_FUNC_ENTER (h5_err_t, "%s", "void");
	int i = 0;
	const int count = 5;
	int blocklens[count];
	MPI_Aint indices[count];
	MPI_Datatype old_types[count];
	MPI_Aint base;
	MPI_Aint addr;
	TRY (mpi_get_address (&chunk, &base));

	// idx
	blocklens[i] = 1;
	TRY (mpi_get_address (&chunk.idx, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_INT;

	// oct_idx
	blocklens[i] = 1;
	TRY (mpi_get_address (&chunk.oct_idx, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_INT;

	// elem_idx
	blocklens[i] = 1;
	TRY (mpi_get_address (&chunk.elem, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_LONG_LONG;

	// chk_weight
	blocklens[i] = 1;
	TRY (mpi_get_address (&chunk.weight, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_LONG_LONG;

	// num_elems
	blocklens[i] = 1;
	TRY (mpi_get_address (&chunk.num_elems, &addr));
	indices[i] = addr - base;
	old_types[i++] = MPI_SHORT;


	// create new type
	assert (i == count);
	TRY (mpi_create_type_struct (count, blocklens, indices, old_types,
	                             &h5_dta_types.mpi_chunk));
	// commit new type
	TRY (h5priv_mpi_type_commit (&h5_dta_types.mpi_chunk));

gsell's avatar
gsell committed
655
	H5_RETURN (H5_SUCCESS);
656 657 658 659 660 661 662 663 664 665
}
#endif

h5_err_t
_h5_exit (int status) {
	exit (status);
	return H5_ERR;
}

h5_err_t
gsell's avatar
gsell committed
666
h5priv_initialize (
667 668 669
        void
        ) {
	memset (&h5_call_stack, 0, sizeof (h5_call_stack));
gsell's avatar
gsell committed
670 671
	// must be set here, otherwise next statement will fail!
	h5_initialized = 1;
672 673 674
	H5_CORE_API_ENTER (h5_err_t, "%s", "void");
	ret_value = H5_SUCCESS;
#ifdef PARALLEL_IO
gsell's avatar
gsell committed
675 676 677 678 679
	int mpi_is_initialized;
	MPI_Initialized (&mpi_is_initialized);
	if (!mpi_is_initialized) {
		MPI_Init (NULL, NULL);
	}
680 681 682 683
	if (h5priv_mpi_comm_rank (MPI_COMM_WORLD, &h5_myproc) < 0) {
		exit (42);
	}
#endif
684 685 686 687
	h5_dta_types.h5_glb_idx_t = H5_INT64;
	h5_dta_types.h5_int64_t = H5_INT64;
	h5_dta_types.h5_float64_t = H5_FLOAT64;
	h5_dta_types.h5_int32_t = H5_INT32;
688 689 690 691 692 693

	TRY (create_array_types ());
	TRY (create_vertex_type ());
	TRY (create_triangle_type ());
	TRY (create_tet_type ());
	TRY (create_tag_types ());
gsell's avatar
gsell committed
694 695

#if defined(WITH_PARALLEL_H5GRID)
696 697 698 699 700 701 702 703 704 705
	TRY (create_chunk_type ());
	TRY (create_octree_type ());
	TRY (create_userdata_type ());

	TRY (create_mpi_type_glb_tri ());
	TRY (create_mpi_type_glb_tet ());
	TRY (create_mpi_type_glb_vtx ());
	TRY (create_mpi_type_chunk ());
	TRY (create_mpi_type_edge_list_elem());
#endif
gsell's avatar
gsell committed
706
	H5_RETURN ((ret_value != H5_SUCCESS) ? _h5_exit (42) : H5_SUCCESS);
707
}