Debian Codegraph @

packages/seacas/applications/epu/EP_ParallelDisks.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 <cstdlib>
10
11 #include <string>
12
13 #include <EP_Internals.h>
14 #include <EP_ParallelDisks.h>
15
16 #if defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || \
17 defined(__MINGW32__) || defined(_WIN64) || defined(__MINGW64__)
18 #include <Shlwapi.h>
19 #endif
20
21 /*****************************************************************************/
22 void Excn::ParallelDisks::rename_file_for_mp(const std::string &rootdir, const std::string &subdir,
23 std::string &name, int node, int numproc) const
24 {
25 // Possible to have node layout without parallel disks
26
27 std::string prepend;
28 if (!rootdir.empty()) {
29 prepend = rootdir + "/";
30 }
31 else if (Excn::is_path_absolute(name)) {
32 prepend = "";
33 }
34 else {
35 prepend = "./";
36 }
37
38 int lnn = node;
39 Create_IO_Filename(name, lnn, numproc);
40 if (!subdir.empty()) {
41 name = subdir + "/" + name;
42 }
43 name = prepend + name;
44 }
45
46 /*****************************************************************************/
47 void Excn::ParallelDisks::Create_IO_Filename(std::string &name, int processor, int num_processors)
48 {
49 // Current format for per-processor file names is:
50 // PREFIX/basename.num_proc.cur_proc
51 // the 'cur_proc' field is padded to be the same width as
52 // the 'num_proc' field
53 // Examples: basename.8.1, basename.64.03, basename.128.001
54
55 // Create a std::string containing the total number of processors
56 std::string num_proc = std::to_string(num_processors);
57 size_t proc_width = num_proc.length();
58
59 // Create a std::string containing the current processor number
60 std::string cur_proc = std::to_string(processor);
61 size_t cur_width = cur_proc.length();
62
63 // Build the filename
64 name += ".";
65 name += num_proc;
66 name += ".";
67
68 // Now, pad with zeros so that 'cur_proc' portion is same
69 // width as 'num_proc' portion.
70 while (cur_width++ < proc_width) {
71 name += "0";
72 }
73
74 name += cur_proc;
75 }