Debian Codegraph @

packages/seacas/applications/nem_spread/pe_util.C

raw
1 /*
2 * Copyright(C) 1999-2021, 2023 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 #include "fmt/ostream.h"
10 #include "ps_pario_const.h" // for Parallel_IO, PIO_Info
11 #include "rf_allo.h" // for array_alloc
12 #include "rf_io_const.h" // for Debug_Flag
13 #include <array>
14 #include <cstdlib> // for exit
15 #include <cstring> // for strlen, etc
16 #include <sstream>
17 #include <string>
18
19 /*********** R O U T I N E S I N T H I S F I L E ***********************
20
21 Name_of_Routine type Called by
22 ---------------------------------------------------------------------------
23 pdisk_stage_begin() void load_mesh (pe_exoII_io.c)
24 pdisk_stage_end() void load_mesh (pe_exoII_io.c)
25 gen_par_filename() void load_lb_info (rf_load_lb_info.c)
26 load_mesh (pe_exoII_io.c)
27
28 ******************************************************************************/
29 /*****************************************************************************/
30 /*****************************************************************************/
31 /*****************************************************************************/
32 void gen_disk_map(struct Parallel_IO *pio_info, const std::array<int, 6> &proc_info, int /*proc*/,
33 int nproc)
34 /*
35 * This function generates a map of which processor ID writes to which
36 * RAID. Note that this is for each processor in the list, not necessarily
37 * the same as the number of processors being used during the run. Each
38 * processor has an identical list.
39 */
40 {
41 /* Allocate memory for the list */
42 pio_info->RDsk_List =
43 reinterpret_cast<int **>(array_alloc(__FILE__, __LINE__, 2, proc_info[0], 2, sizeof(int)));
44 if ((pio_info->RDsk_List) == nullptr) {
45 fmt::print(stderr, "{}: ERROR, insufficient memory\n", __func__);
46 exit(1);
47 }
48
49 /* Generate the list of disks to which data will be written */
50 if (pio_info->Dsk_List_Cnt <= 0) {
51 for (int iproc = 0; iproc < proc_info[0]; iproc++) {
52 int ctrl_id = (iproc % pio_info->Num_Dsk_Ctrlrs);
53 pio_info->RDsk_List[iproc][0] = ctrl_id + pio_info->PDsk_Add_Fact;
54 }
55 }
56 else {
57 for (int iproc = 0; iproc < proc_info[0]; iproc++) {
58 pio_info->RDsk_List[iproc][0] = pio_info->Dsk_List[iproc % pio_info->Dsk_List_Cnt];
59 }
60 }
61
62 /* Generate the list of processors on which info is stored */
63 for (int iproc = 0; iproc < proc_info[0]; iproc++) {
64 int proc_id = iproc;
65 while (proc_id >= nproc) {
66 proc_id -= nproc;
67 }
68
69 pio_info->RDsk_List[iproc][1] = proc_id;
70 }
71 }
72
73 /*****************************************************************************/
74 /*****************************************************************************/
75 /*****************************************************************************/
76 std::string gen_par_filename(const std::string &scalar_fname, int proc_for, int nprocs)
77 /*----------------------------------------------------------------------------
78 *
79 * Author(s): Gary Hennigan (1421)
80 *----------------------------------------------------------------------------
81 * Function which generates the name of a parallel file for a
82 * particular processor. The function does this by appending
83 * "N.p" to the end of the input parameter "scalar_fname", where:
84 *
85 * N - The number of processors utilized
86 * p - The processor ID.
87 *
88 * In addition, the location of the parallel disk system is prepended
89 * to each file name.
90 *---------------------------------------------------------------------------
91 * Example:
92 *
93 * scalar_fname = "Parallel-exoII-" (Input)
94 * par_fname = "/raid/io_01/tmp/rf_crew/Parallel-exoII-8.0" (Output)
95 *
96 * where, for this example:
97 *
98 * N = 8 processors
99 * p = 0 particular processor ID
100 *---------------------------------------------------------------------------
101 * Revision History:
102 *
103 * 05 November 1993: Date of Creation
104 *---------------------------------------------------------------------------
105 */
106 {
107 /*
108 * Find out the number of digits needed to specify the processor ID.
109 * This allows numbers like 01-99, i.e., prepending zeros to the
110 * name to preserve proper alphabetic sorting of the files.
111 */
112
113 int iMaxDigit = 0;
114 int iMyDigit = 0;
115 int iTemp1 = nprocs;
116 do {
117 iTemp1 /= 10;
118 iMaxDigit++;
119 } while (iTemp1 >= 1);
120
121 iTemp1 = proc_for;
122 do {
123 iTemp1 /= 10;
124 iMyDigit++;
125 } while (iTemp1 >= 1);
126
127 /*
128 * Append the number of processors in this run to the scalar file name
129 * along with a '.' (period).
130 */
131 std::string par_filename =
132 scalar_fname + std::string(".") + std::to_string(nprocs) + std::string(".");
133
134 /*
135 * Append the proper number of zeros to the filename.
136 */
137 for (int i1 = 0; i1 < iMaxDigit - iMyDigit; i1++) {
138 par_filename += std::string("0");
139 }
140
141 /*
142 * Generate the name of the directory on which the parallel disk
143 * array resides. This also directs which processor writes to what
144 * disk.
145 */
146 par_filename += std::to_string(proc_for);
147
148 /*
149 * Finally, generate the complete file specification for the parallel
150 * file used by this processor.
151 */
152 if (PIO_Info.NoSubdirectory == 1) {
153 par_filename = PIO_Info.Par_Dsk_Root + PIO_Info.Par_Dsk_SubDirec + par_filename;
154 }
155 else {
156 if (PIO_Info.Zeros != 0) {
157 int ctrlID = PIO_Info.RDsk_List[proc_for][0];
158 if (ctrlID <= 9) {
159 par_filename = PIO_Info.Par_Dsk_Root + "0" + std::to_string(ctrlID) + "/" +
160 PIO_Info.Par_Dsk_SubDirec + par_filename;
161 }
162 else {
163 par_filename = PIO_Info.Par_Dsk_Root + std::to_string(ctrlID) + "/" +
164 PIO_Info.Par_Dsk_SubDirec + par_filename;
165 }
166 }
167 else {
168 int ctrlID = PIO_Info.RDsk_List[proc_for][0];
169 par_filename = PIO_Info.Par_Dsk_Root + std::to_string(ctrlID) + "/" +
170 PIO_Info.Par_Dsk_SubDirec + par_filename;
171 }
172 }
173 if (Debug_Flag >= 4) {
174 fmt::print("Parallel file name: {}\n", par_filename);
175 }
176
177 return par_filename;
178 }