PhoenixHPCProxy  0.8.0
Lightweight HPC proxy
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
7#include "convertToString.h"
8
9#include "OptionParser.h"
10
12#include "BackEnd/backend.h"
14
16
18OptionParser createOptionParser(){
19 OptionParser parser(true, __PROGRAM_VERSION__);
20 parser.setExampleLongOption("phoenix_hpc_proxy --input=file.ph5 --output=output/dir/");
21 parser.setExampleShortOption("phoenix_hpc_proxy -i file1.ph5 file1.ph5 fileN.ph5 -o output/dir/");
22
23 parser.addOption("header", "i", OptionType::FILENAME, true, "list of input headers to be used to describe the main library");
24 std::string libName("lib_shadok");
25 parser.addOption("library", "l", libName, "name of the library to be created");
26
27 parser.addOption("libdir", "d", OptionType::DIRECTORY, false, "directory where the sub libraries are installed");
28
29 parser.addOption("anyarch", "", OptionType::FILENAME, false, "file name of the library to be used for any architectures (kind of security if the other architectures are not found)");
30 parser.addOption("sse", "", OptionType::FILENAME, false, "file name of the library to be used for sse architecture");
31 parser.addOption("sse2", "", OptionType::FILENAME, false, "file name of the library to be used for sse2 architecture");
32 parser.addOption("ssse3", "", OptionType::FILENAME, false, "file name of the library to be used for ssse3 architecture");
33 parser.addOption("sse4.1", "", OptionType::FILENAME, false, "file name of the library to be used for sse4.1 architecture");
34 parser.addOption("sse4.2", "", OptionType::FILENAME, false, "file name of the library to be used for sse4.2 architecture");
35 parser.addOption("avx", "", OptionType::FILENAME, false, "file name of the library to be used for avx architecture");
36 parser.addOption("avx2", "", OptionType::FILENAME, false, "file name of the library to be used for avx2 architecture");
37 parser.addOption("avx512f", "", OptionType::FILENAME, false, "file name of the library to be used for avx512f architecture");
38 parser.addOption("avx512bw", "", OptionType::FILENAME, false, "file name of the library to be used for avx512wb architecture");
39
40 std::string defaultOutputDir(".");
41 parser.addOption("output", "o", defaultOutputDir, "Output directory");
42
43 return parser;
44}
45
47
50void parseVecArchLib(PVecArchLib & vecArchLib, const OptionMode & defaultMode){
51 std::string libAnyArch(""), libSse(""), libSse2(""), libSsse3(""), libSse41(""), libSse42(""), libAvx(""), libAvx2(""), libAvx512f(""), libAvx512wb("");
52 defaultMode.getValue(libAnyArch, "anyarch");
53 defaultMode.getValue(libSse, "sse");
54 defaultMode.getValue(libSse2, "sse2");
55 defaultMode.getValue(libSsse3, "ssse3");
56 defaultMode.getValue(libSse41, "sse4.1");
57 defaultMode.getValue(libSse42, "sse4.2");
58 defaultMode.getValue(libAvx, "avx");
59 defaultMode.getValue(libAvx2, "avx2");
60 defaultMode.getValue(libAvx512f, "avx512f");
61 defaultMode.getValue(libAvx512wb, "avx512wb");
62
63 addArch(vecArchLib, "anyarch", libAnyArch);
64 addArch(vecArchLib, "sse", libSse);
65 addArch(vecArchLib, "sse2", libSse2);
66 addArch(vecArchLib, "ssse3", libSsse3);
67 addArch(vecArchLib, "sse4.1", libSse41);
68 addArch(vecArchLib, "sse4.2", libSse42);
69 addArch(vecArchLib, "avx", libAvx);
70 addArch(vecArchLib, "avx2", libAvx2);
71 addArch(vecArchLib, "avx512f", libAvx512f);
72 addArch(vecArchLib, "avx512wb", libAvx512wb);
73}
74
76
83bool createSourceFromConfig(const PString & inputFile, const PString & libraryName, const PVecArchLib & vecArchLib,
84 const PString & libDir, const PString & outputDir)
85{
86 HeaderParser parser;
87 if(!parser.load(inputFile)){
88 std::cerr << "createSourceFromConfig : cannot parse the input file '"<<inputFile<<"'" << std::endl;
89 return false;
90 }
91 std::string libName(getLibraryFile(vecArchLib));
92 PVecSource vecSource = parser.getVecSource();
93 if(vecSource.size() == 0lu){
94 std::cerr << "createSourceFromConfig : no source to be created" << std::endl;
95 return false;
96 }
97 bool b(cpp_backend(vecSource, libName, outputDir));
98 if(!b){
99 std::cerr << "createSourceFromConfig : cannot save source/header from input file '"<<inputFile<<"'" << std::endl;
100 return b;
101 }
102 b &= cpp_backend_proxy(vecSource, libraryName, vecArchLib, libDir, outputDir);
103 if(!b){
104 std::cerr << "createSourceFromConfig : cannot save source/header ProxyLoader class" << std::endl;
105 return b;
106 }
107 return b;
108}
109
111
118int processFiles(const PVecPath & listInputFile, const PString & libName, const PVecArchLib & vecArchLib,
119 const PPath & libDir, const PPath & outputDir)
120{
121 bool b(true);
122 for(PVecPath::const_iterator it(listInputFile.begin()); it != listInputFile.end(); ++it){
123 b &= createSourceFromConfig(*it, libName, vecArchLib, libDir, outputDir);
124 }
125 return b - 1;
126}
127
128int main(int argc, char** argv){
129 OptionParser parser = createOptionParser();
130 parser.parseArgument(argc, argv);
131
132 const OptionMode & defaultMode = parser.getDefaultMode();
133 PVecPath listInputFile;
134 defaultMode.getValue(listInputFile, "header");
135
136 PPath outputDir("."), libDir("");
137 PString libName("");
138 defaultMode.getValue(outputDir, "output");
139 defaultMode.getValue(libName, "library");
140 defaultMode.getValue(libDir, "libdir");
141
142 PVecArchLib vecArchLib;
143 parseVecArchLib(vecArchLib, defaultMode);
144
145 return processFiles(listInputFile, libName, vecArchLib, libDir, outputDir);
146}
147
148
bool cpp_backend(PSource &source, const PString &libName, const PPath &outputDir)
Save a vector of PSource in the output directory.
Definition backend.cpp:190
bool cpp_backend_proxy(const PVecSource &vecSource, const PString &libraryName, const PVecArchLib &vecArchLib, const PPath &libDir, const PPath &outputDir)
Save ProxyLoader with the corresponding a vector of PSource in the output directory.
Parse the configuration a create the vector of sources.
const PVecSource & getVecSource() const
Get the parsed vector of PSource.
int main(int argc, char **argv)
Definition main.cpp:128
void parseVecArchLib(PVecArchLib &vecArchLib, const OptionMode &defaultMode)
Parse the vector of library architecture.
Definition main.cpp:50
int processFiles(const PVecPath &listInputFile, const PString &libName, const PVecArchLib &vecArchLib, const PPath &libDir, const PPath &outputDir)
Process all the input files.
Definition main.cpp:118
bool createSourceFromConfig(const PString &inputFile, const PString &libraryName, const PVecArchLib &vecArchLib, const PString &libDir, const PString &outputDir)
Create the source from configuration file.
Definition main.cpp:83
OptionParser createOptionParser()
Create the OptionParser of this program.
Definition main.cpp:18
PPath getLibraryFile(const PVecArchLib &vecArch)
Get the first non empty library file name.
void addArch(PVecArchLib &vecArch, const PString &arch, const PString &libName)
Add a PArchLib in the vector of Architecture if the libName is not empty.
std::vector< PSource > PVecSource
std::vector< PArchLib > PVecArchLib