| 1 |
/* |
| 2 |
* Copyright(C) 1999-2024 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
|
| 9 |
#ifdef PARALLEL_AWARE_EXODUS |
| 10 |
#include <mpi.h> |
| 11 |
#else |
| 12 |
#include <time.h> |
| 13 |
#endif |
| 14 |
|
| 15 |
#include <assert.h> |
| 16 |
#include <float.h> |
| 17 |
#include <limits.h> |
| 18 |
#include <stdbool.h> |
| 19 |
#include <stdio.h> |
| 20 |
#include <stdlib.h> |
| 21 |
#include <string.h> |
| 22 |
#include <sys/stat.h> |
| 23 |
#include <sys/types.h> |
| 24 |
#include <unistd.h> |
| 25 |
|
| 26 |
#if defined(_MSC_VER) |
| 27 |
#define NOMINMAX |
| 28 |
#include <windows.h> |
| 29 |
#define sleep(a) Sleep(a * 1000) |
| 30 |
#endif |
| 31 |
|
| 32 |
#include "exodusII.h" |
| 33 |
|
| 34 |
#define DEFAULT_NUM_FIELDS 0 |
| 35 |
#define DEFAULT_FILE_NAME "mesh" |
| 36 |
#define DEFAULT_NUM_ITERATIONS 1 |
| 37 |
#define EXODUS_FILE_TYPE "e" |
| 38 |
#define MBYTES (1024 * 1024) |
| 39 |
#define MAX_STRING_LEN 128 |
| 40 |
#define NUM_NODES_PER_ELEM 8 |
| 41 |
#define WRITE_FILE_TYPE "new" |
| 42 |
#define EBLK_ID 100000 |
| 43 |
|
| 44 |
/* |
| 45 |
* Prototypes |
| 46 |
*/ |
| 47 |
|
| 48 |
typedef double realtyp; |
| 49 |
|
| 50 |
void get_file_name(const char *base, const char *ext, int rank, int nprocs, const char *other, |
| 51 |
char *output); |
| 52 |
|
| 53 |
int parse_input(int argc, char *argv[], bool *exodus, bool *close_files, char *file_name, |
| 54 |
int *num_nodal_fields, int *num_global_fields, int *num_element_fields, |
| 55 |
int *files_per_domain, int *num_iterations, int *sleep_time); |
| 56 |
|
| 57 |
int read_exo_mesh(char *file_name, int rank, int *num_dim, int num_domains, int *num_nodal_fields, |
| 58 |
int *num_global_fields, int *num_element_fields, int *num_timesteps, |
| 59 |
int sleep_time, int num_iterations, int *num_nodes, int **node_map, |
| 60 |
int *num_elems, int **elem_map, realtyp **x_coords, realtyp **y_coords, |
| 61 |
realtyp **z_coords, int **connect); |
| 62 |
|
| 63 |
int write_exo_mesh(char *file_name, int rank, int num_dim, int num_domains, int num_nodal_fields, |
| 64 |
int num_global_fields, int num_element_fields, int num_timesteps, |
| 65 |
int files_per_domain, int sleep_time, int num_iterations, int num_nodes, |
| 66 |
int *node_map, int num_elems, int *elem_map, realtyp *x_coords, |
| 67 |
realtyp *y_coords, realtyp *z_coords, int *connect, int close_files); |
| 68 |
|
| 69 |
double my_timer(void) |
| 70 |
{ |
| 71 |
#ifdef PARALLEL_AWARE_EXODUS |
| 72 |
double t1 = MPI_Wtime(); |
| 73 |
#else |
| 74 |
clock_t ctime = clock(); |
| 75 |
double t1 = ctime / (double)CLOCKS_PER_SEC; |
| 76 |
#endif |
| 77 |
return t1; |
| 78 |
} |
| 79 |
|
| 80 |
/*********************************************************************** |
| 81 |
* |
| 82 |
* Main function |
| 83 |
* |
| 84 |
***********************************************************************/ |
| 85 |
|
| 86 |
int main(int argc, char **argv) |
| 87 |
{ |
| 88 |
int rank, num_domains; |
| 89 |
int quit = false; |
| 90 |
int loc_num_nodes, loc_num_elems; |
| 91 |
int *loc_connect = NULL; |
| 92 |
|
| 93 |
#ifdef PARALLEL_AWARE_EXODUS |
| 94 |
MPI_Info mpi_info_object = MPI_INFO_NULL; /* Copy of MPI Info object. */ |
| 95 |
#endif |
| 96 |
int *elem_map = NULL; |
| 97 |
bool exodus = true; /* true, perform EXODUS benchmark; false don't */ |
| 98 |
bool close_files = false; |
| 99 |
char file_name[MAX_STRING_LEN] = DEFAULT_FILE_NAME; /* Input file name. */ |
| 100 |
int num_nodal_fields = DEFAULT_NUM_FIELDS; |
| 101 |
int num_global_fields = DEFAULT_NUM_FIELDS; |
| 102 |
int num_element_fields = DEFAULT_NUM_FIELDS; |
| 103 |
int num_timesteps = 0; |
| 104 |
int sleep_time = 0; |
| 105 |
int files_per_domain = 1; |
| 106 |
int num_iterations = DEFAULT_NUM_ITERATIONS; |
| 107 |
#ifdef PARALLEL_AWARE_EXODUS |
| 108 |
static const char *hints[] = {/* List of MPI Info hints that if defined in */ |
| 109 |
"cb_buffer_size", /* the environment process 0, will be used to */ |
| 110 |
"cb_nodes", /* set key/value pairs in the MPI */ |
| 111 |
"ind_rd_buffer_size", /* Info object. */ |
| 112 |
"ind_wr_buffer_size", "cb_config_list", "romio_cb_read", |
| 113 |
"romio_cb_write", "romio_ds_read", "romio_ds_write", |
| 114 |
"romio_no_indep_rw"}; |
| 115 |
char key_name[MAX_STRING_LEN]; /* MPI Info object key name. */ |
| 116 |
int key; /* MPI Info object key index. */ |
| 117 |
int key_exists; /* true, if the key exists in the MPI Info */ |
| 118 |
const int nhints = 10; /* Number of items in hints list. */ |
| 119 |
int nkeys; /* Number of keys in a MPI Info object. */ |
| 120 |
char value[MAX_STRING_LEN]; /* Value of a key/value pair in a MPI Info */ |
| 121 |
#endif |
| 122 |
/* object. */ |
| 123 |
realtyp *x_coords = NULL; |
| 124 |
realtyp *y_coords = NULL; |
| 125 |
realtyp *z_coords = NULL; |
| 126 |
int ndim; |
| 127 |
|
| 128 |
/* |
| 129 |
* Initialize Stuff |
| 130 |
*/ |
| 131 |
|
| 132 |
ex_opts(EX_VERBOSE | EX_ABORT); |
| 133 |
|
| 134 |
#ifdef PARALLEL_AWARE_EXODUS |
| 135 |
MPI_Init(&argc, &argv); |
| 136 |
MPI_Comm_rank(MPI_COMM_WORLD, &rank); |
| 137 |
MPI_Comm_size(MPI_COMM_WORLD, &num_domains); |
| 138 |
#else |
| 139 |
rank = 0; |
| 140 |
num_domains = 1; |
| 141 |
#endif |
| 142 |
/* |
| 143 |
* Processor 0: parse the command line arguments. |
| 144 |
*/ |
| 145 |
|
| 146 |
if (rank == 0) { |
| 147 |
quit = (1 == parse_input(argc, argv, &exodus, &close_files, file_name, &num_nodal_fields, |
| 148 |
&num_global_fields, &num_element_fields, &files_per_domain, |
| 149 |
&num_iterations, &sleep_time)); |
| 150 |
} |
| 151 |
|
| 152 |
/* |
| 153 |
* Broadcast Input |
| 154 |
*/ |
| 155 |
|
| 156 |
#ifdef PARALLEL_AWARE_EXODUS |
| 157 |
MPI_Bcast(&quit, 1, MPI_INT, 0, MPI_COMM_WORLD); |
| 158 |
#endif |
| 159 |
|
| 160 |
if (quit) { |
| 161 |
#ifdef PARALLEL_AWARE_EXODUS |
| 162 |
MPI_Finalize(); |
| 163 |
#endif |
| 164 |
exit(0); |
| 165 |
} |
| 166 |
|
| 167 |
#ifdef PARALLEL_AWARE_EXODUS |
| 168 |
MPI_Bcast(&exodus, 1, MPI_INT, 0, MPI_COMM_WORLD); |
| 169 |
MPI_Bcast(&close_files, 1, MPI_INT, 0, MPI_COMM_WORLD); |
| 170 |
MPI_Bcast(file_name, MAX_STRING_LEN, MPI_CHAR, 0, MPI_COMM_WORLD); |
| 171 |
MPI_Bcast(&num_nodal_fields, 1, MPI_INT, 0, MPI_COMM_WORLD); |
| 172 |
MPI_Bcast(&num_global_fields, 1, MPI_INT, 0, MPI_COMM_WORLD); |
| 173 |
MPI_Bcast(&num_element_fields, 1, MPI_INT, 0, MPI_COMM_WORLD); |
| 174 |
MPI_Bcast(&num_iterations, 1, MPI_INT, 0, MPI_COMM_WORLD); |
| 175 |
MPI_Bcast(&files_per_domain, 1, MPI_INT, 0, MPI_COMM_WORLD); |
| 176 |
|
| 177 |
/* env_mpi_hints( nhints, hints ); */ |
| 178 |
{ |
| 179 |
char *env; /* Contents of environmental variable. */ |
| 180 |
int hint; /* ROMIO hint index. */ |
| 181 |
char hint_value[MAX_STRING_LEN]; /* ROMIO hint value. */ |
| 182 |
|
| 183 |
MPI_Comm_rank(MPI_COMM_WORLD, &rank); |
| 184 |
/* The "value" of the hint is obtained from the environment of |
| 185 |
* processor 0 only. The value is broadcast to the other |
| 186 |
* processors. |
| 187 |
*/ |
| 188 |
for (hint = 0; hint < nhints; hint++) { |
| 189 |
if (rank == 0) { |
| 190 |
env = getenv(hints[hint]); |
| 191 |
if (env != NULL) |
| 192 |
ex_copy_string(hint_value, env, MAX_STRING_LEN); |
| 193 |
else |
| 194 |
hint_value[0] = 0; |
| 195 |
} |
| 196 |
MPI_Bcast(hint_value, MAX_STRING_LEN, MPI_CHAR, 0, MPI_COMM_WORLD); |
| 197 |
if (hint_value[0]) { |
| 198 |
if (mpi_info_object == MPI_INFO_NULL) |
| 199 |
MPI_Info_create(&mpi_info_object); |
| 200 |
MPI_Info_set(mpi_info_object, hints[hint], hint_value); |
| 201 |
} |
| 202 |
} |
| 203 |
} |
| 204 |
#endif |
| 205 |
|
| 206 |
if (rank == 0) { |
| 207 |
fprintf(stderr, "\nEXODUSII 3D Benchmark\n\n"); |
| 208 |
fprintf(stderr, " Number of Domains\t\t%8d\n", num_domains); |
| 209 |
fprintf(stderr, " Number of Files/Domain\t%8d\n", files_per_domain); |
| 210 |
fprintf(stderr, " Number of Iterations\t\t%8d\n", num_iterations); |
| 211 |
|
| 212 |
#ifdef PARALLEL_AWARE_EXODUS |
| 213 |
if (mpi_info_object != MPI_INFO_NULL) { |
| 214 |
fprintf(stderr, " MPI Hint Status\n"); |
| 215 |
|
| 216 |
MPI_Info_get_nkeys(mpi_info_object, &nkeys); |
| 217 |
|
| 218 |
for (key = 0; key < nkeys; key++) { |
| 219 |
MPI_Info_get_nthkey(mpi_info_object, key, key_name); |
| 220 |
MPI_Info_get(mpi_info_object, key_name, MAX_STRING_LEN, value, &key_exists); |
| 221 |
|
| 222 |
fprintf(stderr, " %s\t\t\t%s\n", key_name, value); |
| 223 |
} |
| 224 |
|
| 225 |
MPI_Info_free(&mpi_info_object); |
| 226 |
} |
| 227 |
else |
| 228 |
fprintf(stderr, " MPI Hint Status\tMPI_INFO_NULL\n"); |
| 229 |
#endif |
| 230 |
} |
| 231 |
|
| 232 |
if (exodus) { |
| 233 |
int *node_map = NULL; |
| 234 |
if (0 == read_exo_mesh(file_name, rank, &ndim, num_domains, &num_nodal_fields, |
| 235 |
&num_global_fields, &num_element_fields, &num_timesteps, sleep_time, |
| 236 |
num_iterations, &loc_num_nodes, &node_map, &loc_num_elems, &elem_map, |
| 237 |
&x_coords, &y_coords, &z_coords, &loc_connect)) { |
| 238 |
write_exo_mesh(file_name, rank, ndim, num_domains, num_nodal_fields, num_global_fields, |
| 239 |
num_element_fields, num_timesteps, files_per_domain, sleep_time, |
| 240 |
num_iterations, loc_num_nodes, node_map, loc_num_elems, elem_map, x_coords, |
| 241 |
y_coords, z_coords, loc_connect, close_files); |
| 242 |
} |
| 243 |
free(elem_map); |
| 244 |
free(loc_connect); |
| 245 |
free(node_map); |
| 246 |
free(x_coords); |
| 247 |
free(y_coords); |
| 248 |
free(z_coords); |
| 249 |
} |
| 250 |
#ifdef PARALLEL_AWARE_EXODUS |
| 251 |
MPI_Finalize(); |
| 252 |
#endif |
| 253 |
return 0; |
| 254 |
} |
| 255 |
|
| 256 |
/*********************************************************************** |
| 257 |
* |
| 258 |
* Parse Input |
| 259 |
* |
| 260 |
***********************************************************************/ |
| 261 |
|
| 262 |
int parse_input(int argc, char *argv[], bool *exodus, bool *close_files, char *file_name, |
| 263 |
int *num_nodal_fields, int *num_global_fields, int *num_element_fields, |
| 264 |
int *files_per_domain, int *num_iterations, int *sleep_time) |
| 265 |
{ |
| 266 |
int arg = 0; /* Argument index. */ |
| 267 |
|
| 268 |
while (++arg < argc) { |
| 269 |
if (strcmp("-c", argv[arg]) == 0) { |
| 270 |
if (++arg < argc) { |
| 271 |
*num_nodal_fields = strtol(argv[arg], NULL, 10); |
| 272 |
} |
| 273 |
} |
| 274 |
else if (strcmp("-nv", argv[arg]) == 0) { |
| 275 |
if (++arg < argc) { |
| 276 |
*num_nodal_fields = strtol(argv[arg], NULL, 10); |
| 277 |
} |
| 278 |
} |
| 279 |
else if (strcmp("-gv", argv[arg]) == 0) { |
| 280 |
if (++arg < argc) { |
| 281 |
*num_global_fields = strtol(argv[arg], NULL, 10); |
| 282 |
} |
| 283 |
} |
| 284 |
else if (strcmp("-ev", argv[arg]) == 0) { |
| 285 |
if (++arg < argc) { |
| 286 |
*num_element_fields = strtol(argv[arg], NULL, 10); |
| 287 |
} |
| 288 |
} |
| 289 |
else if (strcmp("-f", argv[arg]) == 0) { |
| 290 |
if (++arg < argc) { |
| 291 |
ex_copy_string(file_name, argv[arg], MAX_STRING_LEN); |
| 292 |
} |
| 293 |
} |
| 294 |
else if (strcmp("-M", argv[arg]) == 0) { |
| 295 |
if (++arg < argc) { |
| 296 |
*files_per_domain = strtol(argv[arg], NULL, 10); |
| 297 |
} |
| 298 |
} |
| 299 |
else if (strcmp("-i", argv[arg]) == 0) { |
| 300 |
if (++arg < argc) { |
| 301 |
*num_iterations = strtol(argv[arg], NULL, 10); |
| 302 |
} |
| 303 |
} |
| 304 |
else if (strcmp("-w", argv[arg]) == 0) { |
| 305 |
if (++arg < argc) { |
| 306 |
*sleep_time = strtol(argv[arg], NULL, 10); |
| 307 |
} |
| 308 |
} |
| 309 |
else if (strcmp("-x", argv[arg]) == 0) { |
| 310 |
*exodus = true; |
| 311 |
} |
| 312 |
else if (strcmp("-C", argv[arg]) == 0) { |
| 313 |
*close_files = true; |
| 314 |
} |
| 315 |
else if ((strcmp("-h", argv[arg]) == 0) || (strcmp("-u", argv[arg]) == 0)) { |
| 316 |
fprintf(stderr, " \n"); |
| 317 |
fprintf(stderr, "NAME \n"); |
| 318 |
fprintf(stderr, " \n"); |
| 319 |
fprintf(stderr, "rd_wt_mesh - reads and writes a mesh in parallel for performance\n"); |
| 320 |
fprintf(stderr, " benchmarking. \n"); |
| 321 |
fprintf(stderr, " \n"); |
| 322 |
fprintf(stderr, "SYNOPSIS \n"); |
| 323 |
fprintf(stderr, " \n"); |
| 324 |
fprintf(stderr, "rd_wt_mesh [-S] [-c fields] [-f file_name] [-h] [-i iterations] \n"); |
| 325 |
fprintf(stderr, " [-s] [-u] [-x] [-w] \n"); |
| 326 |
fprintf(stderr, " \n"); |
| 327 |
fprintf(stderr, "DESCRIPTION \n"); |
| 328 |
fprintf(stderr, " \n"); |
| 329 |
fprintf(stderr, "This program reads and writes a mesh in parallel for performance\n"); |
| 330 |
fprintf(stderr, "benchmarking. The first Exodus database file read by \n"); |
| 331 |
fprintf(stderr, "this program is created by create_mesh. Performance summaries \n"); |
| 332 |
fprintf(stderr, "are written to stdout. \n"); |
| 333 |
fprintf(stderr, " \n"); |
| 334 |
fprintf(stderr, "OPTIONS \n"); |
| 335 |
fprintf(stderr, " \n"); |
| 336 |
fprintf(stderr, "-c fields number of fields. Default: %d \n", |
| 337 |
DEFAULT_NUM_FIELDS); |
| 338 |
fprintf(stderr, "-f file_name file name prefix for all read files: \n"); |
| 339 |
fprintf(stderr, " \n"); |
| 340 |
fprintf(stderr, " 'file_name'%s.nproc.rank [EXODUS II file] \n", |
| 341 |
EXODUS_FILE_TYPE); |
| 342 |
fprintf(stderr, " \n"); |
| 343 |
fprintf(stderr, " Default: %s \n", |
| 344 |
DEFAULT_FILE_NAME); |
| 345 |
fprintf(stderr, "-M files number of files/domain. Default: 1 \n"); |
| 346 |
fprintf(stderr, "-h display help/usage information \n"); |
| 347 |
fprintf(stderr, "-i iterations number of iterations. Default: %d \n", |
| 348 |
DEFAULT_NUM_ITERATIONS); |
| 349 |
fprintf(stderr, "-C minimize open files. \n"); |
| 350 |
fprintf(stderr, "-u display help/usage information \n"); |
| 351 |
fprintf(stderr, "-w time wait (sleep) specified time between timesteps.\n"); |
| 352 |
return 1; |
| 353 |
} |
| 354 |
else { |
| 355 |
fprintf(stderr, "Unknown option: %s\n", argv[arg]); |
| 356 |
fprintf(stderr, "Enter rd_wt_mesh -h for description of valid options.\n"); |
| 357 |
|
| 358 |
return 1; |
| 359 |
} |
| 360 |
} |
| 361 |
return 0; |
| 362 |
} |
| 363 |
|
| 364 |
/*********************************************************************** |
| 365 |
***********************************************************************/ |
| 366 |
int read_exo_mesh(char *file_name, int rank, int *num_dim, int num_domains, int *num_nodal_fields, |
| 367 |
int *num_global_fields, int *num_element_fields, int *num_timesteps, |
| 368 |
int sleep_time, int num_iterations, int *num_nodes, int **node_map, |
| 369 |
int *num_elems, int **elem_map, realtyp **x_coords, realtyp **y_coords, |
| 370 |
realtyp **z_coords, int **connect) |
| 371 |
|
| 372 |
{ |
| 373 |
int CPU_word_size = sizeof(realtyp); |
| 374 |
int IO_word_size = 0; |
| 375 |
int exoid, err, num_elem_blk, num_node_sets, num_side_sets; |
| 376 |
int num_nodes_per_elem, num_attrs, num_vars, i, iter; |
| 377 |
size_t len_connect; |
| 378 |
size_t file_size; |
| 379 |
|
| 380 |
struct stat file_status; |
| 381 |
size_t glob_file_size; |
| 382 |
size_t glob_raw_data_vol; |
| 383 |
size_t raw_data_vol = 0; |
| 384 |
|
| 385 |
float version; |
| 386 |
realtyp *globals = NULL; |
| 387 |
|
| 388 |
double tstart, tend, t_tmp1, t_tmp2; |
| 389 |
double raw_read_time, max_raw_read_time = 0.0, min_raw_read_time = DBL_MAX; |
| 390 |
double cum_raw_read_time = 0.0; |
| 391 |
double total_time, max_total_time = 0.0, min_total_time = DBL_MAX; |
| 392 |
double raw_sleep_time = 0.0; |
| 393 |
double cum_total_time = 0.0; |
| 394 |
|
| 395 |
char tmp_name[MAX_STRING_LEN], title[MAX_STRING_LEN + 1]; |
| 396 |
char type[MAX_STRING_LEN + 1]; |
| 397 |
|
| 398 |
for (iter = 0; iter < num_iterations; iter++) { |
| 399 |
/* open the EXODUS file */ |
| 400 |
get_file_name(file_name, EXODUS_FILE_TYPE, rank, num_domains, NULL, tmp_name); |
| 401 |
exoid = ex_open(tmp_name, EX_READ, &CPU_word_size, &IO_word_size, &version); |
| 402 |
|
| 403 |
if (exoid < 0) { |
| 404 |
printf("after ex_open\n"); |
| 405 |
return 1; |
| 406 |
} |
| 407 |
|
| 408 |
raw_read_time = 0.0; |
| 409 |
raw_data_vol = 0; |
| 410 |
|
| 411 |
tstart = my_timer(); |
| 412 |
|
| 413 |
err = ex_get_init(exoid, title, num_dim, num_nodes, num_elems, &num_elem_blk, &num_node_sets, |
| 414 |
&num_side_sets); |
| 415 |
|
| 416 |
if (err) { |
| 417 |
printf("after ex_get_init, error = %d\n", err); |
| 418 |
ex_close(exoid); |
| 419 |
return 1; |
| 420 |
} |
| 421 |
|
| 422 |
len_connect = (size_t)NUM_NODES_PER_ELEM * (*num_elems); |
| 423 |
|
| 424 |
/* malloc things we need */ |
| 425 |
if (iter == 0) { |
| 426 |
*elem_map = malloc(sizeof(int) * (*num_elems)); |
| 427 |
assert(elem_map); |
| 428 |
*connect = malloc(sizeof(int) * len_connect); |
| 429 |
assert(connect); |
| 430 |
*node_map = malloc(sizeof(int) * (*num_nodes)); |
| 431 |
assert(node_map); |
| 432 |
|
| 433 |
*x_coords = malloc(sizeof(realtyp) * (*num_nodes)); |
| 434 |
assert(x_coords); |
| 435 |
*y_coords = malloc(sizeof(realtyp) * (*num_nodes)); |
| 436 |
assert(y_coords); |
| 437 |
*z_coords = malloc(sizeof(realtyp) * (*num_nodes)); |
| 438 |
assert(z_coords); |
| 439 |
} |
| 440 |
|
| 441 |
t_tmp1 = my_timer(); |
| 442 |
|
| 443 |
err = ex_get_coord(exoid, *x_coords, *y_coords, *z_coords); |
| 444 |
|
| 445 |
t_tmp2 = my_timer(); |
| 446 |
|
| 447 |
raw_read_time += t_tmp2 - t_tmp1; |
| 448 |
raw_data_vol += sizeof(realtyp) * 3 * (*num_nodes); |
| 449 |
|
| 450 |
if (err) { |
| 451 |
printf("after ex_get_coord, error = %d\n", err); |
| 452 |
ex_close(exoid); |
| 453 |
return 1; |
| 454 |
} |
| 455 |
|
| 456 |
err = ex_get_block(exoid, EX_ELEM_BLOCK, EBLK_ID, type, num_elems, &num_nodes_per_elem, 0, 0, |
| 457 |
&num_attrs); |
| 458 |
|
| 459 |
if (err) { |
| 460 |
printf("after ex_get_elem_block, error = %d\n", err); |
| 461 |
ex_close(exoid); |
| 462 |
return 1; |
| 463 |
} |
| 464 |
|
| 465 |
t_tmp1 = my_timer(); |
| 466 |
|
| 467 |
err = ex_get_conn(exoid, EX_ELEM_BLOCK, EBLK_ID, *connect, 0, 0); |
| 468 |
|
| 469 |
t_tmp2 = my_timer(); |
| 470 |
|
| 471 |
raw_read_time += t_tmp2 - t_tmp1; |
| 472 |
raw_data_vol += sizeof(int) * len_connect; |
| 473 |
|
| 474 |
if (err) { |
| 475 |
printf("after ex_get_elem_conn, error = %d\n", err); |
| 476 |
ex_close(exoid); |
| 477 |
return 1; |
| 478 |
} |
| 479 |
|
| 480 |
/* read element and node maps */ |
| 481 |
t_tmp1 = my_timer(); |
| 482 |
|
| 483 |
ex_get_id_map(exoid, EX_NODE_MAP, *node_map); |
| 484 |
t_tmp2 = my_timer(); |
| 485 |
raw_data_vol += sizeof(int) * (*num_nodes); |
| 486 |
raw_read_time += t_tmp2 - t_tmp1; |
| 487 |
|
| 488 |
t_tmp1 = my_timer(); |
| 489 |
ex_get_id_map(exoid, EX_ELEM_MAP, *elem_map); |
| 490 |
t_tmp2 = my_timer(); |
| 491 |
raw_data_vol += sizeof(int) * (*num_elems); |
| 492 |
raw_read_time += t_tmp2 - t_tmp1; |
| 493 |
|
| 494 |
/* read results variables */ |
| 495 |
err = ex_get_variable_param(exoid, EX_NODAL, &num_vars); |
| 496 |
|
| 497 |
if (err) { |
| 498 |
printf("after ex_get_variable_param, error = %d\n", err); |
| 499 |
ex_close(exoid); |
| 500 |
return 1; |
| 501 |
} |
| 502 |
*num_nodal_fields = num_vars; |
| 503 |
|
| 504 |
err = ex_get_variable_param(exoid, EX_GLOBAL, &num_vars); |
| 505 |
if (err) { |
| 506 |
printf("after ex_get_variable_param, error = %d\n", err); |
| 507 |
ex_close(exoid); |
| 508 |
return 1; |
| 509 |
} |
| 510 |
*num_global_fields = num_vars; |
| 511 |
if (*num_global_fields > 0) { |
| 512 |
globals = malloc(*num_global_fields * sizeof(realtyp)); |
| 513 |
assert(globals); |
| 514 |
} |
| 515 |
|
| 516 |
err = ex_get_variable_param(exoid, EX_ELEM_BLOCK, &num_vars); |
| 517 |
if (err) { |
| 518 |
printf("after ex_get_variable_param, error = %d\n", err); |
| 519 |
ex_close(exoid); |
| 520 |
if (globals) { |
| 521 |
free(globals); |
| 522 |
} |
| 523 |
return 1; |
| 524 |
} |
| 525 |
*num_element_fields = num_vars; |
| 526 |
|
| 527 |
/* read number of timesteps */ |
| 528 |
*num_timesteps = ex_inquire_int(exoid, EX_INQ_TIME); |
| 529 |
if (rank == 0) { |
| 530 |
fprintf(stderr, " Number of Elements\t\t%8d (per domain)\n", *num_elems); |
| 531 |
fprintf(stderr, " Number of Nodes\t\t%8d (per domain)\n", *num_nodes); |
| 532 |
fprintf(stderr, " Number of Global Fields\t%8d\n", *num_global_fields); |
| 533 |
fprintf(stderr, " Number of Nodal Fields\t%8d\n", *num_nodal_fields); |
| 534 |
fprintf(stderr, " Number of Element Fields\t%8d\n", *num_element_fields); |
| 535 |
fprintf(stderr, " Number of Timesteps\t\t%8d\n", *num_timesteps); |
| 536 |
if (sleep_time > 0) { |
| 537 |
fprintf(stderr, " Timestep Sleep time\t%8d\n", sleep_time); |
| 538 |
} |
| 539 |
} |
| 540 |
|
| 541 |
if (*num_nodal_fields + *num_global_fields + *num_element_fields > 0) { |
| 542 |
int t; |
| 543 |
|
| 544 |
if (rank == 0) { |
| 545 |
fprintf(stderr, "\nReading Timestep: "); |
| 546 |
} |
| 547 |
for (t = 0; t < *num_timesteps; t++) { |
| 548 |
if (sleep_time > 0) { |
| 549 |
t_tmp1 = my_timer(); |
| 550 |
sleep(sleep_time); |
| 551 |
t_tmp2 = my_timer(); |
| 552 |
raw_sleep_time += t_tmp2 - t_tmp1; |
| 553 |
} |
| 554 |
if (rank == 0) { |
| 555 |
fprintf(stderr, " %d,", t + 1); |
| 556 |
} |
| 557 |
|
| 558 |
for (i = 1; i <= *num_nodal_fields; i++) { |
| 559 |
t_tmp1 = my_timer(); |
| 560 |
err = ex_get_var(exoid, t + 1, EX_NODAL, i, 0, *num_nodes, *x_coords); |
| 561 |
t_tmp2 = my_timer(); |
| 562 |
|
| 563 |
raw_read_time += t_tmp2 - t_tmp1; |
| 564 |
raw_data_vol += sizeof(realtyp) * (*num_nodes); |
| 565 |
|
| 566 |
if (err) { |
| 567 |
printf("after ex_get_nodal_var, error = %d\n", err); |
| 568 |
ex_close(exoid); |
| 569 |
return 1; |
| 570 |
} |
| 571 |
} |
| 572 |
|
| 573 |
t_tmp1 = my_timer(); |
| 574 |
err = ex_get_var(exoid, t + 1, EX_GLOBAL, 0, 0, *num_global_fields, globals); |
| 575 |
t_tmp2 = my_timer(); |
| 576 |
|
| 577 |
raw_read_time += t_tmp2 - t_tmp1; |
| 578 |
raw_data_vol += sizeof(realtyp) * *num_global_fields; |
| 579 |
|
| 580 |
if (err) { |
| 581 |
printf("after ex_get_glob_vars, error = %d\n", err); |
| 582 |
ex_close(exoid); |
| 583 |
return 1; |
| 584 |
} |
| 585 |
|
| 586 |
for (i = 1; i <= *num_element_fields; i++) { |
| 587 |
t_tmp1 = my_timer(); |
| 588 |
err = ex_get_var(exoid, t + 1, EX_ELEM_BLOCK, i, EBLK_ID, *num_elems, *x_coords); |
| 589 |
t_tmp2 = my_timer(); |
| 590 |
|
| 591 |
raw_read_time += t_tmp2 - t_tmp1; |
| 592 |
raw_data_vol += sizeof(realtyp) * (*num_elems); |
| 593 |
|
| 594 |
if (err) { |
| 595 |
printf("after ex_get_elem_var, error = %d\n", err); |
| 596 |
ex_close(exoid); |
| 597 |
return 1; |
| 598 |
} |
| 599 |
} |
| 600 |
} |
| 601 |
|
| 602 |
if (rank == 0) { |
| 603 |
fprintf(stderr, "\n"); |
| 604 |
} |
| 605 |
} |
| 606 |
|
| 607 |
err = ex_close(exoid); |
| 608 |
if (err) { |
| 609 |
printf("after ex_close, error = %d\n", err); |
| 610 |
return 1; |
| 611 |
} |
| 612 |
tend = my_timer(); |
| 613 |
|
| 614 |
total_time = tend - tstart - raw_sleep_time; |
| 615 |
if (total_time > max_total_time) { |
| 616 |
max_total_time = total_time; |
| 617 |
} |
| 618 |
if (total_time < min_total_time) { |
| 619 |
min_total_time = total_time; |
| 620 |
} |
| 621 |
cum_total_time += total_time; |
| 622 |
|
| 623 |
if (raw_read_time > max_raw_read_time) { |
| 624 |
max_raw_read_time = raw_read_time; |
| 625 |
} |
| 626 |
if (raw_read_time < min_raw_read_time) { |
| 627 |
min_raw_read_time = raw_read_time; |
| 628 |
} |
| 629 |
cum_raw_read_time += raw_read_time; |
| 630 |
} /* end of for (iter...) */ |
| 631 |
|
| 632 |
#ifdef PARALLEL_AWARE_EXODUS |
| 633 |
MPI_Allreduce(&raw_data_vol, &glob_raw_data_vol, 1, MPI_LONG, MPI_SUM, MPI_COMM_WORLD); |
| 634 |
#else |
| 635 |
glob_raw_data_vol = raw_data_vol; |
| 636 |
#endif |
| 637 |
/* |
| 638 |
* Get File Sizes |
| 639 |
* |
| 640 |
* Note: On ASCI Red, a specialized "stat", named "estat", was added to |
| 641 |
* accommodate file sizes up to 16GB. 3/27/2002 |
| 642 |
*/ |
| 643 |
|
| 644 |
if (stat(tmp_name, &file_status)) { |
| 645 |
if (rank == 0) { |
| 646 |
fprintf(stderr, "Exodus Read: cannot get %s file size.\n", tmp_name); |
| 647 |
} |
| 648 |
return 1; |
| 649 |
} |
| 650 |
{ |
| 651 |
file_size = file_status.st_size; |
| 652 |
} |
| 653 |
|
| 654 |
#ifdef PARALLEL_AWARE_EXODUS |
| 655 |
MPI_Allreduce(&file_size, &glob_file_size, 1, MPI_LONG, MPI_SUM, MPI_COMM_WORLD); |
| 656 |
#else |
| 657 |
glob_file_size = file_size; |
| 658 |
#endif |
| 659 |
|
| 660 |
if (rank == 0) { |
| 661 |
fprintf(stderr, " \n"); |
| 662 |
fprintf(stderr, " Exodus Read Results \n"); |
| 663 |
fprintf(stderr, " \n"); |
| 664 |
fprintf(stderr, " Sizes (bytes) \n"); |
| 665 |
fprintf(stderr, " File %14ld \n", |
| 666 |
(long)glob_file_size); |
| 667 |
fprintf(stderr, " Raw Data %14ld \n", |
| 668 |
(long)glob_raw_data_vol); |
| 669 |
fprintf(stderr, " Difference %14ld (%5.2f%%) \n", |
| 670 |
(long)(glob_file_size - glob_raw_data_vol), |
| 671 |
(1.0 * glob_file_size - 1.0 * glob_raw_data_vol) / (0.01 * glob_file_size)); |
| 672 |
fprintf(stderr, " \n"); |
| 673 |
fprintf(stderr, " Times (sec) \t Minimum\t Maximum\t Average\n"); |
| 674 |
fprintf(stderr, " Raw Data Read (sec) \t%8.4g\t%8.4g\t%8.4g \n", |
| 675 |
min_raw_read_time, max_raw_read_time, cum_raw_read_time / num_iterations); |
| 676 |
fprintf(stderr, " All Other Read (sec) \t \t \t%8.4g \n", |
| 677 |
(cum_total_time - cum_raw_read_time) / num_iterations); |
| 678 |
fprintf(stderr, " Total Read (sec) \t \t \t%8.4g \n", |
| 679 |
cum_total_time / num_iterations); |
| 680 |
fprintf(stderr, " \n"); |
| 681 |
fprintf(stderr, " Input Bandwidths (MiB/sec) \t Minimum\t Maximum\t Average\n"); |
| 682 |
fprintf(stderr, " Raw Data Read (MiB/sec) \t%8.4g\t%8.4g\t%8.4g \n", |
| 683 |
(double)glob_raw_data_vol / max_raw_read_time / MBYTES, |
| 684 |
(double)glob_raw_data_vol / min_raw_read_time / MBYTES, |
| 685 |
(double)glob_raw_data_vol / cum_raw_read_time / MBYTES * num_iterations); |
| 686 |
fprintf(stderr, " Raw + Meta Data Read (MiB/sec)\t \t \t%8.4g \n", |
| 687 |
(double)glob_file_size / cum_total_time / MBYTES * num_iterations); |
| 688 |
} |
| 689 |
if (*num_global_fields > 0) { |
| 690 |
free(globals); |
| 691 |
} |
| 692 |
return 0; |
| 693 |
} |
| 694 |
|
| 695 |
/*********************************************************************** |
| 696 |
***********************************************************************/ |
| 697 |
int write_exo_mesh(char *file_name, int rank, int num_dim, int num_domains, int num_nodal_fields, |
| 698 |
int num_global_fields, int num_element_fields, int num_timesteps, |
| 699 |
int files_per_domain, int sleep_time, int num_iterations, int num_nodes, |
| 700 |
int *node_map, int num_elems, int *elem_map, realtyp *x_coords, |
| 701 |
realtyp *y_coords, realtyp *z_coords, int *connect, int close_files) |
| 702 |
|
| 703 |
{ |
| 704 |
int CPU_word_size = sizeof(realtyp); |
| 705 |
int IO_word_size = sizeof(realtyp); |
| 706 |
int j, t, npd, err, num_elem_blk, num_node_sets, num_side_sets; |
| 707 |
int iter; |
| 708 |
int *elem_var_tab = NULL; |
| 709 |
size_t file_size; |
| 710 |
|
| 711 |
struct stat file_status; |
| 712 |
size_t glob_file_size; |
| 713 |
size_t glob_raw_data_vol; |
| 714 |
size_t raw_data_vol = 0; |
| 715 |
|
| 716 |
realtyp *globals = NULL; |
| 717 |
|
| 718 |
double raw_open_close_time = 0.0; |
| 719 |
double cum_open_close_time = 0.0; |
| 720 |
double min_raw_open_close_time = DBL_MAX; |
| 721 |
double max_raw_open_close_time = 0.0; |
| 722 |
double tstart, tend, t_tmp1, t_tmp2; |
| 723 |
double raw_write_time, max_raw_write_time = 0.0, min_raw_write_time = DBL_MAX; |
| 724 |
double cum_raw_write_time = 0.0; |
| 725 |
double total_time, max_total_time = 0.0, min_total_time = DBL_MAX; |
| 726 |
double cum_total_time = 0.0; |
| 727 |
double raw_sleep_time = 0.0; |
| 728 |
double put_time_time = 0.0; |
| 729 |
|
| 730 |
char tmp_name[MAX_STRING_LEN]; |
| 731 |
char base_name[MAX_STRING_LEN]; |
| 732 |
char **gvar_name = NULL; |
| 733 |
char **nvar_name = NULL; |
| 734 |
char **evar_name = NULL; |
| 735 |
|
| 736 |
int *exoid = malloc(files_per_domain * sizeof(int)); |
| 737 |
|
| 738 |
for (iter = 0; iter < num_iterations; iter++) { |
| 739 |
if (!close_files) { |
| 740 |
t_tmp1 = my_timer(); |
| 741 |
for (npd = 0; npd < files_per_domain; npd++) { |
| 742 |
/* create the EXODUS file */ |
| 743 |
|
| 744 |
snprintf(base_name, MAX_STRING_LEN, "%s_%d", file_name, npd); |
| 745 |
get_file_name(base_name, EXODUS_FILE_TYPE, rank, num_domains, WRITE_FILE_TYPE, tmp_name); |
| 746 |
exoid[npd] = ex_create(tmp_name, EX_CLOBBER, &CPU_word_size, &IO_word_size); |
| 747 |
|
| 748 |
if (exoid[npd] < 0) { |
| 749 |
printf("after ex_create\n"); |
| 750 |
free(exoid); |
| 751 |
return 1; |
| 752 |
} |
| 753 |
} |
| 754 |
t_tmp2 = my_timer(); |
| 755 |
raw_open_close_time += (t_tmp2 - t_tmp1); |
| 756 |
} |
| 757 |
raw_write_time = 0.0; |
| 758 |
raw_data_vol = 0; |
| 759 |
|
| 760 |
tstart = my_timer(); |
| 761 |
|
| 762 |
num_elem_blk = 1; |
| 763 |
num_node_sets = 0; |
| 764 |
num_side_sets = 0; |
| 765 |
|
| 766 |
for (npd = 0; npd < files_per_domain; npd++) { |
| 767 |
|
| 768 |
if (close_files) { |
| 769 |
/* create the EXODUS file */ |
| 770 |
snprintf(base_name, MAX_STRING_LEN, "%s_%d", file_name, npd); |
| 771 |
get_file_name(base_name, EXODUS_FILE_TYPE, rank, num_domains, WRITE_FILE_TYPE, tmp_name); |
| 772 |
exoid[npd] = ex_create(tmp_name, EX_CLOBBER, &CPU_word_size, &IO_word_size); |
| 773 |
|
| 774 |
if (exoid[npd] < 0) { |
| 775 |
printf("after ex_create\n"); |
| 776 |
if (globals) { |
| 777 |
free(globals); |
| 778 |
globals = NULL; |
| 779 |
} |
| 780 |
free(exoid); |
| 781 |
return 1; |
| 782 |
} |
| 783 |
} |
| 784 |
err = ex_put_init(exoid[npd], "This is an EXODUSII performance test.", num_dim, num_nodes, |
| 785 |
num_elems, num_elem_blk, num_node_sets, num_side_sets); |
| 786 |
|
| 787 |
if (err) { |
| 788 |
printf("after ex_put_init, error = %d\n", err); |
| 789 |
ex_close(exoid[npd]); |
| 790 |
free(exoid); |
| 791 |
|
| 792 |
return 1; |
| 793 |
} |
| 794 |
|
| 795 |
#if 0 |
| 796 |
{ |
| 797 |
int ids[1] = {EBLK_ID}; |
| 798 |
int num_elem_per_block[1]; |
| 799 |
char *names[1] = {"hex"}; |
| 800 |
int num_node_per_elem[1]; |
| 801 |
int num_attr_per_block[1]; |
| 802 |
int write_map = num_domains > 1 ? true : false; |
| 803 |
num_elem_per_block[0] = num_elems; |
| 804 |
num_node_per_elem[0] = NUM_NODES_PER_ELEM; |
| 805 |
num_attr_per_block[0] = 0; |
| 806 |
err = ex_put_concat_elem_block (exoid[npd], ids, names, num_elem_per_block, |
| 807 |
num_node_per_elem, num_attr_per_block, write_map); |
| 808 |
} |
| 809 |
#else |
| 810 |
err = ex_put_block(exoid[npd], EX_ELEM_BLOCK, EBLK_ID, "hex", num_elems, NUM_NODES_PER_ELEM, |
| 811 |
0, 0, 0); |
| 812 |
#endif |
| 813 |
if (err) { |
| 814 |
printf("after ex_put_elem_block, error = %d\n", err); |
| 815 |
ex_close(exoid[npd]); |
| 816 |
free(exoid); |
| 817 |
return 1; |
| 818 |
} |
| 819 |
|
| 820 |
t_tmp1 = my_timer(); |
| 821 |
err = ex_put_coord(exoid[npd], x_coords, y_coords, z_coords); |
| 822 |
t_tmp2 = my_timer(); |
| 823 |
|
| 824 |
raw_write_time += t_tmp2 - t_tmp1; |
| 825 |
raw_data_vol += sizeof(realtyp) * num_dim * num_nodes; |
| 826 |
|
| 827 |
if (err) { |
| 828 |
printf("after ex_put_coord, error = %d\n", err); |
| 829 |
ex_close(exoid[npd]); |
| 830 |
free(exoid); |
| 831 |
|
| 832 |
return 1; |
| 833 |
} |
| 834 |
|
| 835 |
t_tmp1 = my_timer(); |
| 836 |
err = ex_put_conn(exoid[npd], EX_ELEM_BLOCK, EBLK_ID, connect, NULL, NULL); |
| 837 |
t_tmp2 = my_timer(); |
| 838 |
|
| 839 |
raw_write_time += t_tmp2 - t_tmp1; |
| 840 |
raw_data_vol += sizeof(int) * num_elems * NUM_NODES_PER_ELEM; |
| 841 |
|
| 842 |
if (err) { |
| 843 |
printf("after ex_put_elem_conn, error = %d\n", err); |
| 844 |
ex_close(exoid[npd]); |
| 845 |
free(exoid); |
| 846 |
|
| 847 |
return 1; |
| 848 |
} |
| 849 |
|
| 850 |
/* write out element and node maps */ |
| 851 |
t_tmp1 = my_timer(); |
| 852 |
err = ex_put_id_map(exoid[npd], EX_NODE_MAP, node_map); |
| 853 |
t_tmp2 = my_timer(); |
| 854 |
|
| 855 |
raw_write_time += t_tmp2 - t_tmp1; |
| 856 |
raw_data_vol += sizeof(int) * num_nodes; |
| 857 |
|
| 858 |
if (err) { |
| 859 |
printf("after ex_put_id_map, error = %d\n", err); |
| 860 |
ex_close(exoid[npd]); |
| 861 |
free(exoid); |
| 862 |
|
| 863 |
return 1; |
| 864 |
} |
| 865 |
|
| 866 |
t_tmp1 = my_timer(); |
| 867 |
|
| 868 |
err = ex_put_id_map(exoid[npd], EX_ELEM_MAP, elem_map); |
| 869 |
|
| 870 |
t_tmp2 = my_timer(); |
| 871 |
|
| 872 |
raw_write_time += t_tmp2 - t_tmp1; |
| 873 |
raw_data_vol += sizeof(int) * num_elems; |
| 874 |
|
| 875 |
if (err) { |
| 876 |
printf("after ex_put_id_map, error = %d\n", err); |
| 877 |
ex_close(exoid[npd]); |
| 878 |
free(exoid); |
| 879 |
|
| 880 |
return 1; |
| 881 |
} |
| 882 |
|
| 883 |
/* write out simulated results fields; |
| 884 |
we'll just write out the x coordinate field 'num_element_fields' times */ |
| 885 |
if (num_element_fields > 0) { |
| 886 |
if (npd == 0) { |
| 887 |
elem_var_tab = malloc(num_element_fields * sizeof(int)); |
| 888 |
assert(elem_var_tab); |
| 889 |
for (j = 0; j < num_element_fields; j++) { |
| 890 |
elem_var_tab[j] = 1; |
| 891 |
} |
| 892 |
} |
| 893 |
} |
| 894 |
else { |
| 895 |
elem_var_tab = NULL; |
| 896 |
} |
| 897 |
err = ex_put_all_var_param(exoid[npd], num_global_fields, num_nodal_fields, |
| 898 |
num_element_fields, elem_var_tab, 0, 0, 0, 0); |
| 899 |
|
| 900 |
if (elem_var_tab) { |
| 901 |
free(elem_var_tab); |
| 902 |
elem_var_tab = NULL; |
| 903 |
} |
| 904 |
|
| 905 |
if (err) { |
| 906 |
fprintf(stderr, "after ex_put_all_var_param, error = %d\n", err); |
| 907 |
ex_close(exoid[npd]); |
| 908 |
exit(1); |
| 909 |
} |
| 910 |
|
| 911 |
if (num_nodal_fields > 0) { |
| 912 |
|
| 913 |
if (npd == 0) { |
| 914 |
nvar_name = malloc(num_nodal_fields * sizeof(char *)); |
| 915 |
assert(nvar_name); |
| 916 |
for (j = 0; j < num_nodal_fields; j++) { |
| 917 |
nvar_name[j] = malloc((MAX_STRING_LEN + 1) * sizeof(char)); |
| 918 |
snprintf(nvar_name[j], MAX_STRING_LEN + 1, "node_field_%d", j + 1); |
| 919 |
} |
| 920 |
} |
| 921 |
err = ex_put_variable_names(exoid[npd], EX_NODAL, num_nodal_fields, nvar_name); |
| 922 |
if (npd == files_per_domain - 1) { |
| 923 |
for (j = 0; j < num_nodal_fields; j++) { |
| 924 |
free(nvar_name[j]); |
| 925 |
} |
| 926 |
free(nvar_name); |
| 927 |
} |
| 928 |
if (err) { |
| 929 |
fprintf(stderr, "after ex_put_variable_names, error = %d\n", err); |
| 930 |
ex_close(exoid[npd]); |
| 931 |
exit(1); |
| 932 |
} |
| 933 |
} |
| 934 |
|
| 935 |
if (num_global_fields > 0) { |
| 936 |
if (npd == 0) { |
| 937 |
globals = malloc(num_global_fields * sizeof(realtyp)); |
| 938 |
gvar_name = malloc(num_global_fields * sizeof(char *)); |
| 939 |
for (j = 0; j < num_global_fields; j++) { |
| 940 |
gvar_name[j] = malloc((MAX_STRING_LEN + 1) * sizeof(char)); |
| 941 |
snprintf(gvar_name[j], MAX_STRING_LEN + 1, "global_field_%d", j + 1); |
| 942 |
globals[j] = j; |
| 943 |
} |
| 944 |
} |
| 945 |
|
| 946 |
ex_put_variable_names(exoid[npd], EX_GLOBAL, num_global_fields, gvar_name); |
| 947 |
|
| 948 |
if (npd == files_per_domain - 1) { |
| 949 |
for (j = 0; j < num_global_fields; j++) { |
| 950 |
free(gvar_name[j]); |
| 951 |
} |
| 952 |
free(gvar_name); |
| 953 |
} |
| 954 |
} |
| 955 |
|
| 956 |
if (num_element_fields > 0) { |
| 957 |
if (npd == 0) { |
| 958 |
evar_name = malloc(num_element_fields * sizeof(char *)); |
| 959 |
for (j = 0; j < num_element_fields; j++) { |
| 960 |
evar_name[j] = malloc((MAX_STRING_LEN + 1) * sizeof(char)); |
| 961 |
snprintf(evar_name[j], MAX_STRING_LEN + 1, "element_field_%d", j + 1); |
| 962 |
} |
| 963 |
} |
| 964 |
|
| 965 |
ex_put_variable_names(exoid[npd], EX_ELEM_BLOCK, num_element_fields, evar_name); |
| 966 |
|
| 967 |
if (npd == files_per_domain - 1) { |
| 968 |
free(elem_var_tab); |
| 969 |
elem_var_tab = NULL; |
| 970 |
for (j = 0; j < num_element_fields; j++) { |
| 971 |
free(evar_name[j]); |
| 972 |
} |
| 973 |
free(evar_name); |
| 974 |
} |
| 975 |
} |
| 976 |
if (close_files) { |
| 977 |
t_tmp1 = my_timer(); |
| 978 |
ex_close(exoid[npd]); |
| 979 |
t_tmp2 = my_timer(); |
| 980 |
raw_open_close_time += (t_tmp2 - t_tmp1); |
| 981 |
} |
| 982 |
} |
| 983 |
|
| 984 |
if (num_nodal_fields + num_global_fields + num_element_fields > 0) { |
| 985 |
if (rank == 0) { |
| 986 |
fprintf(stderr, "\nWriting Timestep: "); |
| 987 |
} |
| 988 |
for (t = 0; t < num_timesteps; t++) { |
| 989 |
for (npd = 0; npd < files_per_domain; npd++) { |
| 990 |
realtyp time = t; |
| 991 |
|
| 992 |
if (close_files) { |
| 993 |
float version; |
| 994 |
snprintf(base_name, MAX_STRING_LEN, "%s_%d", file_name, npd); |
| 995 |
t_tmp1 = my_timer(); |
| 996 |
get_file_name(base_name, EXODUS_FILE_TYPE, rank, num_domains, WRITE_FILE_TYPE, |
| 997 |
tmp_name); |
| 998 |
exoid[npd] = ex_open(tmp_name, EX_WRITE, &CPU_word_size, &IO_word_size, &version); |
| 999 |
t_tmp2 = my_timer(); |
| 1000 |
raw_open_close_time += (t_tmp2 - t_tmp1); |
| 1001 |
} |
| 1002 |
|
| 1003 |
if (sleep_time > 0) { |
| 1004 |
t_tmp1 = my_timer(); |
| 1005 |
sleep(sleep_time); |
| 1006 |
t_tmp2 = my_timer(); |
| 1007 |
raw_sleep_time += t_tmp2 - t_tmp1; |
| 1008 |
} |
| 1009 |
t_tmp1 = my_timer(); |
| 1010 |
ex_put_time(exoid[npd], t + 1, &time); |
| 1011 |
t_tmp2 = my_timer(); |
| 1012 |
put_time_time += t_tmp2 - t_tmp1; |
| 1013 |
if (rank == 0) { |
| 1014 |
if (npd == 0) { |
| 1015 |
fprintf(stderr, " %d", t + 1); |
| 1016 |
} |
| 1017 |
else { |
| 1018 |
fprintf(stderr, "."); |
| 1019 |
} |
| 1020 |
} |
| 1021 |
if (num_global_fields > 0) { |
| 1022 |
t_tmp1 = my_timer(); |
| 1023 |
err = ex_put_var(exoid[npd], t + 1, EX_GLOBAL, 1, 0, num_global_fields, globals); |
| 1024 |
t_tmp2 = my_timer(); |
| 1025 |
raw_write_time += t_tmp2 - t_tmp1; |
| 1026 |
if (err) { |
| 1027 |
free(globals); |
| 1028 |
fprintf(stderr, "after ex_put_global_var, error = %d\n", err); |
| 1029 |
ex_close(exoid[npd]); |
| 1030 |
exit(1); |
| 1031 |
} |
| 1032 |
} |
| 1033 |
for (j = 0; j < num_nodal_fields; j++) { |
| 1034 |
t_tmp1 = my_timer(); |
| 1035 |
err = ex_put_var(exoid[npd], t + 1, EX_NODAL, j + 1, 0, num_nodes, x_coords); |
| 1036 |
t_tmp2 = my_timer(); |
| 1037 |
raw_write_time += t_tmp2 - t_tmp1; |
| 1038 |
if (err) { |
| 1039 |
fprintf(stderr, "after ex_put_nodal_var, error = %d\n", err); |
| 1040 |
ex_close(exoid[npd]); |
| 1041 |
exit(1); |
| 1042 |
} |
| 1043 |
} |
| 1044 |
for (j = 0; j < num_element_fields; j++) { |
| 1045 |
t_tmp1 = my_timer(); |
| 1046 |
err = ex_put_var(exoid[npd], t + 1, EX_ELEM_BLOCK, j + 1, EBLK_ID, num_elems, x_coords); |
| 1047 |
t_tmp2 = my_timer(); |
| 1048 |
raw_write_time += t_tmp2 - t_tmp1; |
| 1049 |
if (err) { |
| 1050 |
fprintf(stderr, "after ex_put_element_var, error = %d\n", err); |
| 1051 |
ex_close(exoid[npd]); |
| 1052 |
exit(1); |
| 1053 |
} |
| 1054 |
} |
| 1055 |
if (close_files) { |
| 1056 |
t_tmp1 = my_timer(); |
| 1057 |
ex_close(exoid[npd]); |
| 1058 |
t_tmp2 = my_timer(); |
| 1059 |
raw_open_close_time += (t_tmp2 - t_tmp1); |
| 1060 |
} |
| 1061 |
} |
| 1062 |
} |
| 1063 |
|
| 1064 |
if (rank == 0) { |
| 1065 |
fprintf(stderr, "\n"); |
| 1066 |
} |
| 1067 |
} |
| 1068 |
t_tmp1 = my_timer(); |
| 1069 |
if (!close_files) { |
| 1070 |
if (rank == 0) { |
| 1071 |
fprintf(stderr, "Closing database..."); |
| 1072 |
} |
| 1073 |
for (npd = 0; npd < files_per_domain; npd++) { |
| 1074 |
err = ex_close(exoid[npd]); |
| 1075 |
if (err) { |
| 1076 |
printf("after ex_close, error = %d\n", err); |
| 1077 |
free(exoid); |
| 1078 |
return 1; |
| 1079 |
} |
| 1080 |
} |
| 1081 |
if (rank == 0) { |
| 1082 |
fprintf(stderr, "\n"); |
| 1083 |
} |
| 1084 |
} |
| 1085 |
t_tmp2 = my_timer(); |
| 1086 |
raw_open_close_time += (t_tmp2 - t_tmp1); |
| 1087 |
|
| 1088 |
if (rank == 0) { |
| 1089 |
fprintf(stderr, "ex_put_time = %5.2f seconds\n", put_time_time); |
| 1090 |
} |
| 1091 |
tend = my_timer(); |
| 1092 |
|
| 1093 |
total_time = tend - tstart - raw_sleep_time; |
| 1094 |
|
| 1095 |
if (total_time > max_total_time) { |
| 1096 |
max_total_time = total_time; |
| 1097 |
} |
| 1098 |
if (total_time < min_total_time) { |
| 1099 |
min_total_time = total_time; |
| 1100 |
} |
| 1101 |
|
| 1102 |
cum_total_time += total_time; |
| 1103 |
|
| 1104 |
if (raw_write_time > max_raw_write_time) { |
| 1105 |
max_raw_write_time = raw_write_time; |
| 1106 |
} |
| 1107 |
if (raw_write_time < min_raw_write_time) { |
| 1108 |
min_raw_write_time = raw_write_time; |
| 1109 |
} |
| 1110 |
|
| 1111 |
cum_raw_write_time += raw_write_time; |
| 1112 |
|
| 1113 |
if (raw_open_close_time > max_raw_open_close_time) { |
| 1114 |
max_raw_open_close_time = raw_open_close_time; |
| 1115 |
} |
| 1116 |
if (raw_open_close_time < min_raw_open_close_time) { |
| 1117 |
min_raw_open_close_time = raw_open_close_time; |
| 1118 |
} |
| 1119 |
|
| 1120 |
cum_open_close_time += raw_open_close_time; |
| 1121 |
|
| 1122 |
raw_data_vol += sizeof(realtyp) * |
| 1123 |
(((size_t)num_nodes * num_nodal_fields) + (num_elems * num_element_fields) + |
| 1124 |
(num_global_fields)) * |
| 1125 |
num_timesteps * files_per_domain; |
| 1126 |
|
| 1127 |
} /* end of for (iter...) */ |
| 1128 |
|
| 1129 |
#ifdef PARALLEL_AWARE_EXODUS |
| 1130 |
MPI_Allreduce(&raw_data_vol, &glob_raw_data_vol, 1, MPI_LONG, MPI_SUM, MPI_COMM_WORLD); |
| 1131 |
#else |
| 1132 |
glob_raw_data_vol = raw_data_vol; |
| 1133 |
#endif |
| 1134 |
/* |
| 1135 |
* Get File Sizes |
| 1136 |
* |
| 1137 |
* Note: On ASCI Red, a specialized "stat", named "estat", was added to |
| 1138 |
* accommodate file sizes up to 16GB. 3/27/2002 |
| 1139 |
*/ |
| 1140 |
|
| 1141 |
if (stat(tmp_name, &file_status)) { |
| 1142 |
if (rank == 0) { |
| 1143 |
fprintf(stderr, "Exodus Write: cannot get %s file size.\n", tmp_name); |
| 1144 |
} |
| 1145 |
|
| 1146 |
free(exoid); |
| 1147 |
return 1; |
| 1148 |
} |
| 1149 |
{ |
| 1150 |
file_size = file_status.st_size * files_per_domain; |
| 1151 |
} |
| 1152 |
|
| 1153 |
#ifdef PARALLEL_AWARE_EXODUS |
| 1154 |
MPI_Allreduce(&file_size, &glob_file_size, 1, MPI_LONG, MPI_SUM, MPI_COMM_WORLD); |
| 1155 |
#else |
| 1156 |
glob_file_size = file_size; |
| 1157 |
#endif |
| 1158 |
|
| 1159 |
if (rank == 0) { |
| 1160 |
fprintf(stderr, " \n"); |
| 1161 |
fprintf(stderr, " Exodus Write Results \n"); |
| 1162 |
fprintf(stderr, " \n"); |
| 1163 |
fprintf(stderr, " Sizes (bytes) \n"); |
| 1164 |
fprintf(stderr, " File %14ld \n", |
| 1165 |
(long)glob_file_size); |
| 1166 |
fprintf(stderr, " Raw Data %14ld \n", |
| 1167 |
(long)glob_raw_data_vol); |
| 1168 |
fprintf(stderr, " Difference %14ld (%5.2f%%) \n", |
| 1169 |
(long)(glob_file_size - glob_raw_data_vol), |
| 1170 |
(1.0 * glob_file_size - 1.0 * glob_raw_data_vol) / (0.01 * glob_file_size)); |
| 1171 |
fprintf(stderr, " \n"); |
| 1172 |
fprintf(stderr, " Times \t Minimum\t Maximum\t Average\n"); |
| 1173 |
fprintf(stderr, " Raw Data Write (sec) \t%8.4g\t%8.4g\t%8.4g \n", |
| 1174 |
min_raw_write_time, max_raw_write_time, cum_raw_write_time / num_iterations); |
| 1175 |
fprintf(stderr, " All Other Write (sec) \t \t \t%8.4g \n", |
| 1176 |
(cum_total_time - cum_raw_write_time) / num_iterations); |
| 1177 |
fprintf(stderr, " Open/Close Time (sec) \t \t \t%8.4g \n", |
| 1178 |
cum_open_close_time / num_iterations); |
| 1179 |
fprintf(stderr, " Total Write (sec) \t \t \t%8.4g \n", |
| 1180 |
cum_total_time / num_iterations); |
| 1181 |
fprintf(stderr, " \n"); |
| 1182 |
fprintf(stderr, " Output Bandwidths \t Minimum\t Maximum\t Average\n"); |
| 1183 |
fprintf(stderr, " Raw Data Write (MiB/sec) \t%8.4g\t%8.4g\t%8.4g \n", |
| 1184 |
(double)glob_raw_data_vol / max_raw_write_time / MBYTES, |
| 1185 |
(double)glob_raw_data_vol / min_raw_write_time / MBYTES, |
| 1186 |
(double)glob_raw_data_vol / cum_raw_write_time / MBYTES * num_iterations); |
| 1187 |
fprintf(stderr, " Raw + Meta Data Write (MiB/sec) \t \t%8.4g\n", |
| 1188 |
(double)glob_file_size / cum_total_time / MBYTES * num_iterations); |
| 1189 |
} |
| 1190 |
free(exoid); |
| 1191 |
if (num_global_fields > 0) { |
| 1192 |
free(globals); |
| 1193 |
globals = NULL; |
| 1194 |
} |
| 1195 |
return 0; |
| 1196 |
} |
| 1197 |
|
| 1198 |
/*****************************************************************************/ |
| 1199 |
void get_file_name(const char *base, const char *ext, int rank, int nprocs, const char *other, |
| 1200 |
char *output) |
| 1201 |
{ |
| 1202 |
output[0] = '\0'; |
| 1203 |
ex_copy_string(output, base, MAX_STRING_LEN); |
| 1204 |
strcat(output, "."); |
| 1205 |
strcat(output, ext); |
| 1206 |
if (other != NULL) { |
| 1207 |
strcat(output, "."); |
| 1208 |
strcat(output, other); |
| 1209 |
} |
| 1210 |
|
| 1211 |
if (nprocs > 1) { |
| 1212 |
/* |
| 1213 |
* Find out the number of digits needed to specify the processor ID. |
| 1214 |
* This allows numbers like 01-99, i.e., prepending zeros to the |
| 1215 |
* name to preserve proper alphabetic sorting of the files. |
| 1216 |
*/ |
| 1217 |
int iMaxDigit = 0, iMyDigit = 0; |
| 1218 |
int iTemp1 = nprocs; |
| 1219 |
do { |
| 1220 |
iTemp1 /= 10; |
| 1221 |
iMaxDigit++; |
| 1222 |
} while (iTemp1 >= 1); |
| 1223 |
|
| 1224 |
iTemp1 = rank; |
| 1225 |
do { |
| 1226 |
iTemp1 /= 10; |
| 1227 |
iMyDigit++; |
| 1228 |
} while (iTemp1 >= 1); |
| 1229 |
|
| 1230 |
strcat(output, "."); |
| 1231 |
|
| 1232 |
char cTemp[128]; |
| 1233 |
snprintf(cTemp, 128, "%d", nprocs); |
| 1234 |
strcat(output, cTemp); |
| 1235 |
strcat(output, "."); |
| 1236 |
|
| 1237 |
/* |
| 1238 |
* Append the proper number of zeros to the filename. |
| 1239 |
*/ |
| 1240 |
for (int i1 = 0; i1 < iMaxDigit - iMyDigit; i1++) { |
| 1241 |
strcat(output, "0"); |
| 1242 |
} |
| 1243 |
|
| 1244 |
snprintf(cTemp, 128, "%d", rank); |
| 1245 |
strcat(output, cTemp); |
| 1246 |
} |
| 1247 |
} |