8 #include "cMakeHeader.h" 9 #include "columns/CommandLineArguments.hpp" 10 #include "columns/ConfigFileArguments.hpp" 11 #include "columns/HyPerCol.hpp" 12 #include "utils/PVLog.hpp" 14 #ifdef PV_USE_OPENMP_THREADS 16 #endif // PV_USE_OPENMP_THREADS 26 mArgV.resize(mArgC + 1);
27 for (
int a = 0; a < mArgC; a++) {
28 mArgV[a] = argv[0][a];
31 mCommunicator =
nullptr;
35 if (mArgC >= 2 && mArgV[1] !=
nullptr && mArgV[1][0] !=
'-') {
40 std::string{mArgV[1]}, MPI_COMM_WORLD, allowUnrecognizedArguments);
43 for (
int arg = 2; arg < mArgC; arg++) {
44 if (pv_getopt(mArgC, mArgV.data(),
"--require-return",
nullptr) == 0) {
63 int PV_Init::initSignalHandler() {
76 sigemptyset(&blockusr1);
77 sigaddset(&blockusr1, SIGUSR1);
78 sigprocmask(SIG_BLOCK, &blockusr1, NULL);
85 int status = PV_SUCCESS;
91 if (!paramsFile.empty()) {
98 int PV_Init::initMaxThreads() {
99 #ifdef PV_USE_OPENMP_THREADS 100 maxThreads = omp_get_max_threads();
101 #else // PV_USE_OPENMP_THREADS 103 #endif // PV_USE_OPENMP_THREADS 107 int PV_Init::commInit(
int *argc,
char ***argv) {
119 MPI_Initialized(&mpiInit);
121 pvAssert((*argv)[*argc] == NULL);
122 MPI_Init(argc, argv);
125 Fatal() <<
"PV_Init communicator already initialized\n";
144 int const globalRootProcess = 0;
146 MPI_Comm_rank(MPI_COMM_WORLD, &globalRank);
147 std::ios_base::openmode mode =
148 appendFlag ? std::ios_base::out | std::ios_base::app : std::ios_base::out;
149 if (!logFile.empty() && globalRank != globalRootProcess) {
157 std::string logFileString(logFile);
158 size_t finalSlash = logFileString.rfind(
'/');
159 size_t finalDot = logFileString.rfind(
'.');
160 size_t insertionPoint;
161 if (finalDot == std::string::npos
162 || (finalSlash != std::string::npos && finalDot < finalSlash)) {
163 insertionPoint = logFileString.length();
166 insertionPoint = finalDot;
168 std::string insertion(
"_");
169 insertion.append(std::to_string(globalRank));
170 logFileString.insert(insertionPoint, insertion);
171 PV::setLogFile(logFileString, mode);
174 PV::setLogFile(logFile, mode);
179 if (params_file ==
nullptr) {
189 if (!paramsFile.empty()) {
193 2 * (INITIAL_LAYER_ARRAY_SIZE + INITIAL_CONNECTION_ARRAY_SIZE),
203 std::string logFileString{logFile};
217 if (batchWidth >= 0) {
226 if (communicator ==
nullptr or communicator->globalCommRank() == 0) {
227 time_t currentTime = time(
nullptr);
228 InfoLog() <<
"PetaVision initialized at " 229 << ctime(¤tTime);
230 InfoLog() <<
"Configuration is:\n";
232 InfoLog().printf(
"----------------\n");
242 int status = Factory::instance()->registerKeyword(keyword, creator);
243 if (status != PV_SUCCESS) {
244 if (getWorldRank() == 0) {
245 ErrorLog().printf(
"PV_Init: keyword \"%s\" has already been registered.\n", keyword);
252 char **argumentArray = (
char **)pvMallocError(
253 (
size_t)(mArgC + 1) *
sizeof(
char *),
254 "PV_Init::getArgsCopy allocate memory for %d arguments: %s\n",
257 for (
int a = 0; a < mArgC; a++) {
258 char const *arga = mArgV[a];
260 char *copied = strdup(arga);
262 ErrorLog().printf(
"PV_Init unable to store argument %d: %s\n", a, strerror(errno));
263 Fatal().printf(
"Argument was \"%s\".\n", arga);
265 argumentArray[a] = copied;
268 argumentArray[a] =
nullptr;
271 argumentArray[mArgC] =
nullptr;
272 return argumentArray;
276 for (
int k = 0; k < argc; k++) {
282 int PV_Init::commFinalize() {
int setLogFile(char const *val, bool appendFlag=false)
bool setBooleanArgument(std::string const &name, bool const &value)
static void freeArgs(int argc, char **argv)
bool setStringArgument(std::string const &name, std::string const &value)
std::string const & getStringArgument(std::string const &name) const
void resetState(std::istream &configStream, bool allowUnrecognizedArguments)
PV_Init(int *argc, char **argv[], bool allowUnrecognizedArguments)
bool setIntegerArgument(std::string const &name, int const &value)
void initLogFile(bool appendFlag)
char ** getArgsCopy() const
int setParams(char const *paramsFile)
int registerKeyword(char const *keyword, ObjectCreateFn creator)
int setMPIConfiguration(int rows, int columns, int batchwidth)