diff --git a/Simulator/Connections/Neuro/ConnGrowth.cpp b/Simulator/Connections/Neuro/ConnGrowth.cpp index beaad1660..fe89f41b3 100644 --- a/Simulator/Connections/Neuro/ConnGrowth.cpp +++ b/Simulator/Connections/Neuro/ConnGrowth.cpp @@ -44,6 +44,7 @@ #include "OperationManager.h" #include "ParameterManager.h" #include "ParseParamError.h" +#include #ifdef USE_HDF5 #include "Hdf5Recorder.h" @@ -324,7 +325,10 @@ void ConnGrowth::updateEdgesWeights() /// Prints radii void ConnGrowth::printRadii() const { + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); for (int i = 0; i < radiiSize_; i++) { - cout << "radii[" << i << "] = " << radii_[i] << endl; + // cout << "radii[" << i << "] = " << radii_[i] << endl; + string msg = "radii[" + to_string(i) + "] = " + to_string(radii_[i]); + LOG4CPLUS_TRACE(consoleLogger, msg); } } diff --git a/Simulator/Core/Core.cpp b/Simulator/Core/Core.cpp index 6c206ed36..876759f71 100644 --- a/Simulator/Core/Core.cpp +++ b/Simulator/Core/Core.cpp @@ -25,7 +25,8 @@ #include "ParameterManager.h" #include "Serializer.h" #include "config.h" // build/config.h contains the git commit id - +#include +#include // Uncomment to use visual leak detector (Visual Studios Plugin) // #include #if defined(USE_GPU) @@ -51,6 +52,8 @@ bool Core::parseCommandLine(string executableName, string cmdLineArguments) "The UW Bothell graph-based simulation environment, for high-performance neural network and other graph-based problems\n Usage: " + executableName + " ")); + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + // Set up the comment line parser. if ((cl.addParam("configfile", 'c', ParamContainer::filename, "parameter configuration filepath") != ParamContainer::errOk) @@ -69,7 +72,7 @@ bool Core::parseCommandLine(string executableName, string cmdLineArguments) || (cl.addParam("version", 'v', ParamContainer::novalue, "output current git commit ID and exit") != ParamContainer::errOk)) { - cerr << "Internal error creating command line parser" << endl; + LOG4CPLUS_FATAL(consoleLogger, ("Internal error creating command line parser\n")); return false; } @@ -80,7 +83,9 @@ bool Core::parseCommandLine(string executableName, string cmdLineArguments) } if (cl["version"].compare("") != 0) { - cout << "Git commit ID: " << GIT_COMMIT_ID << endl; + string str(GIT_COMMIT_ID); + string message = "Git commit ID: " + str + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); exit(0); } @@ -243,8 +248,14 @@ int Core::runSimulation(string executableName, string cmdLineArguments) time(&end_time); double timeElapsed = difftime(end_time, start_time); double ssps = simulator.getEpochDuration() * simulator.getNumEpochs() / timeElapsed; - cout << "time simulated: " << simulator.getEpochDuration() * simulator.getNumEpochs() << endl; - cout << "time elapsed: " << timeElapsed << endl; - cout << "ssps (simulation seconds / real time seconds): " << ssps << endl; + // cout << "time simulated: " << simulator.getEpochDuration() * simulator.getNumEpochs() << endl; + // cout << "time elapsed: " << timeElapsed << endl; + // cout << "ssps (simulation seconds / real time seconds): " << ssps << endl; + string message = "time simulated: " + to_string(simulator.getEpochDuration() * simulator.getNumEpochs()) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = "time elapsed: " + to_string(timeElapsed) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = "ssps (simulation seconds / real time seconds): " + to_string(ssps) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); return 0; } \ No newline at end of file diff --git a/Simulator/Core/Serializer.cpp b/Simulator/Core/Serializer.cpp index 2911ffab8..9631b7bbd 100644 --- a/Simulator/Core/Serializer.cpp +++ b/Simulator/Core/Serializer.cpp @@ -48,9 +48,11 @@ bool Serializer::deserialize() ifstream memory_in(simulator.getDeserializationFileName().c_str()); //ifstream memory_in (simInfo->memInputFileName.c_str(), std::ios::binary); + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + // Checks to see if serialization file exists if (!memory_in) { - cerr << "The serialization file doesn't exist" << endl; + LOG4CPLUS_FATAL(consoleLogger, "The serialization file doesn't exist"); return false; } @@ -60,7 +62,7 @@ bool Serializer::deserialize() //cereal::BinaryInputArchive archive(memory_in); if (!processArchive(archive, simulator)) { - cerr << "Failed to deserialize" << endl; + LOG4CPLUS_FATAL(consoleLogger, "Failed to deserialize"); return false; } @@ -79,17 +81,19 @@ void Serializer::serialize() { Simulator &simulator = Simulator::getInstance(); + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + // We can serialize to a variety of archive file formats. Below, comment out // all but the two lines that correspond to the desired format. ofstream memory_out(simulator.getSerializationFileName().c_str()); - cout << "Please find the serialized file in " << simulator.getSerializationFileName().c_str(); - + string message = "Please find the serialized file in " + simulator.getSerializationFileName(); + LOG4CPLUS_TRACE(consoleLogger, message); cereal::XMLOutputArchive archive(memory_out); //ofstream memory_out (simInfo->memOutputFileName.c_str(), std::ios::binary); //cereal::BinaryOutputArchive archive(memory_out); if (!processArchive(archive, simulator)) { - cerr << "Failed to serialize" << endl; + LOG4CPLUS_ERROR(consoleLogger, "Failed to serialize"); } } @@ -103,7 +107,8 @@ template bool Serializer::processArchive(Archive &archive, Si // Serialize/Deserialize required global variables archive(initRNG, noiseRNG, g_simulationStep); } catch (cereal::Exception e) { - cerr << e.what() << endl; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + LOG4CPLUS_ERROR(consoleLogger, e.what()); return false; } return true; diff --git a/Simulator/Core/Simulator.cpp b/Simulator/Core/Simulator.cpp index e4a42d9df..874693c40 100644 --- a/Simulator/Core/Simulator.cpp +++ b/Simulator/Core/Simulator.cpp @@ -172,7 +172,7 @@ void Simulator::simulate() // Time since start of simulation double total_time = timer.lap() / 1000000.0; - cout << "\ntotal_time: " << total_time << " seconds" << endl; + LOG4CPLUS_TRACE(consoleLogger_, "\ntotal_time: " << total_time << " seconds"); printPerformanceMetrics(total_time, currentEpoch); cout << endl; #endif diff --git a/Simulator/Edges/Neuro/AllDSSynapses.cpp b/Simulator/Edges/Neuro/AllDSSynapses.cpp index 6f12ab551..6a3c6b0c3 100644 --- a/Simulator/Edges/Neuro/AllDSSynapses.cpp +++ b/Simulator/Edges/Neuro/AllDSSynapses.cpp @@ -187,15 +187,23 @@ void AllDSSynapses::changePSR(BGSIZE iEdg, BGFLOAT deltaT) void AllDSSynapses::printSynapsesProps() const { AllSpikingSynapses::printSynapsesProps(); + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); for (int i = 0; i < maxEdgesPerVertex_ * countVertices_; i++) { if (W_[i] != 0.0) { - cout << "lastSpike[" << i << "] = " << lastSpike_[i]; - cout << " r: " << r_[i]; - cout << " u: " << u_[i]; - cout << " D: " << D_[i]; - cout << " U: " << U_[i]; - cout << " F: " << F_[i] << endl; + string message = ("lastSpike[" + to_string(i) + "] = " + to_string(lastSpike_[i])); + LOG4CPLUS_INFO(consoleLogger, message); + message = (" r: " + to_string(r_[i])); + LOG4CPLUS_INFO(consoleLogger, message); + message = (" u: " + to_string(u_[i])); + LOG4CPLUS_INFO(consoleLogger, message); + message = (" D: " + to_string(D_[i])); + LOG4CPLUS_INFO(consoleLogger, message); + message = (" U: " + to_string(U_[i])); + LOG4CPLUS_INFO(consoleLogger, message); + message = (" F: " + to_string(F_[i]) + "\n"); + LOG4CPLUS_INFO(consoleLogger, message); } } - cout << endl; + LOG4CPLUS_INFO(consoleLogger, endl); + } diff --git a/Simulator/Edges/Neuro/AllDSSynapses_d.cpp b/Simulator/Edges/Neuro/AllDSSynapses_d.cpp index c1939d882..fc7dfedb2 100644 --- a/Simulator/Edges/Neuro/AllDSSynapses_d.cpp +++ b/Simulator/Edges/Neuro/AllDSSynapses_d.cpp @@ -302,25 +302,43 @@ void AllDSSynapses::printGPUEdgesProps(void *allEdgesDeviceProps) const cudaMemcpy(FPrint, allSynapsesProps.F_, size * sizeof(BGFLOAT), cudaMemcpyDeviceToHost)); + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + for (int i = 0; i < size; i++) { if (WPrint[i] != 0.0) { - cout << "GPU W[" << i << "] = " << WPrint[i]; - cout << " GPU sourNeuron: " << sourceNeuronIndexPrint[i]; - cout << " GPU desNeuron: " << destNeuronIndexPrint[i]; - cout << " GPU type: " << typePrint[i]; - cout << " GPU psr: " << psrPrint[i]; - cout << " GPU in_use:" << (inUsePrint[i] == 1 ? "true" : "false"); - - cout << " GPU decay: " << decayPrint[i]; - cout << " GPU tau: " << tauPrint[i]; - cout << " GPU total_delay: " << totalDelayPrint[i]; - - cout << " GPU lastSpike: " << lastSpikePrint[i]; - cout << " GPU r: " << rPrint[i]; - cout << " GPU u: " << uPrint[i]; - cout << " GPU D: " << DPrint[i]; - cout << " GPU U: " << UPrint[i]; - cout << " GPU F: " << FPrint[i] << endl; + string message = ("GPU W[" + to_string(i) + "] = " + to_string(WPrint[i])); + LOG4CPLUS_INFO(consoleLogger, message); + message = (" GPU sourNeuron: " + sourceNeuronIndexPrint[i]); + LOG4CPLUS_INFO(consoleLogger, message); + message = (" GPU desNeuron: " + destNeuronIndexPrint[i]); + LOG4CPLUS_INFO(consoleLogger, message); + int currType = (int)typePrint[i]; + message = (" GPU type: " + to_string(currType)); + LOG4CPLUS_INFO(consoleLogger, message); + message = (" GPU psr: " + to_string(psrPrint[i])); + LOG4CPLUS_INFO(consoleLogger, message); + message = (" GPU in_use:" + inUsePrint[i]); + LOG4CPLUS_INFO(consoleLogger, message); + + message = (" GPU decay: " + to_string(decayPrint[i])); + LOG4CPLUS_INFO(consoleLogger, message); + message = (" GPU tau: " + to_string(tauPrint[i])); + LOG4CPLUS_INFO(consoleLogger, message); + message = (" GPU total_delay: " + totalDelayPrint[i]); + LOG4CPLUS_INFO(consoleLogger, message); + + message = (" GPU lastSpike: " + lastSpikePrint[i]); + LOG4CPLUS_INFO(consoleLogger, message); + message = (" GPU r: " + to_string(rPrint[i])); + LOG4CPLUS_INFO(consoleLogger, message); + message = (" GPU u: " + to_string(uPrint[i])); + LOG4CPLUS_INFO(consoleLogger, message); + message = (" GPU D: " + to_string(DPrint[i])); + LOG4CPLUS_INFO(consoleLogger, message); + message = (" GPU U: " + to_string(UPrint[i])); + LOG4CPLUS_INFO(consoleLogger, message); + message = (" GPU F: " + to_string(FPrint[i]) + "\n"); + LOG4CPLUS_INFO(consoleLogger, message); } } diff --git a/Simulator/Edges/Neuro/AllDynamicSTDPSynapses.cpp b/Simulator/Edges/Neuro/AllDynamicSTDPSynapses.cpp index 966a10f40..453ce51c8 100644 --- a/Simulator/Edges/Neuro/AllDynamicSTDPSynapses.cpp +++ b/Simulator/Edges/Neuro/AllDynamicSTDPSynapses.cpp @@ -187,14 +187,15 @@ void AllDynamicSTDPSynapses::changePSR(BGSIZE iEdg, BGFLOAT deltaT) void AllDynamicSTDPSynapses::printSynapsesProps() const { AllSTDPSynapses::printSynapsesProps(); + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); for (int i = 0; i < maxEdgesPerVertex_ * countVertices_; i++) { if (W_[i] != 0.0) { - cout << "lastSpike[" << i << "] = " << lastSpike_[i]; - cout << " r: " << r_[i]; - cout << " u: " << u_[i]; - cout << " D: " << D_[i]; - cout << " U: " << U_[i]; - cout << " F: " << F_[i] << endl; + LOG4CPLUS_TRACE(consoleLogger, "lastSpike[" << i << "] = " << lastSpike_[i]); + LOG4CPLUS_TRACE(consoleLogger, " r: " << r_[i]); + LOG4CPLUS_TRACE(consoleLogger, " u: " << u_[i]); + LOG4CPLUS_TRACE(consoleLogger, " D: " << D_[i]); + LOG4CPLUS_TRACE(consoleLogger, " U: " << U_[i]); + LOG4CPLUS_TRACE(consoleLogger, " F: " << F_[i] << endl); } } } diff --git a/Simulator/Edges/Neuro/AllDynamicSTDPSynapses_d.cpp b/Simulator/Edges/Neuro/AllDynamicSTDPSynapses_d.cpp index f4ef0e2c7..6b40fe723 100644 --- a/Simulator/Edges/Neuro/AllDynamicSTDPSynapses_d.cpp +++ b/Simulator/Edges/Neuro/AllDynamicSTDPSynapses_d.cpp @@ -344,48 +344,49 @@ void AllDynamicSTDPSynapses::printGPUEdgesProps(void *allEdgesDeviceProps) const HANDLE_ERROR( cudaMemcpy(FPrint, allSynapsesProps.F_, size * sizeof(BGFLOAT), cudaMemcpyDeviceToHost)); + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); for (int i = 0; i < maxEdgesPerVertex_ * countVertices_; i++) { if (WPrint[i] != 0.0) { - cout << "GPU W[" << i << "] = " << WPrint[i]; - cout << " GPU sourNeuron: " << sourceNeuronIndexPrint[i]; - cout << " GPU desNeuron: " << destNeuronIndexPrint[i]; - cout << " GPU type: " << typePrint[i]; - cout << " GPU psr: " << psrPrint[i]; - cout << " GPU in_use:" << (inUsePrint[i] == 1 ? "true" : "false"); - - cout << " GPU decay: " << decayPrint[i]; - cout << " GPU tau: " << tauPrint[i]; - cout << " GPU total_delay: " << totalDelayPrint[i]; - - cout << " GPU total_delayPost: " << totalDelayPostPrint[i]; - cout << " GPU tauspost_: " << tauspost_Print[i]; - cout << " GPU tauspre_: " << tauspre_Print[i]; - cout << " GPU taupos_: " << taupos_Print[i]; - cout << " GPU tauneg_: " << tauneg_Print[i]; - cout << " GPU STDPgap_: " << STDPgap_Print[i]; - cout << " GPU Wex_: " << Wex_Print[i]; - cout << " GPU Aneg_: " << Aneg_Print[i]; - cout << " GPU Apos_: " << Apos_Print[i]; - cout << " GPU mupos_: " << mupos_Print[i]; - cout << " GPU muneg_: " << muneg_Print[i]; - cout << " GPU useFroemkeDanSTDP_: " << useFroemkeDanSTDP_Print[i]; - - cout << " GPU lastSpike: " << lastSpikePrint[i]; - cout << " GPU r: " << rPrint[i]; - cout << " GPU u: " << uPrint[i]; - cout << " GPU D: " << DPrint[i]; - cout << " GPU U: " << UPrint[i]; - cout << " GPU F: " << FPrint[i] << endl; + LOG4CPLUS_INFO(consoleLogger, "GPU W[" << i << "] = " << WPrint[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU sourNeuron: " << sourceNeuronIndexPrint[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU desNeuron: " << destNeuronIndexPrint[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU type: " << typePrint[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU psr: " << psrPrint[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU in_use:" << (inUsePrint[i] == 1 ? "true" : "false")); + + LOG4CPLUS_INFO(consoleLogger, " GPU decay: " << decayPrint[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU tau: " << tauPrint[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU total_delay: " << totalDelayPrint[i]); + + LOG4CPLUS_INFO(consoleLogger, " GPU total_delayPost: " << totalDelayPostPrint[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU tauspost_: " << tauspost_Print[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU tauspre_: " << tauspre_Print[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU taupos_: " << taupos_Print[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU tauneg_: " << tauneg_Print[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU STDPgap_: " << STDPgap_Print[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU Wex_: " << Wex_Print[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU Aneg_: " << Aneg_Print[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU Apos_: " << Apos_Print[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU mupos_: " << mupos_Print[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU muneg_: " << muneg_Print[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU useFroemkeDanSTDP_: " << useFroemkeDanSTDP_Print[i]); + + LOG4CPLUS_INFO(consoleLogger, " GPU lastSpike: " << lastSpikePrint[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU r: " << rPrint[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU u: " << uPrint[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU D: " << DPrint[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU U: " << UPrint[i]); + LOG4CPLUS_INFO(consoleLogger, " GPU F: " << FPrint[i] << endl); } } for (int i = 0; i < countVertices_; i++) { - cout << "GPU edge_counts:" << "neuron[" << i << "]" << synapseCountsPrint[i] << endl; + LOG4CPLUS_INFO(consoleLogger, "GPU edge_counts:" << "neuron[" << i << "]" << synapseCountsPrint[i] << endl); } - cout << "GPU totalSynapseCount:" << totalSynapseCountPrint << endl; - cout << "GPU maxEdgesPerVertex:" << maxEdgesPerVertexPrint << endl; - cout << "GPU countVertices_:" << countNeuronsPrint << endl; + LOG4CPLUS_INFO(consoleLogger, "GPU totalSynapseCount:" << totalSynapseCountPrint << endl); + LOG4CPLUS_INFO(consoleLogger, "GPU maxEdgesPerVertex:" << maxEdgesPerVertexPrint << endl); + LOG4CPLUS_INFO(consoleLogger, "GPU countVertices_:" << countNeuronsPrint << endl); // Set countVertices_ to 0 to avoid illegal memory deallocation diff --git a/Simulator/Edges/Neuro/AllNeuroEdges.cpp b/Simulator/Edges/Neuro/AllNeuroEdges.cpp index 5596bb840..06dbe6947 100644 --- a/Simulator/Edges/Neuro/AllNeuroEdges.cpp +++ b/Simulator/Edges/Neuro/AllNeuroEdges.cpp @@ -101,23 +101,25 @@ int AllNeuroEdges::edgSign(const edgeType type) /// Prints SynapsesProps data to console. void AllNeuroEdges::printSynapsesProps() const { - cout << "This is SynapsesProps data:" << endl; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + LOG4CPLUS_TRACE(consoleLogger, "This is SynapsesProps data:" << endl); for (int i = 0; i < maxEdgesPerVertex_ * countVertices_; i++) { if (W_[i] != 0.0) { - cout << "W[" << i << "] = " << W_[i]; - cout << " sourNeuron: " << sourceVertexIndex_[i]; - cout << " desNeuron: " << destVertexIndex_[i]; - cout << " type: " << type_[i]; - cout << " psr: " << psr_[i]; - cout << " in_use:" << (inUse_[i] == 1 ? "true" : "false"); + string message = "W[" + to_string(i) + "] = " + to_string(W_[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + LOG4CPLUS_TRACE(consoleLogger, " sourNeuron: " << sourceVertexIndex_[i]); + LOG4CPLUS_TRACE(consoleLogger, " desNeuron: " << destVertexIndex_[i]); + LOG4CPLUS_TRACE(consoleLogger, " type: " << type_[i]); + LOG4CPLUS_TRACE(consoleLogger, " psr: " << psr_[i]); + LOG4CPLUS_TRACE(consoleLogger, " in_use:" << (inUse_[i] == 1 ? "true" : "false")); } } for (int i = 0; i < countVertices_; i++) { - cout << "edge_counts:" << "vertex[" << i << "]" << edgeCounts_[i] << endl; + LOG4CPLUS_TRACE(consoleLogger, "edge_counts:" << "vertex[" << i << "]" << edgeCounts_[i] << endl); } - cout << "totalEdgeCount:" << totalEdgeCount_ << endl; - cout << "maxEdgesPerVertex:" << maxEdgesPerVertex_ << endl; - cout << "count_neurons:" << countVertices_ << endl; + LOG4CPLUS_TRACE(consoleLogger, "totalEdgeCount:" << totalEdgeCount_ << endl); + LOG4CPLUS_TRACE(consoleLogger, "maxEdgesPerVertex:" << maxEdgesPerVertex_ << endl); + LOG4CPLUS_TRACE(consoleLogger, "count_neurons:" << countVertices_ << endl); } diff --git a/Simulator/Edges/Neuro/AllSTDPSynapses.cpp b/Simulator/Edges/Neuro/AllSTDPSynapses.cpp index 1f227a35a..c2e841c9b 100644 --- a/Simulator/Edges/Neuro/AllSTDPSynapses.cpp +++ b/Simulator/Edges/Neuro/AllSTDPSynapses.cpp @@ -498,19 +498,20 @@ bool AllSTDPSynapses::allowBackPropagation() void AllSTDPSynapses::printSynapsesProps() const { AllSpikingSynapses::printSynapsesProps(); + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); for (int i = 0; i < maxEdgesPerVertex_ * countVertices_; i++) { if (W_[i] != 0.0) { - cout << "total_delayPost[" << i << "] = " << totalDelayPost_[i]; - cout << " tauspost_: " << tauspost_[i]; - cout << " tauspre_: " << tauspre_[i]; - cout << " taupos_: " << taupos_[i]; - cout << " tauneg_: " << tauneg_[i]; - cout << " STDPgap_: " << STDPgap_[i]; - cout << " Wex_: " << Wex_[i]; - cout << " Aneg_: " << Aneg_[i]; - cout << " Apos_: " << Apos_[i]; - cout << " mupos_: " << mupos_[i]; - cout << " muneg_: " << muneg_[i] << endl; + LOG4CPLUS_TRACE(consoleLogger, "total_delayPost[" << i << "] = " << totalDelayPost_[i]); + LOG4CPLUS_TRACE(consoleLogger, " tauspost_: " << tauspost_[i]); + LOG4CPLUS_TRACE(consoleLogger, " tauspre_: " << tauspre_[i]); + LOG4CPLUS_TRACE(consoleLogger, " taupos_: " << taupos_[i]); + LOG4CPLUS_TRACE(consoleLogger, " tauneg_: " << tauneg_[i]); + LOG4CPLUS_TRACE(consoleLogger, " STDPgap_: " << STDPgap_[i]); + LOG4CPLUS_TRACE(consoleLogger, " Wex_: " << Wex_[i]); + LOG4CPLUS_TRACE(consoleLogger, " Aneg_: " << Aneg_[i]); + LOG4CPLUS_TRACE(consoleLogger, " Apos_: " << Apos_[i]); + LOG4CPLUS_TRACE(consoleLogger, " mupos_: " << mupos_[i]); + LOG4CPLUS_TRACE(consoleLogger, " muneg_: " << muneg_[i] << endl); } } } diff --git a/Simulator/Edges/Neuro/AllSTDPSynapses_d.cpp b/Simulator/Edges/Neuro/AllSTDPSynapses_d.cpp index 2d91d1f11..1d4809b70 100644 --- a/Simulator/Edges/Neuro/AllSTDPSynapses_d.cpp +++ b/Simulator/Edges/Neuro/AllSTDPSynapses_d.cpp @@ -378,38 +378,61 @@ void AllSTDPSynapses::printGPUEdgesProps(void *allEdgesDeviceProps) const cudaMemcpyDeviceToHost)); HANDLE_ERROR(cudaMemcpy(munegPrint, allSynapsesProps.muneg_, size * sizeof(BGFLOAT), cudaMemcpyDeviceToHost)); + + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); for (int i = 0; i < maxEdgesPerVertex_ * countVertices_; i++) { if (WPrint[i] != 0.0) { - cout << "GPU W[" << i << "] = " << WPrint[i]; - cout << " GPU sourNeuron: " << sourceNeuronIndexPrint[i]; - cout << " GPU desNeuron: " << destNeuronIndexPrint[i]; - cout << " GPU type: " << typePrint[i]; - cout << " GPU psr: " << psrPrint[i]; - cout << " GPU in_use:" << (inUsePrint[i] == 1 ? "true" : "false"); - - cout << " GPU decay: " << decayPrint[i]; - cout << " GPU tau: " << tauPrint[i]; - cout << " GPU total_delay: " << totalDelayPrint[i]; - - cout << " GPU total_delayPost: " << totalDelayPostPrint[i]; - cout << " GPU tauspost_: " << tauspostPrint[i]; - cout << " GPU tauspre_: " << tausprePrint[i]; - cout << " GPU taupos_: " << tauposPrint[i]; - cout << " GPU tauneg_: " << taunegPrint[i]; - cout << " GPU STDPgap_: " << STDPgapPrint[i]; - cout << " GPU Wex_: " << WexPrint[i]; - cout << " GPU Aneg_: " << AnegPrint[i]; - cout << " GPU Apos_: " << AposPrint[i]; - cout << " GPU mupos_: " << muposPrint[i]; - cout << " GPU muneg_: " << munegPrint[i] << endl; + string message = "GPU W[" + to_string(i) + "] = " + to_string(WPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU sourNeuron: " + to_string(sourceNeuronIndexPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU desNeuron: " + to_string(destNeuronIndexPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + int type = (int)typePrint[i]; + message = " GPU type: " + to_string(type) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU psr: " + to_string(psrPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU in_use: " + string(inUsePrint[i] == 1 ? "true" : "false") + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + + message = " GPU decay: " + to_string(decayPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU tau: " + to_string(tauPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU total_delay: " + to_string(totalDelayPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + + message = " GPU total_delayPost: " + to_string(totalDelayPostPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU tauspost_: " + to_string(tauspostPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU tauspre_: " + to_string(tausprePrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU taupos_: " + to_string(tauposPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU tauneg_: " + to_string(taunegPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU STDPgap_: " + to_string(STDPgapPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU Wex_: " + to_string(WexPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU Aneg_: " + to_string(AnegPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU Apos_: " + to_string(AposPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU mupos_: " + to_string(muposPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU muneg_: " + to_string(munegPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); } } for (int i = 0; i < countVertices_; i++) { - cout << "GPU edge_counts:" << "neuron[" << i << "]" << synapseCountsPrint[i] << endl; + LOG4CPLUS_TRACE(consoleLogger, "GPU edge_counts:" << "neuron[" << i << "]" << synapseCountsPrint[i] << endl); } - cout << "GPU totalSynapseCount:" << totalSynapseCountPrint << endl; - cout << "GPU maxEdgesPerVertex:" << maxEdgesPerVertexPrint << endl; - cout << "GPU countVertices_:" << countNeuronsPrint << endl; + LOG4CPLUS_TRACE(consoleLogger, "GPU totalSynapseCount:" << totalSynapseCountPrint << endl); + LOG4CPLUS_TRACE(consoleLogger, "GPU maxEdgesPerVertex:" << maxEdgesPerVertexPrint << endl); + LOG4CPLUS_TRACE(consoleLogger, "GPU countVertices_:" << countNeuronsPrint << endl); // Set countVertices_ to 0 to avoid illegal memory deallocation // at AllDSSynapsesProps deconstructor. diff --git a/Simulator/Edges/Neuro/AllSpikingSynapses.cpp b/Simulator/Edges/Neuro/AllSpikingSynapses.cpp index 0c7b54bb3..c04a556b1 100644 --- a/Simulator/Edges/Neuro/AllSpikingSynapses.cpp +++ b/Simulator/Edges/Neuro/AllSpikingSynapses.cpp @@ -325,11 +325,12 @@ bool AllSpikingSynapses::allowBackPropagation() void AllSpikingSynapses::printSynapsesProps() const { AllNeuroEdges::printSynapsesProps(); + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); for (int i = 0; i < maxEdgesPerVertex_ * countVertices_; i++) { if (W_[i] != 0.0) { - cout << "decay[" << i << "] = " << decay_[i]; - cout << " tau: " << tau_[i]; - cout << " total_delay: " << totalDelay_[i] << endl; + LOG4CPLUS_TRACE(consoleLogger, "decay[" << i << "] = " << decay_[i]); + LOG4CPLUS_TRACE(consoleLogger, " tau: " << tau_[i]); + LOG4CPLUS_TRACE(consoleLogger, " total_delay: " << totalDelay_[i] << endl); } } } diff --git a/Simulator/Edges/Neuro/AllSpikingSynapses_d.cpp b/Simulator/Edges/Neuro/AllSpikingSynapses_d.cpp index e6bb33be0..1512be833 100644 --- a/Simulator/Edges/Neuro/AllSpikingSynapses_d.cpp +++ b/Simulator/Edges/Neuro/AllSpikingSynapses_d.cpp @@ -400,27 +400,41 @@ void AllSpikingSynapses::printGPUEdgesProps(void *allEdgesDeviceProps) const HANDLE_ERROR(cudaMemcpy(totalDelayPrint, allSynapsesProps.totalDelay_, size * sizeof(int), cudaMemcpyDeviceToHost)); - + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); for (int i = 0; i < maxEdgesPerVertex_ * countVertices_; i++) { if (WPrint[i] != 0.0) { - cout << "GPU W[" << i << "] = " << WPrint[i]; - cout << " GPU sourNeuron: " << sourceNeuronIndexPrint[i]; - cout << " GPU desNeuron: " << destNeuronIndexPrint[i]; - cout << " GPU type: " << typePrint[i]; - cout << " GPU psr: " << psrPrint[i]; - cout << " GPU in_use:" << (inUsePrint[i] == 1 ? "true" : "false"); - cout << " GPU decay: " << decayPrint[i]; - cout << " GPU tau: " << tauPrint[i]; - cout << " GPU total_delay: " << totalDelayPrint[i] << endl; + string message = "GPU W[" + to_string(i) + "] = " + to_string(WPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU sourNeuron: " + to_string(sourceNeuronIndexPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU desNeuron: " + to_string(destNeuronIndexPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + int type = (int)typePrint[i]; + message = " GPU type: " + to_string(type) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU psr: " + to_string(psrPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU in_use: " + string(inUsePrint[i] == 1 ? "true" : "false") + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU decay: " + to_string(decayPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU tau: " + to_string(tauPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = " GPU total_delay: " + to_string(totalDelayPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); ; } } for (int i = 0; i < countVertices_; i++) { - cout << "GPU edge_counts:" << "neuron[" << i << "]" << synapseCountsPrint[i] << endl; + string message = "GPU edge_counts: neuron[" + to_string(i) + "]" + to_string(synapseCountsPrint[i]) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); } - cout << "GPU totalSynapseCount:" << totalSynapseCountPrint << endl; - cout << "GPU maxEdgesPerVertex:" << maxEdgesPerVertexPrint << endl; - cout << "GPU countVertices_:" << countNeuronsPrint << endl; + string message = "GPU totalSynapseCount: " + to_string(totalSynapseCountPrint) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = "GPU maxEdgesPerVertex: " + to_string(maxEdgesPerVertexPrint) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = "GPU countVertices_: " + to_string(countNeuronsPrint) + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); // Set countVertices_ to 0 to avoid illegal memory deallocation // at AllDSSynapsesProps deconstructor. allSynapsesProps.countVertices_ = 0; diff --git a/Simulator/Utils/Global.cpp b/Simulator/Utils/Global.cpp index 8b6b0db96..3b2b7aea0 100644 --- a/Simulator/Utils/Global.cpp +++ b/Simulator/Utils/Global.cpp @@ -8,6 +8,7 @@ #include "Global.h" #include "MTRand.h" #include "Norm.h" +#include "Simulator.h" // Debugging log data and routines // see "global.h" for bitmask usage of debug outputs @@ -53,6 +54,7 @@ string coordToString(int x, int y, int z) return ss.str(); } + #if defined(USE_GPU) //! CUDA device ID int g_deviceId = 0; @@ -86,33 +88,48 @@ double t_gpu_calcSummation; void printPerformanceMetrics(const float total_time, int steps) { - cout << "t_gpu_rndGeneration: " << t_gpu_rndGeneration << " ms (" - << t_gpu_rndGeneration / total_time * 100 << "%)" << endl; - cout << "t_gpu_advanceNeurons: " << t_gpu_advanceNeurons << " ms (" - << t_gpu_advanceNeurons / total_time * 100 << "%)" << endl; - cout << "t_gpu_advanceSynapses: " << t_gpu_advanceSynapses << " ms (" - << t_gpu_advanceSynapses / total_time * 100 << "%)" << endl; - cout << "t_gpu_calcSummation: " << t_gpu_calcSummation << " ms (" - << t_gpu_calcSummation / total_time * 100 << "%)" << endl; - - cout << "\nHost initialization (layout): " << t_host_initialization_layout << " seconds (" - << t_host_initialization_layout / total_time * 100 << "%)" << endl; - - cout << "\nHost initialization (connections): " << t_host_initialization_connections - << " seconds (" << t_host_initialization_connections / total_time * 100 << "%)" << endl; - - cout << "\nHost advance: " << t_host_advance << " seconds (" << t_host_advance / total_time * 100 - << "%)" << endl; - - cout << "\nHost adjustEdges: " << t_host_adjustEdges << " seconds (" - << t_host_adjustEdges / total_time * 100 << "%)" << endl; - - cout << "\nAverage time per simulation epoch:" << endl; - - cout << "t_gpu_rndGeneration: " << t_gpu_rndGeneration / steps << " ms/epoch" << endl; - cout << "t_gpu_advanceNeurons: " << t_gpu_advanceNeurons / steps << " ms/epoch" << endl; - cout << "t_gpu_advanceSynapses: " << t_gpu_advanceSynapses / steps << " ms/epoch" << endl; - cout << "t_gpu_calcSummation: " << t_gpu_calcSummation / steps << " ms/epoch" << endl; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + + string message = "t_gpu_rndGeneration: " + to_string(t_gpu_rndGeneration) + " ms (" + + to_string(t_gpu_rndGeneration / total_time * 100) + "%)\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = "t_gpu_advanceNeurons: " + to_string(t_gpu_advanceNeurons) + " ms (" + + to_string(t_gpu_advanceNeurons / total_time * 100) + "%)\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = "t_gpu_advanceSynapses: " + to_string(t_gpu_advanceSynapses) + " ms (" + + to_string(t_gpu_advanceSynapses / total_time * 100) + "%)\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = "t_gpu_calcSummation: " + to_string(t_gpu_calcSummation) + " ms (" + + to_string(t_gpu_calcSummation / total_time * 100) + "%)\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + + message = "\nHost initialization (layout): " + to_string(t_host_initialization_layout) + " seconds (" + + to_string(t_host_initialization_layout / total_time * 100) + "%)\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + + message = "\nHost initialization (connections): " + to_string(t_host_initialization_connections) + + " seconds (" + to_string(t_host_initialization_connections / total_time * 100) + "%)\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + + message = "\nHost advance: " + to_string(t_host_advance) + " seconds (" + + to_string(t_host_advance / total_time * 100) + "%)\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + + message = "\nHost adjustEdges: " + to_string(t_host_adjustEdges) + " seconds (" + + to_string(t_host_adjustEdges / total_time * 100) + "%)\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + + message = "\nAverage time per simulation epoch:\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + + message = "t_gpu_rndGeneration: " + to_string(t_gpu_rndGeneration / steps) + " ms/epoch\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = "t_gpu_advanceNeurons: " + to_string(t_gpu_advanceNeurons / steps) + " ms/epoch\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = "t_gpu_advanceSynapses: " + to_string(t_gpu_advanceSynapses / steps) + " ms/epoch\n"; + LOG4CPLUS_TRACE(consoleLogger, message); + message = "t_gpu_calcSummation: " + to_string(t_gpu_calcSummation / steps) + " ms/epoch\n"; + LOG4CPLUS_TRACE(consoleLogger, message); } #endif // PERFORMANCE_METRICS diff --git a/Simulator/Utils/GraphManager.h b/Simulator/Utils/GraphManager.h index 6430d87ef..9de351361 100644 --- a/Simulator/Utils/GraphManager.h +++ b/Simulator/Utils/GraphManager.h @@ -41,6 +41,7 @@ #include "Global.h" #include "ParameterManager.h" +#include "Simulator.h" #include #include #include @@ -177,19 +178,22 @@ template bool GraphManager::readGr { // Load graphml file into a BGL graph ifstream graph_file; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); // If graphFilePath_ isn't already defined, get it from ParameterManager if (graphFilePath_ == "") { string path = "//graphmlFile/text()"; if (!ParameterManager::getInstance().getStringByXpath(path, graphFilePath_)) { - cerr << "Could not find XML path: " << path << ".\n"; + string message = "Could not find XML path: " + path + ".\n"; + LOG4CPLUS_ERROR(consoleLogger, message); return false; }; } graph_file.open(graphFilePath_.c_str()); if (!graph_file.is_open()) { - cerr << "Failed to open file: " << graphFilePath_ << ".\n"; + string message = "Failed to open file: " + graphFilePath_ + ".\n"; + LOG4CPLUS_ERROR(consoleLogger, message); return false; } diff --git a/Simulator/Utils/Inputs/FSInput.cpp b/Simulator/Utils/Inputs/FSInput.cpp index 41dce1257..89af5d0d7 100644 --- a/Simulator/Utils/Inputs/FSInput.cpp +++ b/Simulator/Utils/Inputs/FSInput.cpp @@ -9,6 +9,7 @@ #include "FSInput.h" #include "HostSInputPoisson.h" #include "HostSInputRegular.h" +#include "Simulator.h" #if defined(USE_GPU) #include "GpuSInputPoisson.h" #include "GpuSInputRegular.h" @@ -26,20 +27,21 @@ ISInput *FSInput::CreateInstance() if (stimulusFileName.empty()) { return nullptr; } + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); // load stimulus input file TiXmlDocument siDoc(stimulusFileName.c_str()); if (!siDoc.LoadFile()) { - cerr << "Failed loading stimulus input file " << stimulusFileName << ":" << "\n\t" - << siDoc.ErrorDesc() << endl; - cerr << " error: " << siDoc.ErrorRow() << ", " << siDoc.ErrorCol() << endl; + LOG4CPLUS_ERROR(consoleLogger, ("Failed loading stimulus input file " << stimulusFileName << ":" << "\n\t" + << siDoc.ErrorDesc() << endl)); + LOG4CPLUS_ERROR(consoleLogger, (" error: " << siDoc.ErrorRow() << ", " << siDoc.ErrorCol() << endl)); return nullptr; } // load input parameters TiXmlElement *parms = nullptr; if ((parms = siDoc.FirstChildElement("InputParams")) == nullptr) { - cerr << "Could not find in stimulus input file " << stimulusFileName << endl; + LOG4CPLUS_ERROR(consoleLogger, ("Could not find in stimulus input file " << stimulusFileName << endl)); return nullptr; } @@ -48,11 +50,11 @@ ISInput *FSInput::CreateInstance() string name; if ((temp = parms->FirstChildElement("IMethod")) != nullptr) { if (temp->QueryValueAttribute("name", &name) != TIXML_SUCCESS) { - cerr << "error IMethod:name" << endl; + LOG4CPLUS_ERROR(consoleLogger, ("error IMethod:name" << endl)); return nullptr; } } else { - cerr << "missing IMethod" << endl; + LOG4CPLUS_ERROR(consoleLogger, ("missing IMethod" << endl)); return nullptr; } @@ -72,7 +74,7 @@ ISInput *FSInput::CreateInstance() pInput = new HostSInputPoisson(parms); #endif } else { - cerr << "unsupported stimulus input method" << endl; + LOG4CPLUS_ERROR(consoleLogger, ("unsupported stimulus input method" << endl)); } return pInput; diff --git a/Simulator/Utils/Inputs/SInputPoisson.cpp b/Simulator/Utils/Inputs/SInputPoisson.cpp index 3878f7352..09e1c7f2d 100644 --- a/Simulator/Utils/Inputs/SInputPoisson.cpp +++ b/Simulator/Utils/Inputs/SInputPoisson.cpp @@ -22,18 +22,19 @@ SInputPoisson::SInputPoisson(TiXmlElement *parms) : TiXmlElement *temp = nullptr; string sync; BGFLOAT fr_mean; // firing rate (per sec) + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); if ((temp = parms->FirstChildElement("IntParams")) != nullptr) { if (temp->QueryFLOATAttribute("fr_mean", &fr_mean) != TIXML_SUCCESS) { - cerr << "error IntParams:fr_mean" << endl; + LOG4CPLUS_ERROR(consoleLogger, "error IntParams:fr_mean\n"); return; } if (temp->QueryFLOATAttribute("weight", &weight) != TIXML_SUCCESS) { - cerr << "error IntParams:weight" << endl; + LOG4CPLUS_ERROR(consoleLogger, "error IntParams:weight\n"); return; } } else { - cerr << "missing IntParams" << endl; + LOG4CPLUS_ERROR(consoleLogger, "missing IntParams\n"); return; } @@ -66,15 +67,19 @@ SInputPoisson::SInputPoisson(TiXmlElement *parms) : == TIXML_SUCCESS) { TiXmlDocument simDoc(maskNListFileName.c_str()); if (!simDoc.LoadFile()) { - cerr << "Failed loading positions of stimulus input mask neurons list file " - << maskNListFileName << ":" << "\n\t" << simDoc.ErrorDesc() << endl; - cerr << " error: " << simDoc.ErrorRow() << ", " << simDoc.ErrorCol() << endl; + string message = "Failed loading positions of stimulus input mask neurons list file " + + maskNListFileName + ":"; + string errDesc(simDoc.ErrorDesc()); + message += (errDesc + "\n\t"); + LOG4CPLUS_ERROR(consoleLogger, message); + message = " error: " + to_string(simDoc.ErrorRow()) + ", " + to_string(simDoc.ErrorCol()) + "\n"; + LOG4CPLUS_ERROR(consoleLogger, message); break; } TiXmlNode *temp2 = nullptr; if ((temp2 = simDoc.FirstChildElement("M")) == nullptr) { - cerr << "Could not find in positons of stimulus input mask neurons list file " - << maskNListFileName << endl; + string message = "Could not find in positons of stimulus input mask neurons list file " + maskNListFileName + "\n"; + LOG4CPLUS_ERROR(consoleLogger, message); break; } getValueList(temp2->ToElement()->GetText(), &maskIndex); diff --git a/Simulator/Utils/Inputs/SInputRegular.cpp b/Simulator/Utils/Inputs/SInputRegular.cpp index e264ab091..78e72e938 100644 --- a/Simulator/Utils/Inputs/SInputRegular.cpp +++ b/Simulator/Utils/Inputs/SInputRegular.cpp @@ -20,25 +20,26 @@ void getValueList(const string &valString, vector *pList); SInputRegular::SInputRegular(TiXmlElement *parms) : values(nullptr) { fSInput = false; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); // read duration, interval and sync TiXmlElement *temp = nullptr; string sync; if ((temp = parms->FirstChildElement("IntParams")) != nullptr) { if (temp->QueryFLOATAttribute("duration", &duration) != TIXML_SUCCESS) { - cerr << "error IntParams:duration" << endl; + LOG4CPLUS_ERROR(consoleLogger, "error IntParams:duration\n"); return; } if (temp->QueryFLOATAttribute("interval", &interval) != TIXML_SUCCESS) { - cerr << "error IntParams:interval" << endl; + LOG4CPLUS_ERROR(consoleLogger, "error IntParams:interval\n"); return; } if (temp->QueryValueAttribute("sync", &sync) != TIXML_SUCCESS) { - cerr << "error IntParams:sync" << endl; + LOG4CPLUS_ERROR(consoleLogger, "error IntParams:sync\n"); return; } } else { - cerr << "missing IntParams" << endl; + LOG4CPLUS_ERROR(consoleLogger, "missing IntParams\n"); return; } @@ -55,12 +56,12 @@ SInputRegular::SInputRegular(TiXmlElement *parms) : values(nullptr) if (strcmp(pNode->Value(), "I") == 0) { getValueList(pNode->ToElement()->GetText(), &initValues); } else { - cerr << "error I" << endl; + LOG4CPLUS_ERROR(consoleLogger, "error I\n"); return; } } } else { - cerr << "missing Values" << endl; + LOG4CPLUS_ERROR(consoleLogger, "missing Values\n"); return; } diff --git a/Simulator/Utils/Matrix/MatrixFactory.cpp b/Simulator/Utils/Matrix/MatrixFactory.cpp index 19e535ed8..c49c33f55 100644 --- a/Simulator/Utils/Matrix/MatrixFactory.cpp +++ b/Simulator/Utils/Matrix/MatrixFactory.cpp @@ -32,9 +32,11 @@ void MatrixFactory::GetAttributes(TiXmlElement *matElement, string &type, string int &columns, FLOAT &multiplier) { const char *temp = nullptr; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + #ifdef MDEBUG - cerr << "Getting attributes:" << endl; + LOG4CPLUS_ERROR(consoleLogger, "Getting attributes:\n"); #endif temp = matElement->Attribute("type"); if (temp != nullptr) @@ -44,26 +46,30 @@ void MatrixFactory::GetAttributes(TiXmlElement *matElement, string &type, string if ((type != "diag") && (type != "complete") && (type != "sparse")) throw KII_invalid_argument("Illegal matrix type: " + type); #ifdef MDEBUG - cerr << "\ttype=" << type << ", "; + string message = "\trows=" + rows + ", "; + LOG4CPLUS_TRACE(consoleLogger, message); #endif if (matElement->QueryIntAttribute("rows", &rows) != TIXML_SUCCESS) throw KII_invalid_argument("Number of rows not specified for Matrix."); #ifdef MDEBUG - cerr << "\trows=" << rows << ", "; + string message = "\trows=" + rows + ", "; + LOG4CPLUS_TRACE(consoleLogger, message); #endif if (matElement->QueryIntAttribute("columns", &columns) != TIXML_SUCCESS) throw KII_invalid_argument("Number of columns not specified for Matrix."); #ifdef MDEBUG - cerr << "\tcolumns=" << columns << ", "; + string message = "\tcolumns=" + columns + ", "; + LOG4CPLUS_TRACE(consoleLogger, message); #endif if (matElement->QueryFLOATAttribute("multiplier", &multiplier) != TIXML_SUCCESS) { multiplier = 1.0; } #ifdef MDEBUG - cerr << "\tmultiplier=" << multiplier << ", "; + string message = "\tmultiplier=" + multiplier + ", "; + LOG4CPLUS_TRACE(consoleLogger, message); #endif temp = matElement->Attribute("init"); @@ -72,7 +78,8 @@ void MatrixFactory::GetAttributes(TiXmlElement *matElement, string &type, string else init = "none"; #ifdef MDEBUG - cerr << "\tinit=" << init << endl; + string message = "\tinit=" + init + "\n"; + LOG4CPLUS_TRACE(consoleLogger, message); #endif } @@ -95,12 +102,14 @@ Matrix *MatrixFactory::CreateMatrix(TiXmlElement *matElement) FLOAT multiplier; Matrix *theMatrix = nullptr; TiXmlHandle matHandle(matElement); + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); GetAttributes(matElement, type, init, rows, columns, multiplier); #ifdef MDEBUG - cerr << "Creating Matrix with attributes: " << type << ", " << init << ", " << rows << "X" - << columns << ", " << multiplier << endl; + string message = "Creating Matrix with attributes: " + type + ", " + init + ", " + rows + "X" + + columns + ", " + multiplier + "\n"; + LOG4CPLUS_ERROR(consoleLogger, message); #endif if (init == "implementation") @@ -116,7 +125,8 @@ Matrix *MatrixFactory::CreateMatrix(TiXmlElement *matElement) throw KII_invalid_argument("Contents not specified for Matrix with init='none'."); values = valuesNode->Value(); #ifdef MDEBUG - cerr << "\tData present for initialization: " << values << endl; + string message = "\tData present for initialization: " + values + "\n"; + LOG4CPLUS_ERROR(consoleLogger, message); #endif } if ((rows > 1) && (columns > 1)) // Create a 2D Matrix @@ -131,7 +141,8 @@ Matrix *MatrixFactory::CreateMatrix(TiXmlElement *matElement) "Contents not specified for Sparse Matrix with init='none'."); const char *values = valuesNode->Value(); #ifdef MDEBUG - cerr << "\tData present for initialization: " << values << endl; + string message = "\tData present for initialization: " + values + "\n"; + LOG4CPLUS_ERROR(consoleLogger, message); #endif theMatrix = new SparseMatrix(rows, columns, multiplier, values); } else if (init == "const") { // No string of values or XML row data @@ -174,12 +185,14 @@ VectorMatrix MatrixFactory::CreateVector(TiXmlElement *matElement) FLOAT multiplier; string values; TiXmlHandle matHandle(matElement); + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); GetAttributes(matElement, type, init, rows, columns, multiplier); #ifdef VDEBUG - cerr << "Creating Vector with attributes: " << type << ", " << init << ", " << rows << "X" - << columns << ", " << multiplier << endl; + string message = "Creating Vector with attributes: " + type + ", " + init + ", " + rows + "X" + + columns + ", " + multiplier + "\n"; + LOG4CPLUS_ERROR(consoleLogger, message); #endif // Get the Text node that contains the matrix values, if needed @@ -190,7 +203,7 @@ VectorMatrix MatrixFactory::CreateVector(TiXmlElement *matElement) values = valuesNode->Value(); #ifdef VDEBUG - cerr << "\tData present for initialization: " << values << endl; + LOG4CPLUS_ERROR(consoleLogger, ("\tData present for initialization: " << values << endl)); #endif } else if (init == "implementation") throw KII_invalid_argument( @@ -230,12 +243,14 @@ CompleteMatrix MatrixFactory::CreateComplete(TiXmlElement *matElement) FLOAT multiplier; string values; TiXmlHandle matHandle(matElement); + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); GetAttributes(matElement, type, init, rows, columns, multiplier); #ifdef MDEBUG - cerr << "Creating Matrix with attributes: " << type << ", " << init << ", " << rows << "X" - << columns << ", " << multiplier << endl; + string message = "Creating Matrix with attributes: " + type + ", " + init + ", " + rows + "X" + + columns + ", " + multiplier + "\n"; + LOG4CPLUS_ERROR(consoleLogger, message); #endif // Get the Text node that contains the matrix values, if needed @@ -246,7 +261,7 @@ CompleteMatrix MatrixFactory::CreateComplete(TiXmlElement *matElement) values = valuesNode->Value(); #ifdef MDEBUG - cerr << "\tData present for initialization: " << values << endl; + LOG4CPLUS_ERROR(consoleLogger, ("\tData present for initialization: " << values << endl)); #endif } else if (init == "implementation") throw KII_invalid_argument( @@ -277,12 +292,14 @@ SparseMatrix MatrixFactory::CreateSparse(TiXmlElement *matElement) int rows, columns; FLOAT multiplier; TiXmlHandle matHandle(matElement); + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); GetAttributes(matElement, type, init, rows, columns, multiplier); #ifdef MDEBUG - cerr << "Creating SparseMatrix with attributes: " << type << ", " << init << ", " << rows << "X" - << columns << ", " << multiplier << endl; + string message = "Creating SparseMatrix with attributes: " + type + ", " + init << ", " + rows + "X" + + columns + ", " + multiplier + "\n"; + LOG4CPLUS_ERROR(consoleLogger, ); #endif if (type == "diag") { @@ -293,7 +310,8 @@ SparseMatrix MatrixFactory::CreateSparse(TiXmlElement *matElement) "Contents not specified for Sparese Matrix with init='none'."); const char *values = valuesNode->Value(); #ifdef MDEBUG - cerr << "\tData present for initialization: " << values << endl; + string message = "\tData present for initialization: " + values + "\n"; + LOG4CPLUS_ERROR(consoleLogger, message); #endif return SparseMatrix(rows, columns, multiplier, values); } else if (init == "const") { // No string of values or XML row data diff --git a/Simulator/Utils/Matrix/SparseMatrix.cpp b/Simulator/Utils/Matrix/SparseMatrix.cpp index 0aaf82364..5988ae845 100644 --- a/Simulator/Utils/Matrix/SparseMatrix.cpp +++ b/Simulator/Utils/Matrix/SparseMatrix.cpp @@ -7,6 +7,7 @@ * Self-allocating and de-allocating. */ +#include "Simulator.h" #include "SparseMatrix.h" #include "Global.h" #include @@ -216,6 +217,7 @@ SparseMatrix::SparseMatrix(int r, int c, BGFLOAT m, const char *v) : Matrix("sparse", "none", r, c, m), theRows(nullptr), theColumns(nullptr), theElements(MaxElements(r, c), c, this) { + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); DEBUG_SPARSE(cerr << "\tCreating diagonal sparse matrix" << endl;) // Bail out if we're being asked to create nonsense if (!((rows > 0) && (columns > 0))) @@ -249,7 +251,7 @@ SparseMatrix::SparseMatrix(int r, int c, BGFLOAT m, const char *v) : try { theElements.insert(el); } catch (Matrix_invalid_argument e) { - cerr << "Failure during SparseMatrix string constructor: " << e.what() << endl; + LOG4CPLUS_ERROR(consoleLogger, "Failure during SparseMatrix string constructor: " << e.what() << endl); exit(-1); } } @@ -263,7 +265,9 @@ SparseMatrix::SparseMatrix(int r, int c, BGFLOAT m, const char *v) : try { theElements.insert(el); } catch (Matrix_invalid_argument e) { - cerr << "Failure during SparseMatrix multiplier only constructor: " << e.what() << endl; + string w = e.what(); + string message = "Failure during SparseMatrix multiplier only constructor: " + w + "\n"; + LOG4CPLUS_ERROR(consoleLogger, message); exit(-1); } } @@ -314,6 +318,7 @@ SparseMatrix::SparseMatrix(const SparseMatrix &oldM) : dimensions = 2; DEBUG_SPARSE(cerr << rows << "X" << columns << ":" << endl;) + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); // Allocate storage for row and column lists (hash table already // allocated at initialization time; see initializer list, above). @@ -325,8 +330,10 @@ SparseMatrix::SparseMatrix(const SparseMatrix &oldM) : try { copy(oldM); } catch (Matrix_invalid_argument e) { - cerr << "Failure during SparseMatrix copy constructor\n" - << "\tError was: " << e.what() << endl; + string w = e.what(); + string message = "Failure during SparseMatrix copy constructor\n" + + ("\tError was: " + w) + "\n"; + LOG4CPLUS_ERROR(consoleLogger, message); exit(-1); } } @@ -345,6 +352,7 @@ SparseMatrix &SparseMatrix::operator=(const SparseMatrix &rhs) return *this; DEBUG_SPARSE(cerr << "SparseMatrix::operator=" << endl;) + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); clear(); DEBUG_SPARSE(cerr << "\t\tclear() complete, setting data member values." << endl;) @@ -360,8 +368,8 @@ SparseMatrix &SparseMatrix::operator=(const SparseMatrix &rhs) try { copy(rhs); } catch (Matrix_invalid_argument e) { - cerr << "\tFailure during SparseMatrix assignment operator\n" - << "\tError was: " << e.what() << endl; + LOG4CPLUS_ERROR(consoleLogger, "\tFailure during SparseMatrix assignment operator\n" + << "\tError was: " << e.what() << endl); exit(-1); } DEBUG_SPARSE(cerr << "\t\tcopy() complete; returning by reference." << endl;) @@ -415,6 +423,7 @@ void SparseMatrix::copy(const SparseMatrix &source) { DEBUG_SPARSE(cerr << "\t\t\tcopying " << source.rows << "X" << source.columns << " SparseMatrix...";) + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); // We will access the source row-wise, inserting new Elements into // the current SparseMatrix's row and column lists. @@ -427,12 +436,22 @@ void SparseMatrix::copy(const SparseMatrix &source) try { theElements.insert(el); } catch (Matrix_invalid_argument e) { - cerr << "\nFailure during SparseMatrix copy() for element " << el->value << " at (" - << el->row << "," << el->column << ")" << endl; - cerr << "\twith " << theElements.size << " elements already copied at i=" << i + LOG4CPLUS_ERROR(consoleLogger, "\nFailure during SparseMatrix copy() for element " << el->value << " at (" + << el->row << "," << el->column << ")" << endl); + LOG4CPLUS_ERROR(consoleLogger, "\twith " << theElements.size << " elements already copied at i=" << i << ", hashed to " << theElements.hash(el) << " in table with capacity " - << theElements.capacity << endl; - cerr << "\tSource was: " << source << endl << endl; + << theElements.capacity << endl); + LOG4CPLUS_ERROR(consoleLogger, "\tSource was: " << source << endl << endl); + string message = "\nFailure during SparseMatrix copy() for element " + to_string(el->value) + " at (" + + to_string(el->row) + "," + to_string(el->column) + ")\n"; + LOG4CPLUS_ERROR(consoleLogger, message); + + message = "\twith " + to_string(theElements.size) + " elements already copied at i=" + to_string(i) + + ", hashed to " + to_string(theElements.hash(el)) + " in table with capacity " + + to_string(theElements.capacity) + "\n"; + LOG4CPLUS_ERROR(consoleLogger, message); + + LOG4CPLUS_ERROR(consoleLogger, "\tSource was: " << source << "\n\n"); throw e; } } @@ -445,6 +464,7 @@ void SparseMatrix::copy(const SparseMatrix &source) void SparseMatrix::rowFromXML(TiXmlElement *rowElement) { int rowNum; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); if (rowElement->QueryIntAttribute("number", &rowNum) != TIXML_SUCCESS) throw Matrix_invalid_argument("Attempt to read SparseMatrix row without a number"); @@ -464,7 +484,7 @@ void SparseMatrix::rowFromXML(TiXmlElement *rowElement) try { theElements.insert(el); } catch (Matrix_invalid_argument e) { - cerr << "Failure during SparseMatrix rowFromXML: " << e.what() << endl; + LOG4CPLUS_ERROR(consoleLogger, "Failure during SparseMatrix rowFromXML: " << e.what() << endl); exit(-1); } } @@ -549,6 +569,7 @@ string SparseMatrix::toXML(string name) const BGFLOAT &SparseMatrix::operator()(int r, int c) { Element *el = theElements.retrieve(r, c); + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); // Because we're a mutator, we need to insert a zero-value element // if the element wasn't found. We will rely on other methods to @@ -561,8 +582,8 @@ BGFLOAT &SparseMatrix::operator()(int r, int c) try { theElements.insert(el); } catch (Matrix_invalid_argument e) { - cerr << "Failure during SparseMatrix operator() at row " << r << " column " << c << ": " - << e.what() << endl; + LOG4CPLUS_ERROR(consoleLogger, "Failure during SparseMatrix operator() at row " << r << " column " << c << ": " + << e.what() << endl); exit(-1); } } diff --git a/Simulator/Utils/ParameterManager.cpp b/Simulator/Utils/ParameterManager.cpp index 4ebb085cf..73916c159 100644 --- a/Simulator/Utils/ParameterManager.cpp +++ b/Simulator/Utils/ParameterManager.cpp @@ -28,7 +28,9 @@ #include "xpath_static.h" #include #include +#include #include +#include "Simulator.h" #include #include #include @@ -55,10 +57,16 @@ bool ParameterManager::loadParameterFile(string path) // load the XML document xmlDocument_.reset(new TiXmlDocument(path.c_str())); if (!xmlDocument_->LoadFile()) { - cerr << "Failed loading simulation parameter file " << path << ":" << endl; - cerr << "\t" << xmlDocument_->ErrorDesc() << endl; - cerr << " error row: " << xmlDocument_->ErrorRow() - << ", error col: " << xmlDocument_->ErrorCol() << endl; + // cerr << "Failed loading simulation parameter file " << path << ":" << endl; + // cerr << "\t" << xmlDocument_->ErrorDesc() << endl; + // cerr << " error row: " << xmlDocument_->ErrorRow() + // << ", error col: " << xmlDocument_->ErrorCol() << endl; + + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + string errorMsg = "Failed loading simulation parameter file " + path + ": \n" + "\t" + xmlDocument_->ErrorDesc() + "\n error row: "; + errorMsg += xmlDocument_->ErrorRow() + ", error col: " + xmlDocument_->ErrorCol(); + LOG4CPLUS_FATAL(consoleLogger, errorMsg); + return false; } // assign the document root_ object @@ -94,8 +102,12 @@ bool ParameterManager::getStringByXpath(string xpath, string &referenceVar) string temp; // raise error if tinyxml cannot compute the xpath's value or returns empty if (!TinyXPath::o_xpath_string(root_, xpath.c_str(), temp) || temp == "") { - cerr << "Failed loading simulation parameter for xpath " << xpath << endl; - return false; + // cerr << "Failed loading simulation parameter for xpath " << xpath << endl; + // return false; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + string errorMsg = "Failed loading simulation parameter for xpath " + xpath; + LOG4CPLUS_FATAL(consoleLogger, errorMsg); + } referenceVar = temp; return true; @@ -119,22 +131,40 @@ bool ParameterManager::getIntByXpath(string xpath, int &referenceVar) // Workaround for standard value conversion functions. // stoi() will cast floats to ints. if (regex_match(tmp, regex("\\d+[.]\\d+(e[+-]?\\d+)?f?|\\d+[.]?\\d+(e[+-]?\\d+)?f"))) { - cerr << "Parsed parameter is likely a float/double value. " - << "Terminating integer cast. Value: " << tmp << endl; + // cerr << "Parsed parameter is likely a float/double value. " + // << "Terminating integer cast. Value: " << tmp << endl; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + string errorMsg = "Parsed parameter is likely a float/double value. \n"; + errorMsg += "Terminating integer cast. Value: " + tmp; + LOG4CPLUS_INFO(consoleLogger, errorMsg); + return false; } else if (regex_match(tmp, regex(".*[^\\def.]+.*"))) { - cerr << "Parsed parameter is likely a string. " << endl; - cerr << "Terminating integer cast. Value: " << tmp << endl; + // cerr << "Parsed parameter is likely a string. " << endl; + // cerr << "Terminating integer cast. Value: " << tmp << endl; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + string errorMsg = "Parsed parameter is likely a string. \n"; + errorMsg += "Terminating integer cast. Value: " + tmp; + LOG4CPLUS_INFO(consoleLogger, errorMsg); + return false; } try { referenceVar = stoi(tmp); } catch (invalid_argument &arg_exception) { - cerr << "Parsed parameter could not be parsed as an integer. Value: " << tmp << endl; + // cerr << "Parsed parameter could not be parsed as an integer. Value: " << tmp << endl; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + string errorMsg = "Parsed parameter could not be parsed as an integer. Value: " + tmp; + LOG4CPLUS_FATAL(consoleLogger, errorMsg); + return false; } catch (out_of_range &range_exception) { - cerr << "Parsed string parameter could not be converted to an integer. Value: " << tmp - << endl; + // cerr << "Parsed string parameter could not be converted to an integer. Value: " << tmp + // << endl; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + string errorMsg = "Parsed string parameter could not be converted to an integer. Value: " + tmp; + LOG4CPLUS_FATAL(consoleLogger, errorMsg); + return false; } return true; @@ -156,17 +186,27 @@ bool ParameterManager::getDoubleByXpath(string xpath, double &referenceVar) return false; } if (regex_match(tmp, regex(".*[^\\def.+-]+.*"))) { - cerr << "Parsed parameter is likely a string. " - << "Terminating double conversion. Value: " << tmp << endl; + // cerr << "Parsed parameter is likely a string. " + // << "Terminating double conversion. Value: " << tmp << endl; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + string errorMsg = "Parsed parameter is likely a string. \n"; + errorMsg += "Terminating double conversion. Value: " + tmp; + LOG4CPLUS_FATAL(consoleLogger, errorMsg); return false; } try { referenceVar = stod(tmp); } catch (invalid_argument &arg_exception) { - cerr << "Parsed parameter could not be parsed as a double. Value: " << tmp << endl; + // cerr << "Parsed parameter could not be parsed as a double. Value: " << tmp << endl; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + string errorMsg = "Parsed parameter could not be parsed as a double. Value: " + tmp; + LOG4CPLUS_FATAL(consoleLogger, errorMsg); return false; } catch (out_of_range &range_exception) { - cerr << "Parsed string parameter could not be converted to a double. Value: " << tmp << endl; + //cerr << "Parsed string parameter could not be converted to a double. Value: " << tmp << endl; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + string errorMsg = "Parsed string parameter could not be converted to a double. Value: " + tmp; + LOG4CPLUS_FATAL(consoleLogger, errorMsg); return false; } return true; @@ -188,17 +228,27 @@ bool ParameterManager::getFloatByXpath(string xpath, float &referenceVariable) return false; } if (regex_match(tmp, regex(".*[^\\def.+-]+.*"))) { - cerr << "Parsed parameter is likely a string. " - << "Terminating double conversion. Value: " << tmp << endl; + // cerr << "Parsed parameter is likely a string. " + // << "Terminating double conversion. Value: " << tmp << endl; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + string errorMsg = "Parsed parameter is likely a string. \n"; + errorMsg += "Terminating integer cast. Value: " + tmp; + LOG4CPLUS_INFO(consoleLogger, errorMsg); return false; } try { referenceVariable = stof(tmp); } catch (invalid_argument &arg_exception) { - cerr << "Parsed parameter could not be parsed as a float. Value: " << tmp << endl; + // cerr << "Parsed parameter could not be parsed as a float. Value: " << tmp << endl; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + string errorMsg = "Parsed parameter could not be parsed as a float. Value: " + tmp; + LOG4CPLUS_FATAL(consoleLogger, errorMsg); return false; } catch (out_of_range &range_exception) { - cerr << "Parsed string parameter could not be converted to a float. Value: " << tmp << endl; + // cerr << "Parsed string parameter could not be converted to a float. Value: " << tmp << endl; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + string errorMsg = "Parsed string parameter could not be converted to a float. Value: " + tmp; + LOG4CPLUS_FATAL(consoleLogger, errorMsg); return false; } return true; @@ -224,7 +274,10 @@ bool ParameterManager::getBGFloatByXpath(string xpath, BGFLOAT &referenceVar) #ifdef DOUBLEPRECISION return getDoubleByXpath(xpath, referenceVar); #endif - cerr << "Could not infer primitive type for BGFLOAT variable." << endl; + // cerr << "Could not infer primitive type for BGFLOAT variable." << endl; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + string errorMsg = "Could not infer primitive type for BGFLOAT variable."; + LOG4CPLUS_FATAL(consoleLogger, errorMsg); return false; } @@ -244,17 +297,27 @@ bool ParameterManager::getLongByXpath(string xpath, long &referenceVar) return false; } if (!regex_match(tmp, regex("[\\d]+l?"))) { - cerr << "Parsed parameter is not a valid long format. " - << "Terminating long conversion. Value: " << tmp << endl; + // cerr << "Parsed parameter is not a valid long format. " + // << "Terminating long conversion. Value: " << tmp << endl; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + string errorMsg = "Parsed parameter is not a valid long format. + \n"; + errorMsg += "Terminating long conversion. Value: " + tmp; + LOG4CPLUS_FATAL(consoleLogger, errorMsg); return false; } try { referenceVar = stol(tmp); } catch (invalid_argument &arg_exception) { - cerr << "Parsed parameter could not be parsed as a long. Value: " << tmp << endl; + // cerr << "Parsed parameter could not be parsed as a long. Value: " << tmp << endl; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + string errorMsg = "Parsed parameter could not be parsed as a long. Value: " + tmp; + LOG4CPLUS_FATAL(consoleLogger, errorMsg); return false; } catch (out_of_range &range_exception) { - cerr << "Parsed string parameter could not be converted to a long. Value: " << tmp << endl; + // cerr << "Parsed string parameter could not be converted to a long. Value: " << tmp << endl; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + string errorMsg = "Parsed string parameter could not be converted to a long. Value: " + tmp; + LOG4CPLUS_FATAL(consoleLogger, errorMsg); return false; } return true; @@ -278,15 +341,24 @@ bool ParameterManager::getIntVectorByXpath(const string &path, const string &ele // Open file using a local XmlDocument object TiXmlDocument xmlDocument(path.c_str()); if (!xmlDocument.LoadFile()) { - cerr << "Failed to load " << path.c_str() << ":" << endl; - cerr << "\t" << xmlDocument.ErrorDesc() << endl; + // cerr << "Failed to load " << path.c_str() << ":" << endl; + // cerr << "\t" << xmlDocument.ErrorDesc() << endl; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + string p = path.c_str(); + string errorMsg = "Failed to load " + p + ":"; + string xError = xmlDocument.ErrorDesc(); + errorMsg += "\t" + xError; + LOG4CPLUS_FATAL(consoleLogger, errorMsg); return false; } // Check file for matching element TiXmlNode *xmlNode = nullptr; if ((xmlNode = xmlDocument.FirstChildElement(elementName)) == nullptr) { - cerr << "Could not find <" << elementName << "> in vertex list file " << path << endl; + // cerr << "Could not find <" << elementName << "> in vertex list file " << path << endl; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + string errorMsg = "Could not find <" + elementName + "> in vertex list file " + path; + LOG4CPLUS_FATAL(consoleLogger, errorMsg); return false; } @@ -311,14 +383,20 @@ bool ParameterManager::getFileByXpath(const string &path, ifstream &file) { string file_name; if (!ParameterManager::getInstance().getStringByXpath(path, file_name)) { - cerr << "Could not find XML path: " << path << ".\n"; + // cerr << "Could not find XML path: " << path << ".\n"; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + string errorMsg = "Could not find XML path: " + path; + LOG4CPLUS_FATAL(consoleLogger, errorMsg); return false; }; // open file file.open(file_name.c_str()); if (!file.is_open()) { - cerr << "Failed to open file: " << file_name << ".\n"; + // cerr << "Failed to open file: " << file_name << ".\n"; + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + string errorMsg = "Failed to open file: " + file_name; + LOG4CPLUS_FATAL(consoleLogger, errorMsg); return false; } diff --git a/Simulator/Utils/RNG/MersenneTwister_d.cu b/Simulator/Utils/RNG/MersenneTwister_d.cu index e90151495..dd5fe79d6 100644 --- a/Simulator/Utils/RNG/MersenneTwister_d.cu +++ b/Simulator/Utils/RNG/MersenneTwister_d.cu @@ -33,6 +33,7 @@ */ +#include #include #include @@ -60,12 +61,14 @@ unsigned int mt_nPerRng; //Load twister configurations void loadMTGPU(const char *fname){ FILE *fd = fopen(fname, "rb"); + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); + if(!fd){ - cerr << "initMTGPU(): failed to open " << fname << endl << "FAILED" << endl; + LOG4CPLUS_ERROR(consoleLogger, "initMTGPU(): failed to open " << fname << endl << "FAILED" << endl); exit(0); } if( !fread(h_MT, mt_rng_count*sizeof(mt_struct_stripped), 1, fd) ){ - cerr << "initMTGPU(): failed to load " << fname << endl << "FAILED" << endl; + LOG4CPLUS_ERROR(consoleLogger, "initMTGPU(): failed to load " << fname << endl << "FAILED" << endl); exit(0); } fclose(fd); @@ -86,6 +89,7 @@ void seedMTGPU(unsigned int seed){ int i; //Need to be thread-safe mt_struct_stripped *MT = (mt_struct_stripped *)malloc(mt_rng_count * sizeof(mt_struct_stripped)); + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); for(i = 0; i < mt_rng_count; i++){ MT[i] = h_MT[i]; @@ -99,7 +103,7 @@ void seedMTGPU(unsigned int seed){ seedMTGPUState<<>>(seed); if(cudaMemcpyToSymbol(ds_MT, MT, mt_rng_count*sizeof(mt_struct_stripped))!=cudaSuccess){ - cerr << "seedMTGP failed" << endl; + LOG4CPLUS_ERROR(consoleLogger, "seedMTGP failed" << endl); exit(0); }