17
17
18
18
#include <stdio.h>
19
19
#include <stdlib.h>
20
+ #include <string.h> /* strcpy() */
20
21
#include <unistd.h> /* getopt() */
21
22
#include <assert.h>
22
23
@@ -53,15 +54,15 @@ static void
53
54
usage (char * argv0 )
54
55
{
55
56
char * help =
56
- "Usage: %s [-hvwr | -n num | -l num | -g num | file_name] \n"
57
+ "Usage: %s [-hvwr | -n num | -l num | -g num ] -f file_name\n"
57
58
" [-h] Print this help\n"
58
59
" [-v] verbose mode\n"
59
60
" [-w] performs write only (default: both write and read)\n"
60
61
" [-r] performs read only (default: both write and read)\n"
61
62
" [-n num] number of global variables (default: %d)\n"
62
63
" [-l num] length of dimensions X and Y each local variable (default: %d)\n"
63
64
" [-g num] gap at the end of each dimension (default: %d)\n"
64
- " [ file_name] output file name\n" ;
65
+ " -f file_name: output file name\n" ;
65
66
fprintf (stderr , help , argv0 , NVARS , LEN , GAP );
66
67
}
67
68
@@ -70,15 +71,15 @@ int main(int argc, char **argv)
70
71
{
71
72
char filename [512 ];
72
73
size_t i , buf_len ;
73
- int ret , err , rank , verbose , omode , nprocs , do_read , do_write ;
74
+ int ret , err , rank , verbose , omode , nprocs , do_read , do_write , type_size ;
74
75
int nvars , len , gap , psize [2 ], gsize [2 ], count [2 ], start [2 ];
75
76
char * buf ;
76
77
MPI_File fh ;
77
78
MPI_Datatype subType , filetype , buftype ;
78
79
MPI_Status status ;
79
80
MPI_Offset fsize ;
80
81
int * array_of_blocklengths ;
81
- MPI_Aint * array_of_displacements ;
82
+ MPI_Aint lb , extent , * array_of_displacements ;
82
83
MPI_Datatype * array_of_types ;
83
84
MPI_Request req [2 ];
84
85
@@ -93,9 +94,10 @@ int main(int argc, char **argv)
93
94
do_write = 1 ;
94
95
do_read = 1 ;
95
96
verbose = 0 ;
97
+ filename [0 ] = '\0' ;
96
98
97
99
/* get command-line arguments */
98
- while ((ret = getopt (argc , argv , "hvwrn:l:g:" )) != EOF )
100
+ while ((ret = getopt (argc , argv , "hvwrn:l:g:f: " )) != EOF )
99
101
switch (ret ) {
100
102
case 'v' : verbose = 1 ;
101
103
break ;
@@ -109,15 +111,19 @@ int main(int argc, char **argv)
109
111
break ;
110
112
case 'g' : gap = atoi (optarg );
111
113
break ;
114
+ case 'f' : strcpy (filename , optarg );
115
+ break ;
112
116
case 'h' :
113
117
default : if (rank == 0 ) usage (argv [0 ]);
114
118
MPI_Finalize ();
115
119
return 1 ;
116
120
}
117
- if (argv [optind ] == NULL )
118
- sprintf (filename , "%s.out" , argv [0 ]);
119
- else
120
- snprintf (filename , 256 , "%s" , argv [optind ]);
121
+
122
+ if (filename [0 ] == '\0' ) {
123
+ if (rank == 0 ) usage (argv [0 ]);
124
+ MPI_Finalize ();
125
+ return 1 ;
126
+ }
121
127
122
128
array_of_blocklengths = (int * ) malloc (sizeof (int ) * nvars );
123
129
array_of_displacements = (MPI_Aint * ) malloc (sizeof (MPI_Aint ) * nvars );
@@ -179,6 +185,12 @@ int main(int argc, char **argv)
179
185
err = MPI_Type_free (& subType );
180
186
CHECK_MPI_ERROR ("MPI_Type_free" );
181
187
188
+ MPI_Type_size (filetype , & type_size );
189
+ lb = 0 ;
190
+ MPI_Type_get_extent (filetype , & lb , & extent );
191
+ if (verbose && rank == 0 )
192
+ printf ("file type size = %d extent = %ld\n" , type_size , extent );
193
+
182
194
/* Create local buffer datatype: each 2D variable is of size len x len */
183
195
gsize [0 ] = len ;
184
196
gsize [1 ] = len ;
@@ -214,6 +226,12 @@ int main(int argc, char **argv)
214
226
free (array_of_displacements );
215
227
free (array_of_types );
216
228
229
+ MPI_Type_size (buftype , & type_size );
230
+ lb = 0 ;
231
+ MPI_Type_get_extent (buftype , & lb , & extent );
232
+ if (verbose && rank == 0 )
233
+ printf ("buffer type size = %d extent = %ld\n" , type_size , extent );
234
+
217
235
/* allocate a local buffer */
218
236
buf_len = (size_t )nvars * len * len ;
219
237
buf = (char * ) malloc (buf_len );
0 commit comments