1 
2 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3  * Copyright by The HDF Group.                                               *
4  * Copyright by the Board of Trustees of the University of Illinois.         *
5  * All rights reserved.                                                      *
6  *                                                                           *
7  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
8  * terms governing use, modification, and redistribution, is contained in    *
9  * the COPYING file, which can be found at the root of the source code       *
10  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
11  * If you do not have access to either file, you may request a copy from     *
12  * help@hdfgroup.org.                                                        *
13  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
14 
15 /*
16    This program will test irregular hyperslab selections with collective write and read.
17    The way to test whether collective write and read works is to use independent IO
18    output to verify the collective output.
19 
20    1) We will write two datasets with the same hyperslab selection settings;
21    one in independent mode,
22    one in collective mode,
23    2) We will read two datasets with the same hyperslab selection settings,
24       1.  independent read to read independent output,
25           independent read to read collecive   output,
26 	  Compare the result,
27 	  If the result is the same, then collective write succeeds.
28       2.  collective read to read independent output,
29           independent read to read independent output,
30 	  Compare the result,
31 	  If the result is the same, then collective read succeeds.
32 
33  */
34 
35 #include "hdf5.h"
36 #include "H5private.h"
37 #include "testphdf5.h"
38 
39 
40 static void coll_write_test(int chunk_factor);
41 static void coll_read_test(int chunk_factor);
42 
43 
44 /*-------------------------------------------------------------------------
45  * Function:	coll_irregular_cont_write
46  *
47  * Purpose:	Wrapper to test the collectively irregular hyperslab write in
48                 contiguous storage
49  *
50  * Return:	Success:	0
51  *
52  *		Failure:	-1
53  *
54  * Programmer:	Unknown
55  *		Dec 2nd, 2004
56  *
57  * Modifications:
58  *
59  *-------------------------------------------------------------------------
60  */
61 void
coll_irregular_cont_write(void)62 coll_irregular_cont_write(void)
63 {
64 
65   coll_write_test(0);
66 
67 }
68 
69 
70 
71 /*-------------------------------------------------------------------------
72  * Function:	coll_irregular_cont_read
73  *
74  * Purpose:	Wrapper to test the collectively irregular hyperslab read in
75                 contiguous storage
76  *
77  * Return:	Success:	0
78  *
79  *		Failure:	-1
80  *
81  * Programmer:	Unknown
82  *		Dec 2nd, 2004
83  *
84  * Modifications:
85  *
86  *-------------------------------------------------------------------------
87  */
88 void
coll_irregular_cont_read(void)89 coll_irregular_cont_read(void)
90 {
91 
92   coll_read_test(0);
93 
94 }
95 
96 
97 /*-------------------------------------------------------------------------
98  * Function:	coll_irregular_simple_chunk_write
99  *
100  * Purpose:	Wrapper to test the collectively irregular hyperslab write in
101                 chunk storage(1 chunk)
102  *
103  * Return:	Success:	0
104  *
105  *		Failure:	-1
106  *
107  * Programmer:	Unknown
108  *		Dec 2nd, 2004
109  *
110  * Modifications:
111  *
112  *-------------------------------------------------------------------------
113  */
114 void
coll_irregular_simple_chunk_write(void)115 coll_irregular_simple_chunk_write(void)
116 {
117 
118   coll_write_test(1);
119 
120 }
121 
122 
123 
124 /*-------------------------------------------------------------------------
125  * Function:	coll_irregular_simple_chunk_read
126  *
127  * Purpose:	Wrapper to test the collectively irregular hyperslab read in chunk
128                 storage(1 chunk)
129  *
130  * Return:	Success:	0
131  *
132  *		Failure:	-1
133  *
134  * Programmer:	Unknown
135  *		Dec 2nd, 2004
136  *
137  * Modifications:
138  *
139  *-------------------------------------------------------------------------
140  */
141 void
coll_irregular_simple_chunk_read(void)142 coll_irregular_simple_chunk_read(void)
143 {
144 
145   coll_read_test(1);
146 
147 }
148 
149 /*-------------------------------------------------------------------------
150  * Function:	coll_irregular_complex_chunk_write
151  *
152  * Purpose:	Wrapper to test the collectively irregular hyperslab write in chunk
153                 storage(4 chunks)
154  *
155  * Return:	Success:	0
156  *
157  *		Failure:	-1
158  *
159  * Programmer:	Unknown
160  *		Dec 2nd, 2004
161  *
162  * Modifications:
163  *
164  *-------------------------------------------------------------------------
165  */
166 void
coll_irregular_complex_chunk_write(void)167 coll_irregular_complex_chunk_write(void)
168 {
169 
170   coll_write_test(4);
171 
172 }
173 
174 
175 
176 /*-------------------------------------------------------------------------
177  * Function:	coll_irregular_complex_chunk_read
178  *
179  * Purpose:	Wrapper to test the collectively irregular hyperslab read in chunk
180                 storage(1 chunk)
181  *
182  * Return:	Success:	0
183  *
184  *		Failure:	-1
185  *
186  * Programmer:	Unknown
187  *		Dec 2nd, 2004
188  *
189  * Modifications:
190  *
191  *-------------------------------------------------------------------------
192  */
193 void
coll_irregular_complex_chunk_read(void)194 coll_irregular_complex_chunk_read(void)
195 {
196 
197   coll_read_test(4);
198 
199 }
200 
201 
202 /*-------------------------------------------------------------------------
203  * Function:	coll_write_test
204  *
205  * Purpose:	To test the collectively irregular hyperslab write in chunk
206                 storage
207  *  Input:      number of chunks on each dimension
208                 if number is equal to 0, contiguous storage
209  * Return:	Success:	0
210  *
211  *		Failure:	-1
212  *
213  * Programmer:	Unknown
214  *		Dec 2nd, 2004
215  *
216  * Modifications: Oct 18th, 2005
217  *
218  *-------------------------------------------------------------------------
219  */
coll_write_test(int chunk_factor)220 void coll_write_test(int chunk_factor)
221 {
222 
223   const    char *filename;
224   hid_t    facc_plist,dxfer_plist,dcrt_plist;
225   hid_t    file, datasetc,dataseti;      /* File and dataset identifiers */
226   hid_t    mspaceid1, mspaceid, fspaceid,fspaceid1; /* Dataspace identifiers */
227 
228   hsize_t mdim1[1],fsdim[2],mdim[2];
229 
230 #if 0
231   hsize_t  mdim1[] = {MSPACE1_DIM};  /* Dimension size of the first dataset
232 				      (in memory) */
233   hsize_t  fsdim[] = {FSPACE_DIM1, FSPACE_DIM2}; /* Dimension sizes of the dataset
234                                                     (on disk) */
235 
236   hsize_t  mdim[] = {MSPACE_DIM1, MSPACE_DIM2}; /* Dimension sizes of the
237 						  dataset in memory when we
238 						  read selection from the
239 						  dataset on the disk */
240 #endif
241 
242   hsize_t  start[2];  /* Start of hyperslab */
243   hsize_t  stride[2]; /* Stride of hyperslab */
244   hsize_t  count[2];  /* Block count */
245   hsize_t  block[2];  /* Block sizes */
246   hsize_t  chunk_dims[2];
247 
248   herr_t   ret;
249   unsigned i;
250   int      fillvalue = 0;   /* Fill value for the dataset */
251 
252 #if 0
253   int      matrix_out[MSPACE_DIM1][MSPACE_DIM2];
254   int      matrix_out1[MSPACE_DIM1][MSPACE_DIM2];   /* Buffer to read from the
255 						       dataset */
256   int      vector[MSPACE1_DIM];
257 #endif
258 
259 
260   int      *matrix_out, *matrix_out1, *vector;
261 
262   int      mpi_size,mpi_rank;
263 
264   MPI_Comm comm = MPI_COMM_WORLD;
265   MPI_Info info = MPI_INFO_NULL;
266 
267   /*set up MPI parameters */
268   MPI_Comm_size(comm,&mpi_size);
269   MPI_Comm_rank(comm,&mpi_rank);
270 
271   /* Obtain file name */
272   filename = GetTestParameters();
273 
274   /*
275    * Buffers' initialization.
276    */
277 
278   mdim1[0] = MSPACE1_DIM *mpi_size;
279   mdim[0]  = MSPACE_DIM1;
280   mdim[1]  = MSPACE_DIM2*mpi_size;
281   fsdim[0] = FSPACE_DIM1;
282   fsdim[1] = FSPACE_DIM2*mpi_size;
283 
284   vector = (int*)HDmalloc(sizeof(int)*mdim1[0]*mpi_size);
285   matrix_out  = (int*)HDmalloc(sizeof(int)*mdim[0]*mdim[1]*mpi_size);
286   matrix_out1 = (int*)HDmalloc(sizeof(int)*mdim[0]*mdim[1]*mpi_size);
287 
288   HDmemset(vector,0,sizeof(int)*mdim1[0]*mpi_size);
289   vector[0] = vector[MSPACE1_DIM*mpi_size - 1] = -1;
290   for (i = 1; i < MSPACE1_DIM*mpi_size - 1; i++) vector[i] = i;
291 
292   /* Grab file access property list */
293   facc_plist = create_faccess_plist(comm, info, facc_type);
294   VRFY((facc_plist >= 0),"");
295 
296   /*
297    * Create a file.
298    */
299   file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, facc_plist);
300   VRFY((file >= 0),"H5Fcreate succeeded");
301 
302   /*
303    * Create property list for a dataset and set up fill values.
304    */
305   dcrt_plist = H5Pcreate(H5P_DATASET_CREATE);
306   VRFY((dcrt_plist >= 0),"");
307 
308   ret   = H5Pset_fill_value(dcrt_plist, H5T_NATIVE_INT, &fillvalue);
309   VRFY((ret >= 0),"Fill value creation property list succeeded");
310 
311   if(chunk_factor != 0) {
312     chunk_dims[0] = fsdim[0] / chunk_factor;
313     chunk_dims[1] = fsdim[1] / chunk_factor;
314     ret = H5Pset_chunk(dcrt_plist, 2, chunk_dims);
315     VRFY((ret >= 0),"chunk creation property list succeeded");
316   }
317 
318   /*
319    *
320    * Create dataspace for the first dataset in the disk.
321    * dim1 = 9
322    * dim2 = 3600
323    *
324    *
325    */
326   fspaceid = H5Screate_simple(FSPACE_RANK, fsdim, NULL);
327   VRFY((fspaceid >= 0),"file dataspace created succeeded");
328 
329   /*
330    * Create dataset in the file. Notice that creation
331    * property list dcrt_plist is used.
332    */
333   datasetc = H5Dcreate2(file, "collect_write", H5T_NATIVE_INT, fspaceid, H5P_DEFAULT, dcrt_plist, H5P_DEFAULT);
334   VRFY((datasetc >= 0),"dataset created succeeded");
335 
336   dataseti = H5Dcreate2(file, "independ_write", H5T_NATIVE_INT, fspaceid, H5P_DEFAULT, dcrt_plist, H5P_DEFAULT);
337   VRFY((dataseti >= 0),"dataset created succeeded");
338 
339   /* The First selection for FILE
340    *
341    *  block (3,2)
342    *  stride(4,3)
343    *  count (1,768/mpi_size)
344    *  start (0,1+768*3*mpi_rank/mpi_size)
345    *
346    */
347 
348   start[0]  = FHSTART0;
349   start[1]  = FHSTART1 + mpi_rank * FHSTRIDE1 * FHCOUNT1;
350   stride[0] = FHSTRIDE0;
351   stride[1] = FHSTRIDE1;
352   count[0]  = FHCOUNT0;
353   count[1]  = FHCOUNT1;
354   block[0]  = FHBLOCK0;
355   block[1]  = FHBLOCK1;
356 
357   ret = H5Sselect_hyperslab(fspaceid, H5S_SELECT_SET, start, stride, count, block);
358   VRFY((ret >= 0),"hyperslab selection succeeded");
359 
360   /* The Second selection for FILE
361    *
362    *  block  (3,768)
363    *  stride (1,1)
364    *  count  (1,1)
365    *  start  (4,768*mpi_rank/mpi_size)
366    *
367    */
368 
369   start[0]  = SHSTART0;
370   start[1]  = SHSTART1+SHCOUNT1*SHBLOCK1*mpi_rank;
371   stride[0] = SHSTRIDE0;
372   stride[1] = SHSTRIDE1;
373   count[0]  = SHCOUNT0;
374   count[1]  = SHCOUNT1;
375   block[0]  = SHBLOCK0;
376   block[1]  = SHBLOCK1;
377 
378   ret = H5Sselect_hyperslab(fspaceid, H5S_SELECT_OR, start, stride, count, block);
379   VRFY((ret >= 0),"hyperslab selection succeeded");
380 
381   /*
382    * Create dataspace for the first dataset in the memory
383    * dim1 = 27000
384    *
385    */
386   mspaceid1 = H5Screate_simple(MSPACE1_RANK, mdim1, NULL);
387   VRFY((mspaceid1 >= 0),"memory dataspace created succeeded");
388 
389   /*
390    * Memory space is 1-D, this is a good test to check
391    * whether a span-tree derived datatype needs to be built.
392    * block  1
393    * stride 1
394    * count  6912/mpi_size
395    * start  1
396    *
397    */
398   start[0]  = MHSTART0;
399   stride[0] = MHSTRIDE0;
400   count[0]  = MHCOUNT0;
401   block[0]  = MHBLOCK0;
402 
403   ret = H5Sselect_hyperslab(mspaceid1, H5S_SELECT_SET, start, stride, count, block);
404   VRFY((ret >= 0),"hyperslab selection succeeded");
405 
406   /* independent write */
407   ret = H5Dwrite(dataseti, H5T_NATIVE_INT, mspaceid1, fspaceid, H5P_DEFAULT, vector);
408   VRFY((ret >= 0),"dataset independent write succeed");
409 
410   dxfer_plist = H5Pcreate(H5P_DATASET_XFER);
411   VRFY((dxfer_plist >= 0),"");
412 
413   ret = H5Pset_dxpl_mpio(dxfer_plist, H5FD_MPIO_COLLECTIVE);
414   VRFY((ret >= 0),"MPIO data transfer property list succeed");
415   if(dxfer_coll_type == DXFER_INDEPENDENT_IO) {
416      ret = H5Pset_dxpl_mpio_collective_opt(dxfer_plist,H5FD_MPIO_INDIVIDUAL_IO);
417      VRFY((ret>= 0),"set independent IO collectively succeeded");
418   }
419 
420 
421   /* collective write */
422   ret = H5Dwrite(datasetc, H5T_NATIVE_INT, mspaceid1, fspaceid, dxfer_plist, vector);
423   VRFY((ret >= 0),"dataset collective write succeed");
424 
425   ret = H5Sclose(mspaceid1);
426   VRFY((ret >= 0),"");
427 
428   ret = H5Sclose(fspaceid);
429   VRFY((ret >= 0),"");
430 
431   /*
432    * Close dataset.
433    */
434   ret = H5Dclose(datasetc);
435   VRFY((ret >= 0),"");
436 
437   ret = H5Dclose(dataseti);
438   VRFY((ret >= 0),"");
439 
440   /*
441    * Close the file.
442    */
443   ret = H5Fclose(file);
444   VRFY((ret >= 0),"");
445   /*
446    * Close property list
447    */
448 
449   ret = H5Pclose(facc_plist);
450   VRFY((ret >= 0),"");
451   ret = H5Pclose(dxfer_plist);
452   VRFY((ret >= 0),"");
453   ret = H5Pclose(dcrt_plist);
454   VRFY((ret >= 0),"");
455 
456   /*
457    * Open the file.
458    */
459 
460   /***
461 
462        For testing collective hyperslab selection write
463        In this test, we are using independent read to check
464        the correctedness of collective write compared with
465        independent write,
466 
467        In order to throughly test this feature, we choose
468        a different selection set for reading the data out.
469 
470 
471   ***/
472 
473   /* Obtain file access property list with MPI-IO driver */
474   facc_plist = create_faccess_plist(comm, info, facc_type);
475   VRFY((facc_plist >= 0),"");
476 
477   file = H5Fopen(filename, H5F_ACC_RDONLY, facc_plist);
478   VRFY((file >= 0),"H5Fopen succeeded");
479 
480   /*
481    * Open the dataset.
482    */
483   datasetc = H5Dopen2(file,"collect_write", H5P_DEFAULT);
484   VRFY((datasetc >= 0),"H5Dopen2 succeeded");
485 
486   dataseti = H5Dopen2(file,"independ_write", H5P_DEFAULT);
487   VRFY((dataseti >= 0),"H5Dopen2 succeeded");
488 
489   /*
490    * Get dataspace of the open dataset.
491    */
492   fspaceid  = H5Dget_space(datasetc);
493   VRFY((fspaceid >= 0),"file dataspace obtained succeeded");
494 
495   fspaceid1 = H5Dget_space(dataseti);
496   VRFY((fspaceid1 >= 0),"file dataspace obtained succeeded");
497 
498 
499   /* The First selection for FILE to read
500    *
501    *  block (1,1)
502    *  stride(1.1)
503    *  count (3,768/mpi_size)
504    *  start (1,2+768*mpi_rank/mpi_size)
505    *
506    */
507   start[0]  = RFFHSTART0;
508   start[1]  = RFFHSTART1+mpi_rank*RFFHCOUNT1;
509   block[0]  = RFFHBLOCK0;
510   block[1]  = RFFHBLOCK1;
511   stride[0] = RFFHSTRIDE0;
512   stride[1] = RFFHSTRIDE1;
513   count[0]  = RFFHCOUNT0;
514   count[1]  = RFFHCOUNT1;
515 
516 
517   /* The first selection of the dataset generated by collective write */
518   ret = H5Sselect_hyperslab(fspaceid, H5S_SELECT_SET, start, stride, count, block);
519   VRFY((ret >= 0),"hyperslab selection succeeded");
520 
521   /* The first selection of the dataset generated by independent write */
522   ret = H5Sselect_hyperslab(fspaceid1, H5S_SELECT_SET, start, stride, count, block);
523   VRFY((ret >= 0),"hyperslab selection succeeded");
524 
525   /* The Second selection for FILE to read
526    *
527    *  block (1,1)
528    *  stride(1.1)
529    *  count (3,1536/mpi_size)
530    *  start (2,4+1536*mpi_rank/mpi_size)
531    *
532    */
533 
534   start[0] = RFSHSTART0;
535   start[1] = RFSHSTART1+RFSHCOUNT1*mpi_rank;
536   block[0] = RFSHBLOCK0;
537   block[1] = RFSHBLOCK1;
538   stride[0] = RFSHSTRIDE0;
539   stride[1] = RFSHSTRIDE0;
540   count[0]  = RFSHCOUNT0;
541   count[1]  = RFSHCOUNT1;
542 
543   /* The second selection of the dataset generated by collective write */
544   ret = H5Sselect_hyperslab(fspaceid, H5S_SELECT_OR, start, stride, count, block);
545   VRFY((ret >= 0),"hyperslab selection succeeded");
546 
547   /* The second selection of the dataset generated by independent write */
548   ret = H5Sselect_hyperslab(fspaceid1, H5S_SELECT_OR, start, stride, count, block);
549   VRFY((ret >= 0),"hyperslab selection succeeded");
550 
551   /*
552    * Create memory dataspace.
553    * rank  = 2
554    * mdim1 = 9
555    * mdim2 = 3600
556    *
557    */
558   mspaceid = H5Screate_simple(MSPACE_RANK, mdim, NULL);
559 
560   /*
561    * Select two hyperslabs in memory. Hyperslabs has the same
562    * size and shape as the selected hyperslabs for the file dataspace
563    * Only the starting point is different.
564    * The first selection
565    *  block (1,1)
566    *  stride(1.1)
567    *  count (3,768/mpi_size)
568    *  start (0,768*mpi_rank/mpi_size)
569    *
570    */
571 
572 
573   start[0]  = RMFHSTART0;
574   start[1]  = RMFHSTART1+mpi_rank*RMFHCOUNT1;
575   block[0]  = RMFHBLOCK0;
576   block[1]  = RMFHBLOCK1;
577   stride[0] = RMFHSTRIDE0;
578   stride[1] = RMFHSTRIDE1;
579   count[0]  = RMFHCOUNT0;
580   count[1]  = RMFHCOUNT1;
581 
582   ret = H5Sselect_hyperslab(mspaceid, H5S_SELECT_SET, start, stride, count, block);
583   VRFY((ret >= 0),"hyperslab selection succeeded");
584 
585   /*
586    * Select two hyperslabs in memory. Hyperslabs has the same
587    * size and shape as the selected hyperslabs for the file dataspace
588    * Only the starting point is different.
589    * The second selection
590    *  block (1,1)
591    *  stride(1,1)
592    *  count (3,1536/mpi_size)
593    *  start (1,2+1536*mpi_rank/mpi_size)
594    *
595    */
596   start[0]  = RMSHSTART0;
597   start[1]  = RMSHSTART1+mpi_rank*RMSHCOUNT1;
598   block[0]  = RMSHBLOCK0;
599   block[1]  = RMSHBLOCK1;
600   stride[0] = RMSHSTRIDE0;
601   stride[1] = RMSHSTRIDE1;
602   count[0]  = RMSHCOUNT0;
603   count[1]  = RMSHCOUNT1;
604 
605   ret = H5Sselect_hyperslab(mspaceid, H5S_SELECT_OR, start, stride, count, block);
606   VRFY((ret >= 0),"hyperslab selection succeeded");
607 
608   /*
609    * Initialize data buffer.
610    */
611 
612   HDmemset(matrix_out,0,sizeof(int)*MSPACE_DIM1*MSPACE_DIM2*mpi_size);
613   HDmemset(matrix_out1,0,sizeof(int)*MSPACE_DIM1*MSPACE_DIM2*mpi_size);
614   /*
615    * Read data back to the buffer matrix_out.
616    */
617 
618   ret = H5Dread(datasetc, H5T_NATIVE_INT, mspaceid, fspaceid,
619 		H5P_DEFAULT, matrix_out);
620   VRFY((ret >= 0),"H5D independent read succeed");
621 
622 
623   ret = H5Dread(dataseti, H5T_NATIVE_INT, mspaceid, fspaceid,
624 		H5P_DEFAULT, matrix_out1);
625   VRFY((ret >= 0),"H5D independent read succeed");
626 
627   ret = 0;
628 
629   for (i = 0; i < MSPACE_DIM1*MSPACE_DIM2*mpi_size; i++){
630          if(matrix_out[i]!=matrix_out1[i]) ret = -1;
631       if(ret < 0) break;
632     }
633 
634   VRFY((ret >= 0),"H5D irregular collective write succeed");
635 
636   /*
637    * Close memory file and memory dataspaces.
638    */
639   ret = H5Sclose(mspaceid);
640   VRFY((ret >= 0),"");
641   ret = H5Sclose(fspaceid);
642   VRFY((ret >= 0),"");
643 
644   /*
645    * Close dataset.
646    */
647   ret = H5Dclose(dataseti);
648   VRFY((ret >= 0),"");
649 
650   ret = H5Dclose(datasetc);
651   VRFY((ret >= 0),"");
652 
653   /*
654    * Close property list
655    */
656 
657   ret = H5Pclose(facc_plist);
658   VRFY((ret >= 0),"");
659 
660 
661   /*
662    * Close the file.
663    */
664   ret = H5Fclose(file);
665   VRFY((ret >= 0),"");
666 
667   return ;
668 }
669 
670 /*-------------------------------------------------------------------------
671  * Function:	coll_read_test
672  *
673  * Purpose:	To test the collectively irregular hyperslab read in chunk
674                 storage
675  * Input:       number of chunks on each dimension
676                 if number is equal to 0, contiguous storage
677  * Return:	Success:	0
678  *
679  *		Failure:	-1
680  *
681  * Programmer:	Unknown
682  *		Dec 2nd, 2004
683  *
684  * Modifications: Oct 18th, 2005
685  * Note:        This test must be used with the correpsonding
686                 coll_write_test.
687  *-------------------------------------------------------------------------
688  */
689 static void
coll_read_test(int chunk_factor)690 coll_read_test(int chunk_factor)
691 {
692 
693   const   char *filename;
694   hid_t   facc_plist,dxfer_plist;
695   hid_t   file, dataseti;           /* File and dataset identifiers */
696   hid_t   mspaceid, fspaceid1;      /* Dataspace identifiers */
697 
698 
699   /* Dimension sizes of the dataset (on disk) */
700 #if 0
701   hsize_t mdim[] = {MSPACE_DIM1, MSPACE_DIM2}; /* Dimension sizes of the
702 						  dataset in memory when we
703 						  read selection from the
704 						  dataset on the disk */
705 
706 #endif
707   hsize_t mdim[2];
708   hsize_t  start[2];  /* Start of hyperslab */
709   hsize_t  stride[2]; /* Stride of hyperslab */
710   hsize_t  count[2];  /* Block count */
711   hsize_t  block[2];  /* Block sizes */
712   herr_t   ret;
713 
714   unsigned i;
715 
716   int     *matrix_out;
717   int     *matrix_out1;
718 #if 0
719   int      matrix_out[MSPACE_DIM1][MSPACE_DIM2];
720   int      matrix_out1[MSPACE_DIM1][MSPACE_DIM2];   /* Buffer to read from the
721 						       dataset */
722 
723 #endif
724   int      mpi_size,mpi_rank;
725 
726   MPI_Comm comm = MPI_COMM_WORLD;
727   MPI_Info info = MPI_INFO_NULL;
728 
729   /*set up MPI parameters */
730   MPI_Comm_size(comm,&mpi_size);
731   MPI_Comm_rank(comm,&mpi_rank);
732 
733 
734   /* Obtain file name */
735   filename = GetTestParameters();
736 
737 
738   /* Initialize the buffer */
739 
740   mdim[0] = MSPACE_DIM1;
741   mdim[1] = MSPACE_DIM2*mpi_size;
742   matrix_out =(int*)HDmalloc(sizeof(int)*MSPACE_DIM1*MSPACE_DIM2*mpi_size);
743   matrix_out1=(int*)HDmalloc(sizeof(int)*MSPACE_DIM1*MSPACE_DIM2*mpi_size);
744 
745   /*** For testing collective hyperslab selection read ***/
746 
747   /* Obtain file access property list */
748   facc_plist = create_faccess_plist(comm, info, facc_type);
749   VRFY((facc_plist >= 0),"");
750 
751    /*
752    * Open the file.
753    */
754   file = H5Fopen(filename, H5F_ACC_RDONLY, facc_plist);
755   VRFY((file >= 0),"H5Fopen succeeded");
756 
757   /*
758    * Open the dataset.
759    */
760   dataseti = H5Dopen2(file,"independ_write", H5P_DEFAULT);
761   VRFY((dataseti >= 0),"H5Dopen2 succeeded");
762 
763   /*
764    * Get dataspace of the open dataset.
765    */
766   fspaceid1 = H5Dget_space(dataseti);
767   VRFY((fspaceid1 >= 0),"file dataspace obtained succeeded");
768 
769   /* The First selection for FILE to read
770    *
771    *  block (1,1)
772    *  stride(1.1)
773    *  count (3,768/mpi_size)
774    *  start (1,2+768*mpi_rank/mpi_size)
775    *
776    */
777   start[0]  = RFFHSTART0;
778   start[1]  = RFFHSTART1+mpi_rank*RFFHCOUNT1;
779   block[0]  = RFFHBLOCK0;
780   block[1]  = RFFHBLOCK1;
781   stride[0] = RFFHSTRIDE0;
782   stride[1] = RFFHSTRIDE1;
783   count[0]  = RFFHCOUNT0;
784   count[1]  = RFFHCOUNT1;
785 
786   ret = H5Sselect_hyperslab(fspaceid1, H5S_SELECT_SET, start, stride, count, block);
787   VRFY((ret >= 0),"hyperslab selection succeeded");
788 
789   /* The Second selection for FILE to read
790    *
791    *  block (1,1)
792    *  stride(1.1)
793    *  count (3,1536/mpi_size)
794    *  start (2,4+1536*mpi_rank/mpi_size)
795    *
796    */
797   start[0]  = RFSHSTART0;
798   start[1]  = RFSHSTART1+RFSHCOUNT1*mpi_rank;
799   block[0]  = RFSHBLOCK0;
800   block[1]  = RFSHBLOCK1;
801   stride[0] = RFSHSTRIDE0;
802   stride[1] = RFSHSTRIDE0;
803   count[0]  = RFSHCOUNT0;
804   count[1]  = RFSHCOUNT1;
805 
806   ret = H5Sselect_hyperslab(fspaceid1, H5S_SELECT_OR, start, stride, count, block);
807   VRFY((ret >= 0),"hyperslab selection succeeded");
808 
809 
810   /*
811    * Create memory dataspace.
812    */
813   mspaceid = H5Screate_simple(MSPACE_RANK, mdim, NULL);
814 
815   /*
816    * Select two hyperslabs in memory. Hyperslabs has the same
817    * size and shape as the selected hyperslabs for the file dataspace.
818    * Only the starting point is different.
819    * The first selection
820    *  block (1,1)
821    *  stride(1.1)
822    *  count (3,768/mpi_size)
823    *  start (0,768*mpi_rank/mpi_size)
824    *
825    */
826 
827   start[0]  = RMFHSTART0;
828   start[1]  = RMFHSTART1+mpi_rank*RMFHCOUNT1;
829   block[0]  = RMFHBLOCK0;
830   block[1]  = RMFHBLOCK1;
831   stride[0] = RMFHSTRIDE0;
832   stride[1] = RMFHSTRIDE1;
833   count[0]  = RMFHCOUNT0;
834   count[1]  = RMFHCOUNT1;
835   ret = H5Sselect_hyperslab(mspaceid, H5S_SELECT_SET, start, stride, count, block);
836   VRFY((ret >= 0),"hyperslab selection succeeded");
837 
838   /*
839    * Select two hyperslabs in memory. Hyperslabs has the same
840    * size and shape as the selected hyperslabs for the file dataspace
841    * Only the starting point is different.
842    * The second selection
843    *  block (1,1)
844    *  stride(1,1)
845    *  count (3,1536/mpi_size)
846    *  start (1,2+1536*mpi_rank/mpi_size)
847    *
848    */
849   start[0]  = RMSHSTART0;
850   start[1]  = RMSHSTART1+mpi_rank*RMSHCOUNT1;
851   block[0]  = RMSHBLOCK0;
852   block[1]  = RMSHBLOCK1;
853   stride[0] = RMSHSTRIDE0;
854   stride[1] = RMSHSTRIDE1;
855   count[0]  = RMSHCOUNT0;
856   count[1]  = RMSHCOUNT1;
857   ret = H5Sselect_hyperslab(mspaceid, H5S_SELECT_OR, start, stride, count, block);
858   VRFY((ret >= 0),"hyperslab selection succeeded");
859 
860 
861   /*
862    * Initialize data buffer.
863    */
864 
865   HDmemset(matrix_out,0,sizeof(int)*MSPACE_DIM1*MSPACE_DIM2*mpi_size);
866   HDmemset(matrix_out1,0,sizeof(int)*MSPACE_DIM1*MSPACE_DIM2*mpi_size);
867 
868   /*
869    * Read data back to the buffer matrix_out.
870    */
871 
872   dxfer_plist = H5Pcreate(H5P_DATASET_XFER);
873   VRFY((dxfer_plist >= 0),"");
874 
875   ret = H5Pset_dxpl_mpio(dxfer_plist, H5FD_MPIO_COLLECTIVE);
876   VRFY((ret >= 0),"MPIO data transfer property list succeed");
877   if(dxfer_coll_type == DXFER_INDEPENDENT_IO) {
878      ret = H5Pset_dxpl_mpio_collective_opt(dxfer_plist,H5FD_MPIO_INDIVIDUAL_IO);
879      VRFY((ret>= 0),"set independent IO collectively succeeded");
880   }
881 
882 
883   /* Collective read */
884   ret = H5Dread(dataseti, H5T_NATIVE_INT, mspaceid, fspaceid1,
885 		dxfer_plist, matrix_out);
886   VRFY((ret >= 0),"H5D collecive read succeed");
887 
888   ret = H5Pclose(dxfer_plist);
889   VRFY((ret >= 0),"");
890 
891   /* Independent read */
892   ret = H5Dread(dataseti, H5T_NATIVE_INT, mspaceid, fspaceid1,
893 		H5P_DEFAULT, matrix_out1);
894   VRFY((ret >= 0),"H5D independent read succeed");
895 
896   ret = 0;
897   for (i = 0; i < MSPACE_DIM1*MSPACE_DIM2*mpi_size; i++){
898       if(matrix_out[i]!=matrix_out1[i])ret = -1;
899       if(ret < 0) break;
900   }
901   VRFY((ret >= 0),"H5D contiguous irregular collective read succeed");
902 
903   /*
904    * Close memory file and memory dataspaces.
905    */
906   ret = H5Sclose(mspaceid);
907   VRFY((ret >= 0),"");
908   ret = H5Sclose(fspaceid1);
909   VRFY((ret >= 0),"");
910 
911   /*
912    * Close dataset.
913    */
914   ret = H5Dclose(dataseti);
915   VRFY((ret >= 0),"");
916 
917   /*
918    * Close property list
919    */
920   ret = H5Pclose(facc_plist);
921   VRFY((ret >= 0),"");
922 
923 
924   /*
925    * Close the file.
926    */
927   ret = H5Fclose(file);
928   VRFY((ret >= 0),"");
929 
930   return ;
931 }
932 
933 
934 /****************************************************************
935 **
936 **  lower_dim_size_comp_test__select_checker_board():
937 **
938 **	Given a data space of tgt_rank, and dimensions:
939 **
940 **		(mpi_size + 1), edge_size, ... , edge_size
941 **
942 **	edge_size, and a checker_edge_size, select a checker
943 **	board selection of a sel_rank (sel_rank < tgt_rank)
944 **	dimensional slice through the data space parallel to the
945 **      sel_rank fastest changing indicies, with origin (in the
946 **	higher indicies) as indicated by the start array.
947 **
948 **	Note that this function, is hard coded to presume a
949 **	maximum data space rank of 5.
950 **
951 **	While this maximum is declared as a constant, increasing
952 **	it will require extensive coding in addition to changing
953 **      the value of the constant.
954 **
955 **					JRM -- 11/11/09
956 **
957 ****************************************************************/
958 
959 #define LDSCT_DS_RANK	5
960 #define LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK 0
961 
962 #define LOWER_DIM_SIZE_COMP_TEST__SELECT_CHECKER_BOARD__DEBUG 0
963 
964 static void
lower_dim_size_comp_test__select_checker_board(const int mpi_rank,const hid_t tgt_sid,const int tgt_rank,const hsize_t dims[LDSCT_DS_RANK],const int checker_edge_size,const int sel_rank,hsize_t sel_start[])965 lower_dim_size_comp_test__select_checker_board(
966                                  const int mpi_rank,
967                                  const hid_t tgt_sid,
968                                  const int tgt_rank,
969                                  const hsize_t dims[LDSCT_DS_RANK],
970                                  const int checker_edge_size,
971                                  const int sel_rank,
972                                  hsize_t sel_start[])
973 {
974 #if LOWER_DIM_SIZE_COMP_TEST__SELECT_CHECKER_BOARD__DEBUG
975     const char *	fcnName =
976 			"lower_dim_size_comp_test__select_checker_board():";
977 #endif
978     hbool_t		first_selection = TRUE;
979     int                 i, j, k, l, m;
980     int			ds_offset;
981     int			sel_offset;
982     const int		test_max_rank = LDSCT_DS_RANK;  /* must update code if */
983                                                         /* this changes        */
984     hsize_t		base_count;
985     hsize_t             offset_count;
986     hsize_t     	start[LDSCT_DS_RANK];
987     hsize_t     	stride[LDSCT_DS_RANK];
988     hsize_t     	count[LDSCT_DS_RANK];
989     hsize_t     	block[LDSCT_DS_RANK];
990     herr_t      	ret;            /* Generic return value */
991 
992 #if LOWER_DIM_SIZE_COMP_TEST__SELECT_CHECKER_BOARD__DEBUG
993     if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
994         HDfprintf(stdout,
995                   "%s:%d: dims/checker_edge_size = %d %d %d %d %d / %d\n",
996                   fcnName, mpi_rank, (int)dims[0], (int)dims[1], (int)dims[2],
997                   (int)dims[3], (int)dims[4], checker_edge_size);
998     }
999 #endif /* LOWER_DIM_SIZE_COMP_TEST__SELECT_CHECKER_BOARD__DEBUG */
1000 
1001     HDassert( 0 < checker_edge_size );
1002     HDassert( 0 < sel_rank );
1003     HDassert( sel_rank <= tgt_rank );
1004     HDassert( tgt_rank <= test_max_rank );
1005     HDassert( test_max_rank <= LDSCT_DS_RANK );
1006 
1007     sel_offset = test_max_rank - sel_rank;
1008     HDassert( sel_offset >= 0 );
1009 
1010     ds_offset = test_max_rank - tgt_rank;
1011     HDassert( ds_offset >= 0 );
1012     HDassert( ds_offset <= sel_offset );
1013 
1014     HDassert( (hsize_t)checker_edge_size <= dims[sel_offset] );
1015     HDassert( dims[sel_offset] == 10 );
1016 
1017 #if LOWER_DIM_SIZE_COMP_TEST__SELECT_CHECKER_BOARD__DEBUG
1018     if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
1019         HDfprintf(stdout, "%s:%d: sel_rank/sel_offset = %d/%d.\n",
1020                   fcnName, mpi_rank, sel_rank, sel_offset);
1021         HDfprintf(stdout, "%s:%d: tgt_rank/ds_offset = %d/%d.\n",
1022                   fcnName, mpi_rank, tgt_rank, ds_offset);
1023     }
1024 #endif /* LOWER_DIM_SIZE_COMP_TEST__SELECT_CHECKER_BOARD__DEBUG */
1025 
1026     /* First, compute the base count (which assumes start == 0
1027      * for the associated offset) and offset_count (which
1028      * assumes start == checker_edge_size for the associated
1029      * offset).
1030      *
1031      * Note that the following computation depends on the C99
1032      * requirement that integer division discard any fraction
1033      * (truncation towards zero) to function correctly. As we
1034      * now require C99, this shouldn't be a problem, but noting
1035      * it may save us some pain if we are ever obliged to support
1036      * pre-C99 compilers again.
1037      */
1038 
1039     base_count = dims[sel_offset] / (checker_edge_size * 2);
1040 
1041     if ( (dims[sel_rank] % (checker_edge_size * 2)) > 0 ) {
1042 
1043         base_count++;
1044     }
1045 
1046     offset_count =
1047 	(hsize_t)((dims[sel_offset] - (hsize_t)checker_edge_size) /
1048                   ((hsize_t)(checker_edge_size * 2)));
1049 
1050     if ( ((dims[sel_rank] - (hsize_t)checker_edge_size) %
1051           ((hsize_t)(checker_edge_size * 2))) > 0 ) {
1052 
1053         offset_count++;
1054     }
1055 
1056 #if LOWER_DIM_SIZE_COMP_TEST__SELECT_CHECKER_BOARD__DEBUG
1057     if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
1058         HDfprintf(stdout, "%s:%d: base_count/offset_count = %d/%d.\n",
1059                   fcnName, mpi_rank, base_count, offset_count);
1060     }
1061 #endif /* LOWER_DIM_SIZE_COMP_TEST__SELECT_CHECKER_BOARD__DEBUG */
1062 
1063     /* Now set up the stride and block arrays, and portions of the start
1064      * and count arrays that will not be altered during the selection of
1065      * the checker board.
1066      */
1067     i = 0;
1068     while ( i < ds_offset ) {
1069 
1070         /* these values should never be used */
1071         start[i] = 0;
1072         stride[i] = 0;
1073         count[i] = 0;
1074         block[i] = 0;
1075 
1076         i++;
1077     }
1078 
1079     while ( i < sel_offset ) {
1080 
1081         start[i] = sel_start[i];
1082         stride[i] = 2 * dims[i];
1083         count[i] = 1;
1084         block[i] = 1;
1085 
1086         i++;
1087     }
1088 
1089     while ( i < test_max_rank ) {
1090 
1091         stride[i] = (hsize_t)(2 * checker_edge_size);
1092         block[i] = (hsize_t)checker_edge_size;
1093 
1094         i++;
1095     }
1096 
1097     i = 0;
1098     do {
1099         if ( 0 >= sel_offset ) {
1100 
1101             if ( i == 0 ) {
1102 
1103                 start[0] = 0;
1104                 count[0] = base_count;
1105 
1106             } else {
1107 
1108                 start[0] = (hsize_t)checker_edge_size;
1109                 count[0] = offset_count;
1110 
1111             }
1112         }
1113 
1114         j = 0;
1115         do {
1116             if ( 1 >= sel_offset ) {
1117 
1118                 if ( j == 0 ) {
1119 
1120                     start[1] = 0;
1121                     count[1] = base_count;
1122 
1123                 } else {
1124 
1125                     start[1] = (hsize_t)checker_edge_size;
1126                     count[1] = offset_count;
1127 
1128                 }
1129             }
1130 
1131             k = 0;
1132             do {
1133                 if ( 2 >= sel_offset ) {
1134 
1135                     if ( k == 0 ) {
1136 
1137                         start[2] = 0;
1138                         count[2] = base_count;
1139 
1140                     } else {
1141 
1142                         start[2] = (hsize_t)checker_edge_size;
1143                         count[2] = offset_count;
1144 
1145                     }
1146                 }
1147 
1148                 l = 0;
1149                 do {
1150                     if ( 3 >= sel_offset ) {
1151 
1152                         if ( l == 0 ) {
1153 
1154                             start[3] = 0;
1155                             count[3] = base_count;
1156 
1157                         } else {
1158 
1159                             start[3] = (hsize_t)checker_edge_size;
1160                             count[3] = offset_count;
1161 
1162                         }
1163                     }
1164 
1165                     m = 0;
1166                     do {
1167                         if ( 4 >= sel_offset ) {
1168 
1169                             if ( m == 0 ) {
1170 
1171                                 start[4] = 0;
1172                                 count[4] = base_count;
1173 
1174                             } else {
1175 
1176                                 start[4] = (hsize_t)checker_edge_size;
1177                                 count[4] = offset_count;
1178 
1179                             }
1180                         }
1181 
1182                         if ( ((i + j + k + l + m) % 2) == 0 ) {
1183 
1184 #if LOWER_DIM_SIZE_COMP_TEST__SELECT_CHECKER_BOARD__DEBUG
1185                              if ( mpi_rank ==
1186                                   LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
1187 
1188                                 HDfprintf(stdout,
1189                                       "%s%d: *** first_selection = %d ***\n",
1190                                       fcnName, mpi_rank, (int)first_selection);
1191                                 HDfprintf(stdout,
1192                                       "%s:%d: i/j/k/l/m = %d/%d/%d/%d/%d\n",
1193                                       fcnName, mpi_rank, i, j, k, l, m);
1194                                 HDfprintf(stdout,
1195                                       "%s:%d: start = %d %d %d %d %d.\n",
1196                                       fcnName, mpi_rank,
1197                                       (int)start[0], (int)start[1],
1198                                       (int)start[2], (int)start[3],
1199                                       (int)start[4]);
1200                                 HDfprintf(stdout,
1201                                       "%s:%d: stride = %d %d %d %d %d.\n",
1202                                       fcnName, mpi_rank,
1203                                       (int)stride[0], (int)stride[1],
1204                                       (int)stride[2], (int)stride[3],
1205                                       (int)stride[4]);
1206                                 HDfprintf(stdout,
1207                                       "%s:%d: count = %d %d %d %d %d.\n",
1208                                       fcnName, mpi_rank,
1209                                       (int)count[0], (int)count[1],
1210                                       (int)count[2], (int)count[3],
1211                                       (int)count[4]);
1212                                 HDfprintf(stdout,
1213                                       "%s:%d: block = %d %d %d %d %d.\n",
1214                                       fcnName, mpi_rank,
1215                                       (int)block[0], (int)block[1],
1216                                       (int)block[2], (int)block[3],
1217                                       (int)block[4]);
1218                                 HDfprintf(stdout,
1219                                       "%s:%d: n-cube extent dims = %d.\n",
1220                                       fcnName, mpi_rank,
1221                                       H5Sget_simple_extent_ndims(tgt_sid));
1222                                 HDfprintf(stdout,
1223                                       "%s:%d: selection rank = %d.\n",
1224                                       fcnName, mpi_rank, sel_rank);
1225                             }
1226 #endif
1227 
1228                             if ( first_selection ) {
1229 
1230                                 first_selection = FALSE;
1231 
1232                                 ret = H5Sselect_hyperslab
1233                                       (
1234                                         tgt_sid,
1235                                         H5S_SELECT_SET,
1236                                         &(start[ds_offset]),
1237                                         &(stride[ds_offset]),
1238                                         &(count[ds_offset]),
1239                                         &(block[ds_offset])
1240                                       );
1241 
1242                                 VRFY((ret != FAIL), "H5Sselect_hyperslab(SET) succeeded");
1243 
1244                             } else {
1245 
1246                                 ret = H5Sselect_hyperslab
1247                                       (
1248                                         tgt_sid,
1249                                         H5S_SELECT_OR,
1250                                         &(start[ds_offset]),
1251                                         &(stride[ds_offset]),
1252                                         &(count[ds_offset]),
1253                                         &(block[ds_offset])
1254                                       );
1255 
1256                                 VRFY((ret != FAIL), "H5Sselect_hyperslab(OR) succeeded");
1257 
1258                             }
1259                         }
1260 
1261                         m++;
1262 
1263                     } while ( ( m <= 1 ) &&
1264                               ( 4 >= sel_offset ) );
1265 
1266                     l++;
1267 
1268                 } while ( ( l <= 1 ) &&
1269                           ( 3 >= sel_offset ) );
1270 
1271                 k++;
1272 
1273             } while ( ( k <= 1 ) &&
1274                       ( 2 >= sel_offset ) );
1275 
1276             j++;
1277 
1278         } while ( ( j <= 1 ) &&
1279                   ( 1 >= sel_offset ) );
1280 
1281 
1282         i++;
1283 
1284     } while ( ( i <= 1 ) &&
1285               ( 0 >= sel_offset ) );
1286 
1287 #if LOWER_DIM_SIZE_COMP_TEST__SELECT_CHECKER_BOARD__DEBUG
1288     if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
1289         HDfprintf(stdout, "%s%d: H5Sget_select_npoints(tgt_sid) = %d.\n",
1290                   fcnName, mpi_rank, (int)H5Sget_select_npoints(tgt_sid));
1291     }
1292 #endif /* LOWER_DIM_SIZE_COMP_TEST__SELECT_CHECKER_BOARD__DEBUG */
1293 
1294     /* Clip the selection back to the data space proper. */
1295 
1296     for ( i = 0; i < test_max_rank; i++ ) {
1297 
1298         start[i]  = 0;
1299         stride[i] = dims[i];
1300         count[i]  = 1;
1301         block[i]  = dims[i];
1302     }
1303 
1304     ret = H5Sselect_hyperslab(tgt_sid, H5S_SELECT_AND,
1305                               start, stride, count, block);
1306 
1307     VRFY((ret != FAIL), "H5Sselect_hyperslab(AND) succeeded");
1308 
1309 #if LOWER_DIM_SIZE_COMP_TEST__SELECT_CHECKER_BOARD__DEBUG
1310     if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
1311         HDfprintf(stdout, "%s%d: H5Sget_select_npoints(tgt_sid) = %d.\n",
1312                   fcnName, mpi_rank, (int)H5Sget_select_npoints(tgt_sid));
1313         HDfprintf(stdout, "%s%d: done.\n", fcnName, mpi_rank);
1314     }
1315 #endif /* LOWER_DIM_SIZE_COMP_TEST__SELECT_CHECKER_BOARD__DEBUG */
1316 
1317     return;
1318 
1319 } /* lower_dim_size_comp_test__select_checker_board() */
1320 
1321 
1322 /****************************************************************
1323 **
1324 **  lower_dim_size_comp_test__verify_data():
1325 **
1326 **	Examine the supplied buffer to see if it contains the
1327 **	expected data.  Return TRUE if it does, and FALSE
1328 **      otherwise.
1329 **
1330 **	The supplied buffer is presumed to this process's slice
1331 **	of the target data set.  Each such slice will be an
1332 **	n-cube of rank (rank -1) and the supplied edge_size with
1333 **	origin (mpi_rank, 0, ... , 0) in the target data set.
1334 **
1335 **	Further, the buffer is presumed to be the result of reading
1336 **	or writing a checker board selection of an m (1 <= m <
1337 **      rank) dimensional slice through this processes slice
1338 **	of the target data set.  Also, this slice must be parallel
1339 **	to the fastest changing indicies.
1340 **
1341 **	It is further presumed that the buffer was zeroed before
1342 **	the read/write, and that the full target data set (i.e.
1343 **	the buffer/data set for all processes) was initialized
1344 **      with the natural numbers listed in order from the origin
1345 **	along the fastest changing axis.
1346 **
1347 **      Thus for a 20x10x10 dataset, the value stored in location
1348 **	(x, y, z) (assuming that z is the fastest changing index
1349 **	and x the slowest) is assumed to be:
1350 **
1351 **		(10 * 10 * x) + (10 * y) + z
1352 **
1353 **	Further, supposing that this is process 10, this process's
1354 **	slice of the dataset would be a 10 x 10 2-cube with origin
1355 **	(10, 0, 0) in the data set, and would be initialize (prior
1356 **	to the checkerboard selection) as follows:
1357 **
1358 **		1000, 1001, 1002, ... 1008, 1009
1359 **		1010, 1011, 1012, ... 1018, 1019
1360 **		  .     .     .         .     .
1361 **		  .     .     .         .     .
1362 **		  .     .     .         .     .
1363 **		1090, 1091, 1092, ... 1098, 1099
1364 **
1365 **	In the case of a read from the processors slice of another
1366 **	data set of different rank, the values expected will have
1367 **	to be adjusted accordingly.  This is done via the
1368 **	first_expected_val parameter.
1369 **
1370 **	Finally, the function presumes that the first element
1371 **	of the buffer resides either at the origin of either
1372 **	a selected or an unselected checker.  (Translation:
1373 **	if partial checkers appear in the buffer, they will
1374 **	intersect the edges of the n-cube oposite the origin.)
1375 **
1376 ****************************************************************/
1377 
1378 #define LOWER_DIM_SIZE_COMP_TEST__VERIFY_DATA__DEBUG 0
1379 
1380 static hbool_t
lower_dim_size_comp_test__verify_data(uint32_t * buf_ptr,const int mpi_rank,const int rank,const int edge_size,const int checker_edge_size,uint32_t first_expected_val,hbool_t buf_starts_in_checker)1381 lower_dim_size_comp_test__verify_data(uint32_t * buf_ptr,
1382 #if LOWER_DIM_SIZE_COMP_TEST__VERIFY_DATA__DEBUG
1383                                       const int mpi_rank,
1384 #endif /* LOWER_DIM_SIZE_COMP_TEST__VERIFY_DATA__DEBUG */
1385                                       const int rank,
1386                                       const int edge_size,
1387                                       const int checker_edge_size,
1388                                       uint32_t first_expected_val,
1389                                       hbool_t buf_starts_in_checker)
1390 {
1391 #if LOWER_DIM_SIZE_COMP_TEST__VERIFY_DATA__DEBUG
1392     const char *	fcnName =
1393 			"lower_dim_size_comp_test__verify_data():";
1394 #endif
1395     hbool_t good_data = TRUE;
1396     hbool_t in_checker;
1397     hbool_t start_in_checker[5];
1398     uint32_t expected_value;
1399     uint32_t * val_ptr;
1400     int i, j, k, l, m;  /* to track position in n-cube */
1401     int v, w, x, y, z;  /* to track position in checker */
1402     const int test_max_rank = 5; /* code changes needed if this is increased */
1403 
1404     HDassert( buf_ptr != NULL );
1405     HDassert( 0 < rank );
1406     HDassert( rank <= test_max_rank );
1407     HDassert( edge_size >= 6 );
1408     HDassert( 0 < checker_edge_size );
1409     HDassert( checker_edge_size <= edge_size );
1410     HDassert( test_max_rank <= LDSCT_DS_RANK );
1411 
1412 #if LOWER_DIM_SIZE_COMP_TEST__VERIFY_DATA__DEBUG
1413     if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
1414         HDfprintf(stdout, "%s mpi_rank = %d.\n", fcnName, mpi_rank);
1415         HDfprintf(stdout, "%s rank = %d.\n", fcnName, rank);
1416         HDfprintf(stdout, "%s edge_size = %d.\n", fcnName, edge_size);
1417         HDfprintf(stdout, "%s checker_edge_size = %d.\n",
1418                   fcnName, checker_edge_size);
1419         HDfprintf(stdout, "%s first_expected_val = %d.\n",
1420                   fcnName, (int)first_expected_val);
1421         HDfprintf(stdout, "%s starts_in_checker = %d.\n",
1422                   fcnName, (int)buf_starts_in_checker);
1423     }
1424 #endif
1425 
1426     val_ptr = buf_ptr;
1427     expected_value = first_expected_val;
1428 
1429     i = 0;
1430     v = 0;
1431     start_in_checker[0] = buf_starts_in_checker;
1432     do
1433     {
1434         if ( v >= checker_edge_size ) {
1435 
1436             start_in_checker[0] = ! start_in_checker[0];
1437             v = 0;
1438         }
1439 
1440         j = 0;
1441         w = 0;
1442         start_in_checker[1] = start_in_checker[0];
1443         do
1444         {
1445             if ( w >= checker_edge_size ) {
1446 
1447                 start_in_checker[1] = ! start_in_checker[1];
1448                 w = 0;
1449             }
1450 
1451             k = 0;
1452             x = 0;
1453             start_in_checker[2] = start_in_checker[1];
1454             do
1455             {
1456                 if ( x >= checker_edge_size ) {
1457 
1458                     start_in_checker[2] = ! start_in_checker[2];
1459                     x = 0;
1460                 }
1461 
1462                 l = 0;
1463                 y = 0;
1464                 start_in_checker[3] = start_in_checker[2];
1465                 do
1466                 {
1467                     if ( y >= checker_edge_size ) {
1468 
1469                         start_in_checker[3] = ! start_in_checker[3];
1470                         y = 0;
1471                     }
1472 
1473                     m = 0;
1474                     z = 0;
1475 #if LOWER_DIM_SIZE_COMP_TEST__VERIFY_DATA__DEBUG
1476                     if ( mpi_rank ==
1477                          LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
1478                         HDfprintf(stdout, "%d, %d, %d, %d, %d:", i, j, k, l, m);
1479                     }
1480 #endif
1481                     in_checker = start_in_checker[3];
1482                     do
1483                     {
1484 #if LOWER_DIM_SIZE_COMP_TEST__VERIFY_DATA__DEBUG
1485                         if ( mpi_rank ==
1486                              LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
1487                             HDfprintf(stdout, " %d", (int)(*val_ptr));
1488                         }
1489 #endif
1490                         if ( z >= checker_edge_size ) {
1491 
1492                             in_checker = ! in_checker;
1493                             z = 0;
1494                         }
1495 
1496                         if ( in_checker ) {
1497 
1498                             if ( *val_ptr != expected_value ) {
1499 
1500                                 good_data = FALSE;
1501                             }
1502 
1503                             /* zero out buffer for re-use */
1504                             *val_ptr = 0;
1505 
1506                         } else if ( *val_ptr != 0 ) {
1507 
1508                             good_data = FALSE;
1509 
1510                             /* zero out buffer for re-use */
1511                             *val_ptr = 0;
1512 
1513                         }
1514 
1515                         val_ptr++;
1516                         expected_value++;
1517                         m++;
1518                         z++;
1519 
1520                     } while ( ( rank >= (test_max_rank - 4) ) &&
1521                               ( m < edge_size ) );
1522 #if LOWER_DIM_SIZE_COMP_TEST__VERIFY_DATA__DEBUG
1523                     if ( mpi_rank ==
1524                          LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
1525                         HDfprintf(stdout, "\n");
1526                     }
1527 #endif
1528                     l++;
1529                     y++;
1530                 } while ( ( rank >= (test_max_rank - 3) ) &&
1531                           ( l < edge_size ) );
1532                 k++;
1533                 x++;
1534             } while ( ( rank >= (test_max_rank - 2) ) &&
1535                       ( k < edge_size ) );
1536             j++;
1537             w++;
1538         } while ( ( rank >= (test_max_rank - 1) ) &&
1539                   ( j < edge_size ) );
1540         i++;
1541         v++;
1542     } while ( ( rank >= test_max_rank ) &&
1543               ( i < edge_size ) );
1544 
1545     return(good_data);
1546 
1547 } /* lower_dim_size_comp_test__verify_data() */
1548 
1549 
1550 /*-------------------------------------------------------------------------
1551  * Function:	lower_dim_size_comp_test__run_test()
1552  *
1553  * Purpose:	Verify that a bug in the computation of the size of the
1554  *		lower dimensions of a data space in H5S_obtain_datatype()
1555  *		has been corrected.
1556  *
1557  * Return:	void
1558  *
1559  * Programmer:	JRM -- 11/11/09
1560  *
1561  * Modifications:
1562  *
1563  *-------------------------------------------------------------------------
1564  */
1565 
1566 #define LDSCT_DS_RANK	5
1567 #define LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG 0
1568 
1569 static void
lower_dim_size_comp_test__run_test(const int chunk_edge_size,const hbool_t use_collective_io,const hid_t dset_type)1570 lower_dim_size_comp_test__run_test(const int chunk_edge_size,
1571                                    const hbool_t use_collective_io,
1572                                    const hid_t dset_type)
1573 {
1574 #if LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG
1575     const char   *fcnName = "lower_dim_size_comp_test__run_test()";
1576     int		  rank;
1577     hsize_t	  dims[32];
1578     hsize_t	  max_dims[32];
1579 #endif /* LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG */
1580     const char   *filename;
1581     hbool_t	  data_ok = FALSE;
1582     hbool_t	  mis_match = FALSE;
1583     int           i;
1584     int           start_index;
1585     int           stop_index;
1586     int		  mrc;
1587     int		  mpi_rank;
1588     int		  mpi_size;
1589     MPI_Comm      mpi_comm = MPI_COMM_NULL;
1590     MPI_Info      mpi_info = MPI_INFO_NULL;
1591     hid_t         fid;                    /* HDF5 file ID */
1592     hid_t         acc_tpl;                /* File access templates */
1593     hid_t         xfer_plist = H5P_DEFAULT;
1594     size_t        small_ds_size;
1595     size_t        small_ds_slice_size;
1596     size_t        large_ds_size;
1597     size_t        large_ds_slice_size;
1598     uint32_t      expected_value;
1599     uint32_t    * small_ds_buf_0 = NULL;
1600     uint32_t    * small_ds_buf_1 = NULL;
1601     uint32_t    * large_ds_buf_0 = NULL;
1602     uint32_t    * large_ds_buf_1 = NULL;
1603     uint32_t    * ptr_0;
1604     uint32_t    * ptr_1;
1605     hsize_t       small_chunk_dims[LDSCT_DS_RANK];
1606     hsize_t       large_chunk_dims[LDSCT_DS_RANK];
1607     hsize_t       small_dims[LDSCT_DS_RANK];
1608     hsize_t       large_dims[LDSCT_DS_RANK];
1609     hsize_t       start[LDSCT_DS_RANK];
1610     hsize_t       stride[LDSCT_DS_RANK];
1611     hsize_t       count[LDSCT_DS_RANK];
1612     hsize_t       block[LDSCT_DS_RANK];
1613     hsize_t       small_sel_start[LDSCT_DS_RANK];
1614     hsize_t       large_sel_start[LDSCT_DS_RANK];
1615     hid_t         full_mem_small_ds_sid;
1616     hid_t         full_file_small_ds_sid;
1617     hid_t         mem_small_ds_sid;
1618     hid_t         file_small_ds_sid;
1619     hid_t         full_mem_large_ds_sid;
1620     hid_t         full_file_large_ds_sid;
1621     hid_t         mem_large_ds_sid;
1622     hid_t         file_large_ds_sid;
1623     hid_t         small_ds_dcpl_id = H5P_DEFAULT;
1624     hid_t         large_ds_dcpl_id = H5P_DEFAULT;
1625     hid_t         small_dataset;     /* Dataset ID                   */
1626     hid_t         large_dataset;     /* Dataset ID                   */
1627     htri_t        check;          /* Shape comparison return value */
1628     herr_t        ret;            /* Generic return value */
1629 
1630     MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
1631     MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
1632 
1633     HDassert( mpi_size >= 1 );
1634 
1635     mpi_comm = MPI_COMM_WORLD;
1636     mpi_info = MPI_INFO_NULL;
1637 
1638 #if LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG
1639     if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
1640         HDfprintf(stdout, "%s:%d: chunk_edge_size = %d.\n",
1641                   fcnName, mpi_rank, (int)chunk_edge_size);
1642         HDfprintf(stdout, "%s:%d: use_collective_io = %d.\n",
1643                   fcnName, mpi_rank, (int)use_collective_io);
1644     }
1645 #endif /* LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG */
1646 
1647 
1648     small_ds_size       = (size_t)((mpi_size + 1) *  1 *  1 * 10 * 10);
1649     small_ds_slice_size = (size_t)                 ( 1 *  1 * 10 * 10);
1650     large_ds_size       = (size_t)((mpi_size + 1) * 10 * 10 * 10 * 10);
1651     large_ds_slice_size = (size_t)                 (10 * 10 * 10 * 10);
1652 
1653 #if LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG
1654     if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
1655         HDfprintf(stdout, "%s:%d: small ds size / slice size = %d / %d.\n",
1656                   fcnName, mpi_rank,
1657                   (int)small_ds_size, (int)small_ds_slice_size);
1658         HDfprintf(stdout, "%s:%d: large ds size / slice size = %d / %d.\n",
1659                   fcnName, mpi_rank,
1660                   (int)large_ds_size, (int)large_ds_slice_size);
1661     }
1662 #endif /* LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG */
1663 
1664     /* Allocate buffers */
1665     small_ds_buf_0 = (uint32_t *)HDmalloc(sizeof(uint32_t) * small_ds_size);
1666     VRFY((small_ds_buf_0 != NULL), "malloc of small_ds_buf_0 succeeded");
1667 
1668     small_ds_buf_1 = (uint32_t *)HDmalloc(sizeof(uint32_t) * small_ds_size);
1669     VRFY((small_ds_buf_1 != NULL), "malloc of small_ds_buf_1 succeeded");
1670 
1671     large_ds_buf_0 = (uint32_t *)HDmalloc(sizeof(uint32_t) * large_ds_size);
1672     VRFY((large_ds_buf_0 != NULL), "malloc of large_ds_buf_0 succeeded");
1673 
1674     large_ds_buf_1 = (uint32_t *)HDmalloc(sizeof(uint32_t) * large_ds_size);
1675     VRFY((large_ds_buf_1 != NULL), "malloc of large_ds_buf_1 succeeded");
1676 
1677 
1678     /* initialize the buffers */
1679 
1680     ptr_0 = small_ds_buf_0;
1681     ptr_1 = small_ds_buf_1;
1682 
1683     for ( i = 0; i < (int)small_ds_size; i++ ) {
1684 
1685         *ptr_0 = (uint32_t)i;
1686         *ptr_1 = 0;
1687 
1688         ptr_0++;
1689         ptr_1++;
1690     }
1691 
1692     ptr_0 = large_ds_buf_0;
1693     ptr_1 = large_ds_buf_1;
1694 
1695     for ( i = 0; i < (int)large_ds_size; i++ ) {
1696 
1697         *ptr_0 = (uint32_t)i;
1698         *ptr_1 = 0;
1699 
1700         ptr_0++;
1701         ptr_1++;
1702     }
1703 
1704 
1705     /* get the file name */
1706 
1707     filename = (const char *)GetTestParameters();
1708     HDassert( filename != NULL );
1709 
1710 
1711     /* ----------------------------------------
1712      * CREATE AN HDF5 FILE WITH PARALLEL ACCESS
1713      * ---------------------------------------*/
1714     /* setup file access template */
1715     acc_tpl = create_faccess_plist(mpi_comm, mpi_info, facc_type);
1716     VRFY((acc_tpl >= 0), "create_faccess_plist() succeeded");
1717 
1718     /* create the file collectively */
1719     fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, acc_tpl);
1720     VRFY((fid >= 0), "H5Fcreate succeeded");
1721 
1722     MESG("File opened.");
1723 
1724     /* Release file-access template */
1725     ret = H5Pclose(acc_tpl);
1726     VRFY((ret >= 0), "H5Pclose(acc_tpl) succeeded");
1727 
1728 
1729     /* setup dims: */
1730     small_dims[0] = (hsize_t)(mpi_size + 1);
1731     small_dims[1] =  1;
1732     small_dims[2] =  1;
1733     small_dims[3] = 10;
1734     small_dims[4] = 10;
1735 
1736     large_dims[0] = (hsize_t)(mpi_size + 1);
1737     large_dims[1] = 10;
1738     large_dims[2] = 10;
1739     large_dims[3] = 10;
1740     large_dims[4] = 10;
1741 
1742 #if LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG
1743     if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
1744         HDfprintf(stdout, "%s:%d: small_dims[] = %d %d %d %d %d\n",
1745                   fcnName, mpi_rank, (int)small_dims[0], (int)small_dims[1],
1746                   (int)small_dims[2], (int)small_dims[3], (int)small_dims[4]);
1747         HDfprintf(stdout, "%s:%d: large_dims[] = %d %d %d %d %d\n",
1748                   fcnName, mpi_rank, (int)large_dims[0], (int)large_dims[1],
1749                   (int)large_dims[2], (int)large_dims[3], (int)large_dims[4]);
1750     }
1751 #endif
1752 
1753     /* create data spaces */
1754 
1755     full_mem_small_ds_sid = H5Screate_simple(5, small_dims, NULL);
1756     VRFY((full_mem_small_ds_sid != 0),
1757          "H5Screate_simple() full_mem_small_ds_sid succeeded");
1758 
1759     full_file_small_ds_sid = H5Screate_simple(5, small_dims, NULL);
1760     VRFY((full_file_small_ds_sid != 0),
1761          "H5Screate_simple() full_file_small_ds_sid succeeded");
1762 
1763     mem_small_ds_sid = H5Screate_simple(5, small_dims, NULL);
1764     VRFY((mem_small_ds_sid != 0),
1765          "H5Screate_simple() mem_small_ds_sid succeeded");
1766 
1767     file_small_ds_sid = H5Screate_simple(5, small_dims, NULL);
1768     VRFY((file_small_ds_sid != 0),
1769           "H5Screate_simple() file_small_ds_sid succeeded");
1770 
1771 
1772     full_mem_large_ds_sid = H5Screate_simple(5, large_dims, NULL);
1773     VRFY((full_mem_large_ds_sid != 0),
1774          "H5Screate_simple() full_mem_large_ds_sid succeeded");
1775 
1776     full_file_large_ds_sid = H5Screate_simple(5, large_dims, NULL);
1777     VRFY((full_file_large_ds_sid != 0),
1778          "H5Screate_simple() full_file_large_ds_sid succeeded");
1779 
1780     mem_large_ds_sid = H5Screate_simple(5, large_dims, NULL);
1781     VRFY((mem_large_ds_sid != 0),
1782          "H5Screate_simple() mem_large_ds_sid succeeded");
1783 
1784     file_large_ds_sid = H5Screate_simple(5, large_dims, NULL);
1785     VRFY((file_large_ds_sid != 0),
1786           "H5Screate_simple() file_large_ds_sid succeeded");
1787 
1788 
1789     /* Select the entire extent of the full small ds dataspaces */
1790     ret = H5Sselect_all(full_mem_small_ds_sid);
1791     VRFY((ret != FAIL), "H5Sselect_all(full_mem_small_ds_sid) succeeded");
1792 
1793     ret = H5Sselect_all(full_file_small_ds_sid);
1794     VRFY((ret != FAIL), "H5Sselect_all(full_file_small_ds_sid) succeeded");
1795 
1796 
1797     /* Select the entire extent of the full large ds dataspaces */
1798     ret = H5Sselect_all(full_mem_large_ds_sid);
1799     VRFY((ret != FAIL), "H5Sselect_all(full_mem_large_ds_sid) succeeded");
1800 
1801     ret = H5Sselect_all(full_file_large_ds_sid);
1802     VRFY((ret != FAIL), "H5Sselect_all(full_file_large_ds_sid) succeeded");
1803 
1804 
1805     /* if chunk edge size is greater than zero, set up the small and
1806      * large data set creation property lists to specify chunked
1807      * datasets.
1808      */
1809     if ( chunk_edge_size > 0 ) {
1810 
1811         small_chunk_dims[0] = (hsize_t)(1);
1812         small_chunk_dims[1] = small_chunk_dims[2] = (hsize_t)1;
1813         small_chunk_dims[3] = small_chunk_dims[4] = (hsize_t)chunk_edge_size;
1814 
1815 #if LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG
1816         if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
1817             HDfprintf(stdout, "%s:%d: small chunk dims[] = %d %d %d %d %d\n",
1818                       fcnName, mpi_rank, (int)small_chunk_dims[0],
1819                       (int)small_chunk_dims[1], (int)small_chunk_dims[2],
1820                       (int)small_chunk_dims[3], (int)small_chunk_dims[4]);
1821         }
1822 #endif
1823 
1824         small_ds_dcpl_id = H5Pcreate(H5P_DATASET_CREATE);
1825         VRFY((ret != FAIL), "H5Pcreate() small_ds_dcpl_id succeeded");
1826 
1827         ret = H5Pset_layout(small_ds_dcpl_id, H5D_CHUNKED);
1828         VRFY((ret != FAIL), "H5Pset_layout() small_ds_dcpl_id succeeded");
1829 
1830         ret = H5Pset_chunk(small_ds_dcpl_id, 5, small_chunk_dims);
1831         VRFY((ret != FAIL), "H5Pset_chunk() small_ds_dcpl_id succeeded");
1832 
1833         large_chunk_dims[0] = (hsize_t)(1);
1834         large_chunk_dims[1] = large_chunk_dims[2] =
1835         	large_chunk_dims[3] = large_chunk_dims[4] = (hsize_t)chunk_edge_size;
1836 
1837 
1838 #if LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG
1839         if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
1840             HDfprintf(stdout, "%s:%d: large chunk dims[] = %d %d %d %d %d\n",
1841                       fcnName, mpi_rank, (int)large_chunk_dims[0],
1842                       (int)large_chunk_dims[1], (int)large_chunk_dims[2],
1843                       (int)large_chunk_dims[3], (int)large_chunk_dims[4]);
1844         }
1845 #endif
1846 
1847         large_ds_dcpl_id = H5Pcreate(H5P_DATASET_CREATE);
1848         VRFY((ret != FAIL), "H5Pcreate() large_ds_dcpl_id succeeded");
1849 
1850         ret = H5Pset_layout(large_ds_dcpl_id, H5D_CHUNKED);
1851         VRFY((ret != FAIL), "H5Pset_layout() large_ds_dcpl_id succeeded");
1852 
1853         ret = H5Pset_chunk(large_ds_dcpl_id, 5, large_chunk_dims);
1854         VRFY((ret != FAIL), "H5Pset_chunk() large_ds_dcpl_id succeeded");
1855     }
1856 
1857 
1858     /* create the small dataset */
1859     small_dataset = H5Dcreate2(fid, "small_dataset", dset_type,
1860                                file_small_ds_sid, H5P_DEFAULT,
1861                                small_ds_dcpl_id, H5P_DEFAULT);
1862     VRFY((ret >= 0), "H5Dcreate2() small_dataset succeeded");
1863 
1864 
1865     /* create the large dataset */
1866     large_dataset = H5Dcreate2(fid, "large_dataset", dset_type,
1867                                file_large_ds_sid, H5P_DEFAULT,
1868                                large_ds_dcpl_id, H5P_DEFAULT);
1869     VRFY((ret >= 0), "H5Dcreate2() large_dataset succeeded");
1870 
1871 #if LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG
1872     if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
1873         HDfprintf(stdout,
1874                   "%s:%d: small/large ds id = %d / %d.\n",
1875                   fcnName, mpi_rank, (int)small_dataset,
1876                   (int)large_dataset);
1877     }
1878 #endif /* LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG */
1879 
1880 
1881     /* setup xfer property list */
1882     xfer_plist = H5Pcreate(H5P_DATASET_XFER);
1883     VRFY((xfer_plist >= 0), "H5Pcreate(H5P_DATASET_XFER) succeeded");
1884 
1885     ret = H5Pset_dxpl_mpio(xfer_plist, H5FD_MPIO_COLLECTIVE);
1886     VRFY((ret >= 0), "H5Pset_dxpl_mpio succeeded");
1887 
1888     if ( ! use_collective_io ) {
1889 
1890         ret = H5Pset_dxpl_mpio_collective_opt(xfer_plist,
1891                                               H5FD_MPIO_INDIVIDUAL_IO);
1892         VRFY((ret>= 0), "H5Pset_dxpl_mpio_collective_opt() suceeded");
1893     }
1894 
1895 
1896     /* setup selection to write initial data to the small data sets */
1897     start[0] = (hsize_t)(mpi_rank + 1);
1898     start[1] = start[2] = start[3] = start[4] = 0;
1899 
1900     stride[0] = (hsize_t)(2 * (mpi_size + 1));
1901     stride[1] = stride[2] = 2;
1902     stride[3] = stride[4] = 2 * 10;
1903 
1904     count[0] = count[1] = count[2] = count[3] = count[4] = 1;
1905 
1906     block[0] = block[1] = block[2] = 1;
1907     block[3] = block[4] = 10;
1908 
1909 #if LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG
1910     if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
1911         HDfprintf(stdout,
1912                   "%s:%d: settings for small data set initialization.\n",
1913                   fcnName, mpi_rank);
1914         HDfprintf(stdout, "%s:%d: start[]  = %d %d %d %d %d\n",
1915                   fcnName, mpi_rank, (int)start[0], (int)start[1],
1916                   (int)start[2], (int)start[3], (int)start[4]);
1917         HDfprintf(stdout, "%s:%d: stride[] = %d %d %d %d %d\n",
1918                   fcnName, mpi_rank, (int)stride[0], (int)stride[1],
1919                   (int)stride[2], (int)stride[3], (int)stride[4]);
1920         HDfprintf(stdout, "%s:%d: count[]  = %d %d %d %d %d\n",
1921                   fcnName, mpi_rank, (int)count[0], (int)count[1],
1922                   (int)count[2], (int)count[3], (int)count[4]);
1923         HDfprintf(stdout, "%s:%d: block[]  = %d %d %d %d %d\n",
1924                   fcnName, mpi_rank, (int)block[0], (int)block[1],
1925                   (int)block[2], (int)block[3], (int)block[4]);
1926     }
1927 #endif /* LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG */
1928 
1929     /* setup selections for writing initial data to the small data set */
1930     ret = H5Sselect_hyperslab(mem_small_ds_sid,
1931                               H5S_SELECT_SET,
1932                               start,
1933                               stride,
1934                               count,
1935                               block);
1936     VRFY((ret >= 0), "H5Sselect_hyperslab(mem_small_ds_sid, set) suceeded");
1937 
1938     ret = H5Sselect_hyperslab(file_small_ds_sid,
1939                               H5S_SELECT_SET,
1940                               start,
1941                               stride,
1942                               count,
1943                               block);
1944     VRFY((ret >= 0), "H5Sselect_hyperslab(file_small_ds_sid, set) suceeded");
1945 
1946     if ( MAINPROCESS ) { /* add an additional slice to the selections */
1947 
1948         start[0] = 0;
1949 
1950 #if LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG
1951         if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
1952             HDfprintf(stdout,
1953                       "%s:%d: added settings for main process.\n",
1954                       fcnName, mpi_rank);
1955             HDfprintf(stdout, "%s:%d: start[]  = %d %d %d %d %d\n",
1956                       fcnName, mpi_rank, (int)start[0], (int)start[1],
1957                       (int)start[2], (int)start[3], (int)start[4]);
1958             HDfprintf(stdout, "%s:%d: stride[] = %d %d %d %d %d\n",
1959                       fcnName, mpi_rank, (int)stride[0], (int)stride[1],
1960                       (int)stride[2], (int)stride[3], (int)stride[4]);
1961             HDfprintf(stdout, "%s:%d: count[]  = %d %d %d %d %d\n",
1962                       fcnName, mpi_rank, (int)count[0], (int)count[1],
1963                       (int)count[2], (int)count[3], (int)count[4]);
1964             HDfprintf(stdout, "%s:%d: block[]  = %d %d %d %d %d\n",
1965                       fcnName, mpi_rank, (int)block[0], (int)block[1],
1966                       (int)block[2], (int)block[3], (int)block[4]);
1967         }
1968 #endif /* LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG */
1969 
1970         ret = H5Sselect_hyperslab(mem_small_ds_sid,
1971                                   H5S_SELECT_OR,
1972                                   start,
1973                                   stride,
1974                                   count,
1975                                   block);
1976         VRFY((ret>= 0), "H5Sselect_hyperslab(mem_small_ds_sid, or) suceeded");
1977 
1978         ret = H5Sselect_hyperslab(file_small_ds_sid,
1979                                   H5S_SELECT_OR,
1980                                   start,
1981                                   stride,
1982                                   count,
1983                                   block);
1984         VRFY((ret>= 0), "H5Sselect_hyperslab(file_small_ds_sid, or) suceeded");
1985     }
1986 
1987     check =  H5Sselect_valid(mem_small_ds_sid);
1988     VRFY((check == TRUE),"H5Sselect_valid(mem_small_ds_sid) returns TRUE");
1989 
1990     check =  H5Sselect_valid(file_small_ds_sid);
1991     VRFY((check == TRUE),"H5Sselect_valid(file_small_ds_sid) returns TRUE");
1992 
1993 
1994     /* write the initial value of the small data set to file */
1995 #if LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG
1996     if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
1997         HDfprintf(stdout, "%s:%d: writing init value of small ds to file.\n",
1998                   fcnName, mpi_rank);
1999     }
2000 #endif /* LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG */
2001     ret = H5Dwrite(small_dataset,
2002                    dset_type,
2003                    mem_small_ds_sid,
2004                    file_small_ds_sid,
2005                    xfer_plist,
2006                    small_ds_buf_0);
2007     VRFY((ret >= 0), "H5Dwrite() small_dataset initial write succeeded");
2008 
2009 
2010     /* read the small data set back to verify that it contains the
2011      * expected data.  Note that each process reads in the entire
2012      * data set and verifies it.
2013      */
2014     ret = H5Dread(small_dataset,
2015                   H5T_NATIVE_UINT32,
2016                   full_mem_small_ds_sid,
2017                   full_file_small_ds_sid,
2018                   xfer_plist,
2019                   small_ds_buf_1);
2020     VRFY((ret >= 0), "H5Dread() small_dataset initial read succeeded");
2021 
2022 
2023     /* sync with the other processes before checking data */
2024     mrc = MPI_Barrier(MPI_COMM_WORLD);
2025     VRFY((mrc==MPI_SUCCESS), "Sync after small dataset writes");
2026 
2027 
2028     /* verify that the correct data was written to the small data set,
2029      * and reset the buffer to zero in passing.
2030      */
2031     expected_value = 0;
2032     mis_match = FALSE;
2033     ptr_1 = small_ds_buf_1;
2034 
2035     i = 0;
2036     for ( i = 0; i < (int)small_ds_size; i++ ) {
2037 
2038         if ( *ptr_1 != expected_value ) {
2039 
2040             mis_match = TRUE;
2041         }
2042 
2043         *ptr_1 = (uint32_t)0;
2044 
2045         ptr_1++;
2046         expected_value++;
2047     }
2048     VRFY( (mis_match == FALSE), "small ds init data good.");
2049 
2050 
2051 
2052     /* setup selections for writing initial data to the large data set */
2053     start[0] = (hsize_t)(mpi_rank + 1);
2054     start[1] = start[2] = start[3] = start[4] = (hsize_t)0;
2055 
2056     stride[0] = (hsize_t)(2 * (mpi_size + 1));
2057     stride[1] = stride[2] = stride[3] = stride[4] = (hsize_t)(2 * 10);
2058 
2059     count[0] = count[1] = count[2] = count[3] = count[4] = (hsize_t)1;
2060 
2061     block[0] = (hsize_t)1;
2062     block[1] = block[2] = block[3] = block[4] = (hsize_t)10;
2063 
2064 #if LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG
2065     if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
2066         HDfprintf(stdout,
2067                   "%s:%d: settings for large data set initialization.\n",
2068                   fcnName, mpi_rank);
2069         HDfprintf(stdout, "%s:%d: start[]  = %d %d %d %d %d\n",
2070                   fcnName, mpi_rank, (int)start[0], (int)start[1],
2071                   (int)start[2], (int)start[3], (int)start[4]);
2072         HDfprintf(stdout, "%s:%d: stride[] = %d %d %d %d %d\n",
2073                   fcnName, mpi_rank, (int)stride[0], (int)stride[1],
2074                   (int)stride[2], (int)stride[3], (int)stride[4]);
2075         HDfprintf(stdout, "%s:%d: count[]  = %d %d %d %d %d\n",
2076                   fcnName, mpi_rank, (int)count[0], (int)count[1],
2077                   (int)count[2], (int)count[3], (int)count[4]);
2078         HDfprintf(stdout, "%s:%d: block[]  = %d %d %d %d %d\n",
2079                   fcnName, mpi_rank, (int)block[0], (int)block[1],
2080                   (int)block[2], (int)block[3], (int)block[4]);
2081     }
2082 #endif /* LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG */
2083 
2084     ret = H5Sselect_hyperslab(mem_large_ds_sid,
2085                               H5S_SELECT_SET,
2086                               start,
2087                               stride,
2088                               count,
2089                               block);
2090     VRFY((ret >= 0), "H5Sselect_hyperslab(mem_large_ds_sid, set) suceeded");
2091 
2092     ret = H5Sselect_hyperslab(file_large_ds_sid,
2093                               H5S_SELECT_SET,
2094                               start,
2095                               stride,
2096                               count,
2097                               block);
2098     VRFY((ret >= 0), "H5Sselect_hyperslab(file_large_ds_sid, set) suceeded");
2099 
2100 #if LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG
2101     if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
2102 	 HDfprintf(stdout,
2103               "%s%d: H5Sget_select_npoints(mem_large_ds_sid) = %d.\n",
2104               fcnName, mpi_rank,
2105               (int)H5Sget_select_npoints(mem_large_ds_sid));
2106 	 HDfprintf(stdout,
2107               "%s%d: H5Sget_select_npoints(file_large_ds_sid) = %d.\n",
2108               fcnName, mpi_rank,
2109               (int)H5Sget_select_npoints(file_large_ds_sid));
2110     }
2111 #endif /* LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG */
2112 
2113     if ( MAINPROCESS ) { /* add an additional slice to the selections */
2114 
2115         start[0] = (hsize_t)0;
2116 
2117 #if LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG
2118         if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
2119             HDfprintf(stdout,
2120                       "%s:%d: added settings for main process.\n",
2121                       fcnName, mpi_rank);
2122             HDfprintf(stdout, "%s:%d: start[]  = %d %d %d %d %d\n",
2123                       fcnName, mpi_rank, (int)start[0], (int)start[1],
2124                       (int)start[2], (int)start[3], (int)start[4]);
2125             HDfprintf(stdout, "%s:%d: stride[] = %d %d %d %d %d\n",
2126                       fcnName, mpi_rank, (int)stride[0], (int)stride[1],
2127                       (int)stride[2], (int)stride[3], (int)stride[4]);
2128             HDfprintf(stdout, "%s:%d: count[]  = %d %d %d %d %d\n",
2129                       fcnName, mpi_rank, (int)count[0], (int)count[1],
2130                       (int)count[2], (int)count[3], (int)count[4]);
2131             HDfprintf(stdout, "%s:%d: block[]  = %d %d %d %d %d\n",
2132                       fcnName, mpi_rank, (int)block[0], (int)block[1],
2133                       (int)block[2], (int)block[3], (int)block[4]);
2134         }
2135 #endif /* LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG */
2136 
2137         ret = H5Sselect_hyperslab(mem_large_ds_sid,
2138                                   H5S_SELECT_OR,
2139                                   start,
2140                                   stride,
2141                                   count,
2142                                   block);
2143         VRFY((ret>= 0), "H5Sselect_hyperslab(mem_large_ds_sid, or) suceeded");
2144 
2145         ret = H5Sselect_hyperslab(file_large_ds_sid,
2146                                   H5S_SELECT_OR,
2147                                   start,
2148                                   stride,
2149                                   count,
2150                                   block);
2151         VRFY((ret>= 0), "H5Sselect_hyperslab(file_large_ds_sid, or) suceeded");
2152 
2153 #if LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG
2154         if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
2155  	     HDfprintf(stdout,
2156                   "%s%d: H5Sget_select_npoints(mem_large_ds_sid) = %d.\n",
2157                   fcnName, mpi_rank,
2158                   (int)H5Sget_select_npoints(mem_large_ds_sid));
2159 	     HDfprintf(stdout,
2160                   "%s%d: H5Sget_select_npoints(file_large_ds_sid) = %d.\n",
2161                   fcnName, mpi_rank,
2162                   (int)H5Sget_select_npoints(file_large_ds_sid));
2163         }
2164 #endif /* LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG */
2165     }
2166 
2167     /* try clipping the selection back to the large data space proper */
2168     start[0] = start[1] = start[2] = start[3] = start[4] = (hsize_t)0;
2169 
2170     stride[0] = (hsize_t)(2 * (mpi_size + 1));
2171     stride[1] = stride[2] = stride[3] = stride[4] = (hsize_t)(2 * 10);
2172 
2173     count[0] = count[1] = count[2] = count[3] = count[4] = (hsize_t)1;
2174 
2175     block[0] = (hsize_t)(mpi_size + 1);
2176     block[1] = block[2] = block[3] = block[4] = (hsize_t)10;
2177 
2178     ret = H5Sselect_hyperslab(mem_large_ds_sid, H5S_SELECT_AND,
2179                               start, stride, count, block);
2180     VRFY((ret != FAIL),"H5Sselect_hyperslab(mem_large_ds_sid, and) succeeded");
2181 
2182     ret = H5Sselect_hyperslab(file_large_ds_sid, H5S_SELECT_AND,
2183                               start, stride, count, block);
2184     VRFY((ret != FAIL),"H5Sselect_hyperslab(file_large_ds_sid, and) succeeded");
2185 
2186 #if LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG
2187     if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
2188 
2189         rank = H5Sget_simple_extent_dims(mem_large_ds_sid, dims, max_dims);
2190         HDfprintf(stdout,
2191                   "%s:%d: mem_large_ds_sid dims[%d] = %d %d %d %d %d\n",
2192                   fcnName, mpi_rank, rank, (int)dims[0], (int)dims[1],
2193                   (int)dims[2], (int)dims[3], (int)dims[4]);
2194 
2195         rank = H5Sget_simple_extent_dims(file_large_ds_sid, dims, max_dims);
2196         HDfprintf(stdout,
2197                   "%s:%d: file_large_ds_sid dims[%d] = %d %d %d %d %d\n",
2198                   fcnName, mpi_rank, rank, (int)dims[0], (int)dims[1],
2199                   (int)dims[2], (int)dims[3], (int)dims[4]);
2200     }
2201 #endif /* LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG */
2202 
2203     check =  H5Sselect_valid(mem_large_ds_sid);
2204     VRFY((check == TRUE),"H5Sselect_valid(mem_large_ds_sid) returns TRUE");
2205 
2206     check =  H5Sselect_valid(file_large_ds_sid);
2207     VRFY((check == TRUE),"H5Sselect_valid(file_large_ds_sid) returns TRUE");
2208 
2209 
2210     /* write the initial value of the large data set to file */
2211 #if LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG
2212     if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
2213         HDfprintf(stdout, "%s:%d: writing init value of large ds to file.\n",
2214                   fcnName, mpi_rank);
2215         HDfprintf(stdout,
2216                   "%s:%d: large_dataset = %d.\n",
2217                   fcnName, mpi_rank,
2218                   (int)large_dataset);
2219         HDfprintf(stdout,
2220                   "%s:%d: mem_large_ds_sid = %d, file_large_ds_sid = %d.\n",
2221                   fcnName, mpi_rank,
2222                   (int)mem_large_ds_sid, (int)file_large_ds_sid);
2223     }
2224 #endif /* LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG */
2225 
2226     ret = H5Dwrite(large_dataset,
2227                    dset_type,
2228                    mem_large_ds_sid,
2229                    file_large_ds_sid,
2230                    xfer_plist,
2231                    large_ds_buf_0);
2232 
2233     if ( ret < 0 ) H5Eprint2(H5E_DEFAULT, stderr);
2234     VRFY((ret >= 0), "H5Dwrite() large_dataset initial write succeeded");
2235 
2236 
2237     /* sync with the other processes before checking data */
2238     mrc = MPI_Barrier(MPI_COMM_WORLD);
2239     VRFY((mrc==MPI_SUCCESS), "Sync after large dataset writes");
2240 
2241     /* read the large data set back to verify that it contains the
2242      * expected data.  Note that each process reads in the entire
2243      * data set.
2244      */
2245     ret = H5Dread(large_dataset,
2246                   H5T_NATIVE_UINT32,
2247                   full_mem_large_ds_sid,
2248                   full_file_large_ds_sid,
2249                   xfer_plist,
2250                   large_ds_buf_1);
2251     VRFY((ret >= 0), "H5Dread() large_dataset initial read succeeded");
2252 
2253 
2254     /* verify that the correct data was written to the large data set.
2255      * in passing, reset the buffer to zeros
2256      */
2257     expected_value = 0;
2258     mis_match = FALSE;
2259     ptr_1 = large_ds_buf_1;
2260 
2261     i = 0;
2262     for ( i = 0; i < (int)large_ds_size; i++ ) {
2263 
2264         if ( *ptr_1 != expected_value ) {
2265 
2266             mis_match = TRUE;
2267         }
2268 
2269         *ptr_1 = (uint32_t)0;
2270 
2271         ptr_1++;
2272         expected_value++;
2273     }
2274     VRFY( (mis_match == FALSE), "large ds init data good.");
2275 
2276     /***********************************/
2277     /***** INITIALIZATION COMPLETE *****/
2278     /***********************************/
2279 
2280 
2281     /* read a checkerboard selection of the process slice of the
2282      * small on disk data set into the process slice of the large
2283      * in memory data set, and verify the data read.
2284      */
2285 
2286     small_sel_start[0] = (hsize_t)(mpi_rank + 1);
2287     small_sel_start[1] = small_sel_start[2] =
2288     small_sel_start[3] = small_sel_start[4] = 0;
2289 
2290     lower_dim_size_comp_test__select_checker_board(mpi_rank,
2291                                                    file_small_ds_sid,
2292                                                    /* tgt_rank          = */  5,
2293                                                    small_dims,
2294                                                    /* checker_edge_size = */  3,
2295                                                    /* sel_rank */             2,
2296                                                    small_sel_start);
2297 
2298     expected_value = (uint32_t)
2299                      ((small_sel_start[0] * small_dims[1] * small_dims[2] *
2300                                             small_dims[3] * small_dims[4]) +
2301                       (small_sel_start[1] * small_dims[2] * small_dims[3] *
2302                                             small_dims[4]) +
2303                       (small_sel_start[2] * small_dims[3] * small_dims[4]) +
2304                       (small_sel_start[3] * small_dims[4]) +
2305                       (small_sel_start[4]));
2306 
2307 
2308     large_sel_start[0] = (hsize_t)(mpi_rank + 1);
2309     large_sel_start[1] = 5;
2310     large_sel_start[2] = large_sel_start[3] = large_sel_start[4] = 0;
2311 
2312     lower_dim_size_comp_test__select_checker_board(mpi_rank,
2313                                                    mem_large_ds_sid,
2314                                                    /* tgt_rank          = */  5,
2315                                                    large_dims,
2316                                                    /* checker_edge_size = */  3,
2317                                                    /* sel_rank          = */  2,
2318                                                    large_sel_start);
2319 
2320 
2321     /* verify that H5S_select_shape_same() reports the two
2322      * selections as having the same shape.
2323      */
2324     check = H5S_select_shape_same_test(mem_large_ds_sid,
2325                                        file_small_ds_sid);
2326     VRFY((check == TRUE), "H5S_select_shape_same_test passed (1)");
2327 
2328 
2329     ret = H5Dread(small_dataset,
2330                   H5T_NATIVE_UINT32,
2331                   mem_large_ds_sid,
2332                   file_small_ds_sid,
2333                   xfer_plist,
2334                   large_ds_buf_1);
2335 
2336     VRFY((ret >= 0), "H5Sread() slice from small ds succeeded.");
2337 
2338 #if LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG
2339     if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
2340         HDfprintf(stdout, "%s:%d: H5Dread() returns.\n", fcnName, mpi_rank);
2341     }
2342 #endif /* LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG */
2343 
2344     /* verify that expected data is retrieved */
2345 
2346     data_ok = TRUE;
2347 
2348     start_index = (int)((large_sel_start[0] * large_dims[1] * large_dims[2] *
2349                                               large_dims[3] * large_dims[4]) +
2350                         (large_sel_start[1] * large_dims[2] * large_dims[3] *
2351                                               large_dims[4]) +
2352                         (large_sel_start[2] * large_dims[3] * large_dims[4]) +
2353                         (large_sel_start[3] * large_dims[4]) +
2354                         (large_sel_start[4]));
2355 
2356     stop_index  = start_index + (int)small_ds_slice_size;
2357 
2358     HDassert( 0 <= start_index );
2359     HDassert( start_index < stop_index );
2360     HDassert( stop_index <= (int)large_ds_size );
2361 
2362     ptr_1 = large_ds_buf_1;
2363 
2364     for ( i = 0; i < start_index; i++ ) {
2365 
2366         if ( *ptr_1 != (uint32_t)0 ) {
2367 
2368             data_ok = FALSE;
2369             *ptr_1 = (uint32_t)0;
2370         }
2371 
2372         ptr_1++;
2373     }
2374 
2375     VRFY((data_ok == TRUE), "slice read from small ds data good(1).");
2376 
2377 
2378     data_ok = lower_dim_size_comp_test__verify_data(ptr_1,
2379 #if LOWER_DIM_SIZE_COMP_TEST__VERIFY_DATA__DEBUG
2380                                             mpi_rank,
2381 #endif /* LOWER_DIM_SIZE_COMP_TEST__VERIFY_DATA__DEBUG */
2382                                             /* rank */ 2,
2383                                             /* edge_size */ 10,
2384                                             /*  checker_edge_size */ 3,
2385                                             expected_value,
2386                                             /* buf_starts_in_checker */ TRUE);
2387 
2388     VRFY((data_ok == TRUE), "slice read from small ds data good(2).");
2389 
2390     data_ok = TRUE;
2391 
2392     ptr_1 += small_ds_slice_size;
2393 
2394 
2395     for ( i = stop_index; i < (int)large_ds_size; i++ ) {
2396 
2397         if ( *ptr_1 != (uint32_t)0 ) {
2398 
2399             data_ok = FALSE;
2400             *ptr_1 = (uint32_t)0;
2401         }
2402 
2403         ptr_1++;
2404     }
2405 
2406     VRFY((data_ok == TRUE), "slice read from small ds data good(3).");
2407 
2408 
2409 
2410 
2411 
2412     /* read a checkerboard selection of a slice of the process slice of
2413      * the large on disk data set into the process slice of the small
2414      * in memory data set, and verify the data read.
2415      */
2416 
2417     small_sel_start[0] = (hsize_t)(mpi_rank + 1);
2418     small_sel_start[1] = small_sel_start[2] =
2419     small_sel_start[3] = small_sel_start[4] = 0;
2420 
2421     lower_dim_size_comp_test__select_checker_board(mpi_rank,
2422                                                    mem_small_ds_sid,
2423                                                    /* tgt_rank          = */  5,
2424                                                    small_dims,
2425                                                    /* checker_edge_size = */  3,
2426                                                    /* sel_rank */             2,
2427                                                    small_sel_start);
2428 
2429     large_sel_start[0] = (hsize_t)(mpi_rank + 1);
2430     large_sel_start[1] = 5;
2431     large_sel_start[2] = large_sel_start[3] = large_sel_start[4] = 0;
2432 
2433     lower_dim_size_comp_test__select_checker_board(mpi_rank,
2434                                                    file_large_ds_sid,
2435                                                    /* tgt_rank          = */  5,
2436                                                    large_dims,
2437                                                    /* checker_edge_size = */  3,
2438                                                    /* sel_rank          = */  2,
2439                                                    large_sel_start);
2440 
2441 
2442     /* verify that H5S_select_shape_same() reports the two
2443      * selections as having the same shape.
2444      */
2445     check = H5S_select_shape_same_test(mem_small_ds_sid,
2446                                        file_large_ds_sid);
2447     VRFY((check == TRUE), "H5S_select_shape_same_test passed (2)");
2448 
2449 
2450     ret = H5Dread(large_dataset,
2451                   H5T_NATIVE_UINT32,
2452                   mem_small_ds_sid,
2453                   file_large_ds_sid,
2454                   xfer_plist,
2455                   small_ds_buf_1);
2456 
2457     VRFY((ret >= 0), "H5Sread() slice from large ds succeeded.");
2458 
2459 #if LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG
2460     if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
2461         HDfprintf(stdout, "%s:%d: H5Dread() returns.\n", fcnName, mpi_rank);
2462     }
2463 #endif /* LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG */
2464 
2465     /* verify that expected data is retrieved */
2466 
2467     data_ok = TRUE;
2468 
2469     expected_value = (uint32_t)
2470                      ((large_sel_start[0] * large_dims[1] * large_dims[2] *
2471                                             large_dims[3] * large_dims[4]) +
2472                       (large_sel_start[1] * large_dims[2] * large_dims[3] *
2473                                             large_dims[4]) +
2474                       (large_sel_start[2] * large_dims[3] * large_dims[4]) +
2475                       (large_sel_start[3] * large_dims[4]) +
2476                       (large_sel_start[4]));
2477 
2478     start_index = (int)(mpi_rank + 1) * (int)small_ds_slice_size;
2479 
2480     stop_index  = start_index + (int)small_ds_slice_size;
2481 
2482     HDassert( 0 <= start_index );
2483     HDassert( start_index < stop_index );
2484     HDassert( stop_index <= (int)small_ds_size );
2485 
2486     ptr_1 = small_ds_buf_1;
2487 
2488     for ( i = 0; i < start_index; i++ ) {
2489 
2490         if ( *ptr_1 != (uint32_t)0 ) {
2491 
2492             data_ok = FALSE;
2493             *ptr_1 = (uint32_t)0;
2494         }
2495 
2496         ptr_1++;
2497     }
2498 
2499     VRFY((data_ok == TRUE), "slice read from large ds data good(1).");
2500 
2501 
2502     data_ok = lower_dim_size_comp_test__verify_data(ptr_1,
2503 #if LOWER_DIM_SIZE_COMP_TEST__VERIFY_DATA__DEBUG
2504                                                     mpi_rank,
2505 #endif /* LOWER_DIM_SIZE_COMP_TEST__VERIFY_DATA__DEBUG */
2506                                                     /* rank */ 2,
2507                                                     /* edge_size */ 10,
2508                                                     /*  checker_edge_size */ 3,
2509                                                     expected_value,
2510                                                     /* buf_starts_in_checker */ TRUE);
2511 
2512     VRFY((data_ok == TRUE), "slice read from large ds data good(2).");
2513 
2514     data_ok = TRUE;
2515 
2516     ptr_1 += small_ds_slice_size;
2517 
2518 
2519     for ( i = stop_index; i < (int)small_ds_size; i++ ) {
2520 
2521         if ( *ptr_1 != (uint32_t)0 ) {
2522 
2523 #if LOWER_DIM_SIZE_COMP_TEST__VERIFY_DATA__DEBUG
2524             if ( mpi_rank == LOWER_DIM_SIZE_COMP_TEST_DEBUG_TARGET_RANK ) {
2525                 HDfprintf(stdout, "%s:%d: unexpected value at index %d: %d.\n",
2526                           fcnName, mpi_rank, (int)i, (int)(*ptr_1));
2527             }
2528 #endif /* LOWER_DIM_SIZE_COMP_TEST__VERIFY_DATA__DEBUG */
2529 
2530             data_ok = FALSE;
2531             *ptr_1 = (uint32_t)0;
2532         }
2533 
2534         ptr_1++;
2535     }
2536 
2537     VRFY((data_ok == TRUE), "slice read from large ds data good(3).");
2538 
2539 
2540     /* Close dataspaces */
2541     ret = H5Sclose(full_mem_small_ds_sid);
2542     VRFY((ret != FAIL), "H5Sclose(full_mem_small_ds_sid) succeeded");
2543 
2544     ret = H5Sclose(full_file_small_ds_sid);
2545     VRFY((ret != FAIL), "H5Sclose(full_file_small_ds_sid) succeeded");
2546 
2547     ret = H5Sclose(mem_small_ds_sid);
2548     VRFY((ret != FAIL), "H5Sclose(mem_small_ds_sid) succeeded");
2549 
2550     ret = H5Sclose(file_small_ds_sid);
2551     VRFY((ret != FAIL), "H5Sclose(file_small_ds_sid) succeeded");
2552 
2553 
2554     ret = H5Sclose(full_mem_large_ds_sid);
2555     VRFY((ret != FAIL), "H5Sclose(full_mem_large_ds_sid) succeeded");
2556 
2557     ret = H5Sclose(full_file_large_ds_sid);
2558     VRFY((ret != FAIL), "H5Sclose(full_file_large_ds_sid) succeeded");
2559 
2560     ret = H5Sclose(mem_large_ds_sid);
2561     VRFY((ret != FAIL), "H5Sclose(mem_large_ds_sid) succeeded");
2562 
2563     ret = H5Sclose(file_large_ds_sid);
2564     VRFY((ret != FAIL), "H5Sclose(file_large_ds_sid) succeeded");
2565 
2566 
2567     /* Close Datasets */
2568     ret = H5Dclose(small_dataset);
2569     VRFY((ret != FAIL), "H5Dclose(small_dataset) succeeded");
2570 
2571     ret = H5Dclose(large_dataset);
2572     VRFY((ret != FAIL), "H5Dclose(large_dataset) succeeded");
2573 
2574 
2575     /* close the file collectively */
2576     MESG("about to close file.");
2577     ret = H5Fclose(fid);
2578     VRFY((ret != FAIL), "file close succeeded");
2579 
2580     /* Free memory buffers */
2581     if ( small_ds_buf_0 != NULL ) HDfree(small_ds_buf_0);
2582     if ( small_ds_buf_1 != NULL ) HDfree(small_ds_buf_1);
2583 
2584     if ( large_ds_buf_0 != NULL ) HDfree(large_ds_buf_0);
2585     if ( large_ds_buf_1 != NULL ) HDfree(large_ds_buf_1);
2586 
2587     return;
2588 
2589 } /* lower_dim_size_comp_test__run_test() */
2590 
2591 
2592 /*-------------------------------------------------------------------------
2593  * Function:	lower_dim_size_comp_test()
2594  *
2595  * Purpose:	Test to see if an error in the computation of the size
2596  *		of the lower dimensions in H5S_obtain_datatype() has
2597  *		been corrected.
2598  *
2599  * Return:	void
2600  *
2601  * Programmer:	JRM -- 11/11/09
2602  *
2603  * Modifications:
2604  *
2605  *-------------------------------------------------------------------------
2606  */
2607 
2608 void
lower_dim_size_comp_test(void)2609 lower_dim_size_comp_test(void)
2610 {
2611     /* const char *fcnName = "lower_dim_size_comp_test()"; */
2612     int		chunk_edge_size = 0;
2613     int  	use_collective_io = 1;
2614     hid_t	dset_type = H5T_NATIVE_UINT;
2615 #if 0
2616    sleep(60);
2617 #endif
2618     HDcompile_assert(sizeof(uint32_t) == sizeof(unsigned));
2619     for ( use_collective_io = (hbool_t)0;
2620           (int)use_collective_io <= 1;
2621           (hbool_t)(use_collective_io++) ) {
2622 
2623         chunk_edge_size = 0;
2624         lower_dim_size_comp_test__run_test(chunk_edge_size,
2625                                            (hbool_t)use_collective_io,
2626                                            dset_type);
2627 
2628 
2629         chunk_edge_size = 5;
2630         lower_dim_size_comp_test__run_test(chunk_edge_size,
2631                                            (hbool_t)use_collective_io,
2632                                            dset_type);
2633     }
2634 
2635     return;
2636 
2637 } /* lower_dim_size_comp_test() */
2638 
2639 
2640 /*-------------------------------------------------------------------------
2641  * Function:	link_chunk_collective_io_test()
2642  *
2643  * Purpose:	Test to verify that an error in MPI type management in
2644  *		H5D_link_chunk_collective_io() has been corrected.
2645  *		In this bug, we used to free MPI types regardless of
2646  *		whether they were basic or derived.
2647  *
2648  *		This test is based on a bug report kindly provided by
2649  *		Rob Latham of the MPICH team and ANL.
2650  *
2651  *		The basic thrust of the test is to cause a process
2652  *		to participate in a collective I/O in which it:
2653  *
2654  *		1) Reads or writes exactly one chunk,
2655  *
2656  *		2) Has no in memory buffer for any other chunk.
2657  *
2658  *		The test differers from Rob Latham's bug report in
2659  *		that is runs with an arbitrary number of proceeses,
2660  *		and uses a 1 dimensional dataset.
2661  *
2662  * Return:	void
2663  *
2664  * Programmer:	JRM -- 12/16/09
2665  *
2666  * Modifications:
2667  *
2668  *-------------------------------------------------------------------------
2669  */
2670 
2671 #define LINK_CHUNK_COLLECTIVE_IO_TEST_CHUNK_SIZE	16
2672 
2673 void
link_chunk_collective_io_test(void)2674 link_chunk_collective_io_test(void)
2675 {
2676     /* const char *fcnName = "link_chunk_collective_io_test()"; */
2677     const char *filename;
2678     hbool_t    mis_match = FALSE;
2679     int	       i;
2680     int	       mrc;
2681     int        mpi_rank;
2682     int        mpi_size;
2683     MPI_Comm   mpi_comm = MPI_COMM_WORLD;
2684     MPI_Info   mpi_info = MPI_INFO_NULL;
2685     hsize_t    count[1] = {1};
2686     hsize_t    stride[1] = {2 * LINK_CHUNK_COLLECTIVE_IO_TEST_CHUNK_SIZE};
2687     hsize_t    block[1] = {LINK_CHUNK_COLLECTIVE_IO_TEST_CHUNK_SIZE};
2688     hsize_t    start[1];
2689     hsize_t    dims[1];
2690     hsize_t    chunk_dims[1] = {LINK_CHUNK_COLLECTIVE_IO_TEST_CHUNK_SIZE};
2691     herr_t     ret;            /* Generic return value */
2692     hid_t      file_id;
2693     hid_t      acc_tpl;
2694     hid_t      dset_id;
2695     hid_t      file_ds_sid;
2696     hid_t      write_mem_ds_sid;
2697     hid_t      read_mem_ds_sid;
2698     hid_t      ds_dcpl_id;
2699     hid_t      xfer_plist;
2700     double     diff;
2701     double     expected_value;
2702     double     local_data_written[LINK_CHUNK_COLLECTIVE_IO_TEST_CHUNK_SIZE];
2703     double     local_data_read[LINK_CHUNK_COLLECTIVE_IO_TEST_CHUNK_SIZE];
2704 
2705     MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
2706     MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
2707 
2708     HDassert( mpi_size > 0 );
2709 
2710     /* get the file name */
2711     filename = (const char *)GetTestParameters();
2712     HDassert( filename != NULL );
2713 
2714     /* setup file access template */
2715     acc_tpl = create_faccess_plist(mpi_comm, mpi_info, facc_type);
2716     VRFY((acc_tpl >= 0), "create_faccess_plist() succeeded");
2717 
2718     /* create the file collectively */
2719     file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, acc_tpl);
2720     VRFY((file_id >= 0), "H5Fcreate succeeded");
2721 
2722     MESG("File opened.");
2723 
2724     /* Release file-access template */
2725     ret = H5Pclose(acc_tpl);
2726     VRFY((ret >= 0), "H5Pclose(acc_tpl) succeeded");
2727 
2728     /* setup dims */
2729     dims[0] = ((hsize_t)mpi_size) * ((hsize_t)(LINK_CHUNK_COLLECTIVE_IO_TEST_CHUNK_SIZE));
2730 
2731     /* setup mem and file data spaces */
2732     write_mem_ds_sid = H5Screate_simple(1, chunk_dims, NULL);
2733     VRFY((write_mem_ds_sid != 0),
2734          "H5Screate_simple() write_mem_ds_sid succeeded");
2735 
2736     read_mem_ds_sid = H5Screate_simple(1, chunk_dims, NULL);
2737     VRFY((read_mem_ds_sid != 0),
2738          "H5Screate_simple() read_mem_ds_sid succeeded");
2739 
2740     file_ds_sid = H5Screate_simple(1, dims, NULL);
2741     VRFY((file_ds_sid != 0),
2742          "H5Screate_simple() file_ds_sid succeeded");
2743 
2744     /* setup data set creation property list */
2745     ds_dcpl_id = H5Pcreate(H5P_DATASET_CREATE);
2746     VRFY((ds_dcpl_id != FAIL), "H5Pcreate() ds_dcpl_id succeeded");
2747 
2748     ret = H5Pset_layout(ds_dcpl_id, H5D_CHUNKED);
2749     VRFY((ret != FAIL), "H5Pset_layout() ds_dcpl_id succeeded");
2750 
2751     ret = H5Pset_chunk(ds_dcpl_id, 1, chunk_dims);
2752     VRFY((ret != FAIL), "H5Pset_chunk() small_ds_dcpl_id succeeded");
2753 
2754     /* create the data set */
2755     dset_id = H5Dcreate2(file_id, "dataset", H5T_NATIVE_DOUBLE,
2756                          file_ds_sid, H5P_DEFAULT,
2757                          ds_dcpl_id, H5P_DEFAULT);
2758     VRFY((dset_id >= 0), "H5Dcreate2() dataset succeeded");
2759 
2760     /* close the dataset creation property list */
2761     ret = H5Pclose(ds_dcpl_id);
2762     VRFY((ret >= 0), "H5Pclose(ds_dcpl_id) succeeded");
2763 
2764     /* setup local data */
2765     expected_value = (double)(LINK_CHUNK_COLLECTIVE_IO_TEST_CHUNK_SIZE) *
2766                      (double)(mpi_rank);
2767     for ( i = 0; i < LINK_CHUNK_COLLECTIVE_IO_TEST_CHUNK_SIZE; i++ ) {
2768 
2769         local_data_written[i] = expected_value;
2770 	local_data_read[i] = 0.0;
2771 	expected_value += 1.0;
2772     }
2773 
2774     /* select the file and mem spaces */
2775     start[0] = (hsize_t)(mpi_rank * LINK_CHUNK_COLLECTIVE_IO_TEST_CHUNK_SIZE);
2776     ret = H5Sselect_hyperslab(file_ds_sid,
2777                               H5S_SELECT_SET,
2778                               start,
2779                               stride,
2780                               count,
2781                               block);
2782     VRFY((ret >= 0), "H5Sselect_hyperslab(file_ds_sid, set) suceeded");
2783 
2784     ret = H5Sselect_all(write_mem_ds_sid);
2785     VRFY((ret != FAIL), "H5Sselect_all(mem_ds_sid) succeeded");
2786 
2787     /* Note that we use NO SELECTION on the read memory dataspace */
2788 
2789     /* setup xfer property list */
2790     xfer_plist = H5Pcreate(H5P_DATASET_XFER);
2791     VRFY((xfer_plist >= 0), "H5Pcreate(H5P_DATASET_XFER) succeeded");
2792 
2793     ret = H5Pset_dxpl_mpio(xfer_plist, H5FD_MPIO_COLLECTIVE);
2794     VRFY((ret >= 0), "H5Pset_dxpl_mpio succeeded");
2795 
2796     /* write the data set */
2797     ret = H5Dwrite(dset_id,
2798                    H5T_NATIVE_DOUBLE,
2799                    write_mem_ds_sid,
2800                    file_ds_sid,
2801                    xfer_plist,
2802                    local_data_written);
2803 
2804     VRFY((ret >= 0), "H5Dwrite() dataset initial write succeeded");
2805 
2806     /* sync with the other processes before checking data */
2807     mrc = MPI_Barrier(MPI_COMM_WORLD);
2808     VRFY((mrc==MPI_SUCCESS), "Sync after dataset write");
2809 
2810     /* read this processes slice of the dataset back in */
2811     ret = H5Dread(dset_id,
2812                   H5T_NATIVE_DOUBLE,
2813                   read_mem_ds_sid,
2814                   file_ds_sid,
2815                   xfer_plist,
2816                   local_data_read);
2817     VRFY((ret >= 0), "H5Dread() dataset read succeeded");
2818 
2819     /* close the xfer property list */
2820     ret = H5Pclose(xfer_plist);
2821     VRFY((ret >= 0), "H5Pclose(xfer_plist) succeeded");
2822 
2823     /* verify the data */
2824     mis_match = FALSE;
2825     for ( i = 0; i < LINK_CHUNK_COLLECTIVE_IO_TEST_CHUNK_SIZE; i++ ) {
2826 
2827         diff = local_data_written[i] - local_data_read[i];
2828         diff = fabs(diff);
2829 
2830         if ( diff >= 0.001 ) {
2831 
2832             mis_match = TRUE;
2833         }
2834     }
2835     VRFY( (mis_match == FALSE), "dataset data good.");
2836 
2837     /* Close dataspaces */
2838     ret = H5Sclose(write_mem_ds_sid);
2839     VRFY((ret != FAIL), "H5Sclose(write_mem_ds_sid) succeeded");
2840 
2841     ret = H5Sclose(read_mem_ds_sid);
2842     VRFY((ret != FAIL), "H5Sclose(read_mem_ds_sid) succeeded");
2843 
2844     ret = H5Sclose(file_ds_sid);
2845     VRFY((ret != FAIL), "H5Sclose(file_ds_sid) succeeded");
2846 
2847     /* Close Dataset */
2848     ret = H5Dclose(dset_id);
2849     VRFY((ret != FAIL), "H5Dclose(dset_id) succeeded");
2850 
2851     /* close the file collectively */
2852     ret = H5Fclose(file_id);
2853     VRFY((ret != FAIL), "file close succeeded");
2854 
2855     return;
2856 
2857 } /* link_chunk_collective_io_test() */
2858 
2859