-
Notifications
You must be signed in to change notification settings - Fork 1
/
clrosetta.cpp
137 lines (107 loc) · 3.94 KB
/
clrosetta.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//-------------------------------------------------------------------
// Author........: Aleksander šhrn
// Date..........: 9903
// Description...: Simple utility that enables ROSETTA script files
// to be run from the DOS command line.
// Revisions.....:
//===================================================================
#ifdef WIN32
#include <stdafx.h> // Precompiled headers.
#endif
#include <common/installer.h>
#include <common/objectmanager.h>
#include <common/configuration.h>
#include <kernel/basic/idholder.h>
#include <kernel/basic/message.h>
#include <kernel/utilities/creator.h>
#include <kernel/system/iostream.h>
//#include <kernel/utilities/license.h>
//No longer supporting single-cores. -N
#include "omp.h"
#include <kernel/utilities/threadcontrol.h>
//-------------------------------------------------------------------
// Method........: main
// Author........: Aleksander šhrn, Lukasz Ligowski
// Date..........: 9903
// Description...:
// Comments......: The current handling of command-line options is
// very ugly and ad hoc. Use getopt instead.
// Revisions.....: Added license checking.
//===================================================================
int
main(int argc, char *argv[]) {
//if (!License::CheckLicense()){
// return 100;
//}
// Expected number of arguments?
if (argc != 3 && argc != 4) {
cout << "Usage: " << argv[0] << " <algorithm> <parameter list> [<input filename>]" << endl;
cout << "Did you quote the parameter list, if needed?" << endl;
return 0;
}
// Load settings.
Configuration::Kernel::Load("rosetta.cfg");
// Name the parameters.
String algorithmname = argv[1];
String parameterlist = argv[2];
// Write some yada yada.
cout << "ROSETTA kernel version " << Configuration::Kernel::GetVersion() << endl;
#if defined(_DEBUG)
cout << "Debug build ";
#else
cout << "Release build ";
#endif
cout << Configuration::GetCompilationTime() << " " << Configuration::GetCompilationDate() << endl;
cout << parameterlist << endl;
String inputfilename = (argc == 4) ? argv[3] : Undefined::String();
// Valid algorithm name?
Id id = IdHolder::GetId(algorithmname);
if (id == Undefined::Id()) {
Message::Error(algorithmname + " is not a recognized algorithm.");
return 1;
}
// Install prototypes.
Installer::Install();
// Specified algorithm installed?
if (!ObjectManager::IsInstalled(id)) {
Message::Error(algorithmname + " is not an installed algorithm.");
return 1;
}
// Acquire algorithm.
Handle<Algorithm> algorithm = ObjectManager::GetIdentifiedAlgorithm(id);
#ifdef _OPENMP
omp_set_dynamic(true);
omp_set_nested(false);
//ThreadControl::SetMaxThreads( omp_get_num_procs() * 2);
//ThreadControl::SetMaxThreads(10);
//omp_set_num_threads(5);
#endif
cout << "Dynamic: " << omp_get_dynamic() << endl;
cout << "Nested: " << omp_get_nested() << endl;
cout << "Max Threads: " << omp_get_max_threads() << endl;
// Set parameters.
if (!algorithm->SetParameters(parameterlist))
return 1;
cout << "Dynamic: " << omp_get_dynamic() << endl;
cout << "Nested: " << omp_get_nested() << endl;
cout << "Max Threads: " << omp_get_max_threads() << endl;
Handle<Structure> structure;
// Create the starting point. Don't bother with setting up the ProjectManager,
// assume for now that the algorithm is an Executor (where this is done).
if (inputfilename == Undefined::String())
structure = Creator::Create(PROJECT);
else
// cout << "Loadfile: |" << inputfilename << "|" << endl;
structure = Creator::Load(inputfilename);
if (structure == NULL) {
Message::Error("Failed to load " + inputfilename + ".");
return 1;
}
// Apply.
if (structure->Apply(*algorithm) == NULL) {
Message::Error("Execution of " + algorithmname + " failed.");
return 1;
}
cout << algorithmname << " executed successfully." << endl;
return 0;
}