Skip to content

Commit 56591cf

Browse files
committed
print sizes of file datatype and buffer datatype
1 parent 2f62581 commit 56591cf

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

tests/large_dtype.c

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <stdio.h>
1919
#include <stdlib.h>
20+
#include <string.h> /* strcpy() */
2021
#include <unistd.h> /* getopt() */
2122
#include <assert.h>
2223

@@ -53,15 +54,15 @@ static void
5354
usage(char *argv0)
5455
{
5556
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"
5758
" [-h] Print this help\n"
5859
" [-v] verbose mode\n"
5960
" [-w] performs write only (default: both write and read)\n"
6061
" [-r] performs read only (default: both write and read)\n"
6162
" [-n num] number of global variables (default: %d)\n"
6263
" [-l num] length of dimensions X and Y each local variable (default: %d)\n"
6364
" [-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";
6566
fprintf(stderr, help, argv0, NVARS, LEN, GAP);
6667
}
6768

@@ -70,15 +71,15 @@ int main(int argc, char **argv)
7071
{
7172
char filename[512];
7273
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;
7475
int nvars, len, gap, psize[2], gsize[2], count[2], start[2];
7576
char *buf;
7677
MPI_File fh;
7778
MPI_Datatype subType, filetype, buftype;
7879
MPI_Status status;
7980
MPI_Offset fsize;
8081
int *array_of_blocklengths;
81-
MPI_Aint *array_of_displacements;
82+
MPI_Aint lb, extent, *array_of_displacements;
8283
MPI_Datatype *array_of_types;
8384
MPI_Request req[2];
8485

@@ -93,9 +94,10 @@ int main(int argc, char **argv)
9394
do_write = 1;
9495
do_read = 1;
9596
verbose = 0;
97+
filename[0] = '\0';
9698

9799
/* 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)
99101
switch(ret) {
100102
case 'v': verbose = 1;
101103
break;
@@ -109,15 +111,19 @@ int main(int argc, char **argv)
109111
break;
110112
case 'g': gap = atoi(optarg);
111113
break;
114+
case 'f': strcpy(filename, optarg);
115+
break;
112116
case 'h':
113117
default: if (rank==0) usage(argv[0]);
114118
MPI_Finalize();
115119
return 1;
116120
}
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+
}
121127

122128
array_of_blocklengths = (int*) malloc(sizeof(int) * nvars);
123129
array_of_displacements = (MPI_Aint*) malloc(sizeof(MPI_Aint) * nvars);
@@ -179,6 +185,12 @@ int main(int argc, char **argv)
179185
err = MPI_Type_free(&subType);
180186
CHECK_MPI_ERROR("MPI_Type_free");
181187

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+
182194
/* Create local buffer datatype: each 2D variable is of size len x len */
183195
gsize[0] = len;
184196
gsize[1] = len;
@@ -214,6 +226,12 @@ int main(int argc, char **argv)
214226
free(array_of_displacements);
215227
free(array_of_types);
216228

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+
217235
/* allocate a local buffer */
218236
buf_len = (size_t)nvars * len * len;
219237
buf = (char*) malloc(buf_len);

0 commit comments

Comments
 (0)