Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_get_init_info.c

raw
1 /*
2 * Copyright(C) 1999-2020, 2022 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 /*****************************************************************************/
10 /* Function(s) contained in this file:
11 * ex_get_init_info()
12 *****************************************************************************
13 * This function reads information about the processors for which the
14 * decomposition was performed.
15 *****************************************************************************
16 * Variable Index:
17 * exoid - The NetCDF ID of an already open NemesisI file.
18 * num_proc - The number of processors in the decomposition.
19 * num_proc_in_f - The number of processors the file contains
20 * information for.
21 */
22 /*****************************************************************************/
23 /*****************************************************************************/
24 /*****************************************************************************/
25
26 #include <exodusII.h> // for ex_err, EX_MSG, etc
27 #include <exodusII_int.h> // for EX_FATAL, DIM_NUM_PROCS, etc
28
29 /*!
30 * \ingroup ModelDescription
31 * \undoc
32 */
33 int ex_get_init_info(int exoid, int *num_proc, int *num_proc_in_f, char *ftype)
34 {
35 int dimid, status;
36 size_t ltempsv;
37
38 char errmsg[MAX_ERR_LENGTH];
39 /*-----------------------------Execution begins-----------------------------*/
40
41 EX_FUNC_ENTER();
42 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
43 EX_FUNC_LEAVE(EX_FATAL);
44 }
45
46 /* In case file isn't parallel, set the values here... */
47 *num_proc = 1;
48 *num_proc_in_f = 1;
49
50 /* Get the file type */
51 if (exi_get_file_type(exoid, ftype) != EX_NOERR) {
52 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get file type for file ID %d", exoid);
53 ex_err_fn(exoid, __func__, errmsg, EX_LASTERR);
54
55 EX_FUNC_LEAVE(EX_FATAL);
56 }
57
58 if (nc_inq_dimid(exoid, DIM_NUM_PROCS, &dimid) != NC_NOERR) {
59 /* This isn't a parallel file. Just return now with no error, but with num_proc and
60 * num_proc_in_f set to 1 */
61 EX_FUNC_LEAVE(EX_NOERR);
62 }
63
64 /* Get the value of the number of processors */
65 if ((status = nc_inq_dimlen(exoid, dimid, &ltempsv)) != NC_NOERR) {
66 snprintf(errmsg, MAX_ERR_LENGTH,
67 "ERROR: failed to find length of dimension \"%s\" in file ID %d", DIM_NUM_PROCS,
68 exoid);
69 ex_err_fn(exoid, __func__, errmsg, status);
70
71 EX_FUNC_LEAVE(EX_FATAL);
72 }
73 *num_proc = ltempsv;
74
75 /* Get the dimension ID of processors that have info in this file */
76 if ((status = nc_inq_dimid(exoid, DIM_NUM_PROCS_F, &dimid)) != NC_NOERR) {
77 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find dimension ID for \"%s\" in file ID %d",
78 DIM_NUM_PROCS_F, exoid);
79 ex_err_fn(exoid, __func__, errmsg, status);
80
81 EX_FUNC_LEAVE(EX_FATAL);
82 }
83
84 /* Get the value of the number of processors that have info in this file */
85 if ((status = nc_inq_dimlen(exoid, dimid, &ltempsv)) != NC_NOERR) {
86 snprintf(errmsg, MAX_ERR_LENGTH,
87 "ERROR: failed to find length of dimension \"%s\" in file ID %d", DIM_NUM_PROCS_F,
88 exoid);
89 ex_err_fn(exoid, __func__, errmsg, status);
90
91 EX_FUNC_LEAVE(EX_FATAL);
92 }
93 *num_proc_in_f = ltempsv;
94
95 EX_FUNC_LEAVE(EX_NOERR);
96 }