source: src/cleanUp.cpp@ 856d05

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 856d05 was 856d05, checked in by Frederik Heber <heber@…>, 13 years ago

MEMFIX: Added WorldTime and ObserverLog ::purgeInstance() calls.

  • added several memory fixes:
  • added ObserverLog include to GLMoleculeObject_bond, _molecule, and GLWorldView.
  • TESTFIX: due to changes with new JobMarket, we need to give jobids in regression test mpqc-jobs.
  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * cleanUp.cpp
10 *
11 * Created on: Oct 28, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include <iostream>
21#include <iomanip>
22
23#include "CodePatterns/MemDebug.hpp"
24
25#include "cleanUp.hpp"
26
27#include "Atom/AtomObserver.hpp"
28
29#include "CodePatterns/Chronos.hpp"
30#include "CodePatterns/errorlogger.hpp"
31#include "CodePatterns/logger.hpp"
32#include "CodePatterns/Observer/ObserverLog.hpp"
33
34#include "Actions/ActionHistory.hpp"
35#include "Actions/ActionRegistry.hpp"
36#include "Actions/OptionRegistry.hpp"
37
38#include "RandomNumbers/RandomNumberDistributionFactory.hpp"
39#include "RandomNumbers/RandomNumberEngineFactory.hpp"
40#include "RandomNumbers/RandomNumberGeneratorFactory.hpp"
41
42#include "Parser/ChangeTracker.hpp"
43#include "Parser/FormatParserStorage.hpp"
44#include "Parser/XmlParser.hpp"
45
46#include "UIElements/CommandLineUI/CommandLineParser.hpp"
47#include "UIElements/Menu/MenuDescription.hpp"
48#include "UIElements/UIFactory.hpp"
49#include "World.hpp"
50#include "WorldTime.hpp"
51
52/** In this function all dynamicly allocated member variables to static/global
53 * variables are added to the ignore list of Memory/MemDebug.
54 *
55 * Use this to prevent their listing in the Memory::getState() at the end of the
56 * program. Check with valgrind that truely no memory leak occurs!
57 */
58void AddStaticEntitiestoIgnoreList()
59{
60 // zeroVec and unitVec are global variables (on the stack) but vectorContent
61 // within is situated on the heap and has to be ignored
62 Memory::ignore(zeroVec.get());
63 Memory::ignore(unitVec[0].get());
64 Memory::ignore(unitVec[1].get());
65 Memory::ignore(unitVec[2].get());
66
67 // XmlParser has static instance that uses vectorContent as well
68 Memory::ignore(FormatParser< xml >::defaultAtomInfo.field.get());
69}
70
71/** purges all static (singleton) instances in correct order of dependency.
72 *
73 */
74void purgeStaticInstances()
75{
76 Chronos::purgeInstance();
77 RandomNumberDistributionFactory::purgeInstance();
78 RandomNumberEngineFactory::purgeInstance();
79 RandomNumberGeneratorFactory::purgeInstance();
80 FormatParserStorage::purgeInstance();
81 ChangeTracker::purgeInstance();
82 World::purgeInstance();
83 AtomObserver::purgeInstance();
84 MenuDescription::purgeInstance();
85 UIFactory::purgeInstance();
86 CommandLineParser::purgeInstance();
87 MoleCuilder::ActionRegistry::purgeInstance();
88 MoleCuilder::OptionRegistry::purgeInstance();
89 MoleCuilder::ActionHistory::purgeInstance();
90 logger::purgeInstance();
91 errorLogger::purgeInstance();
92 WorldTime::purgeInstance();
93}
94
95/** Cleans all singleton instances in an orderly fashion.
96 * C++ does not guarantee any specific sequence of removal of single instances
97 * which have static/global variables. Some singletons depend on others hence we
98 * acertain a specific ordering here, which is is used via the atexit() hook.
99 */
100void cleanUp()
101{
102 // give timings per Action
103 printTimings();
104 // purge static instances from memory
105 purgeStaticInstances();
106 // put some static variables' dynamic contents on the Memory::ignore map to avoid their
107 // admonishing lateron
108 AddStaticEntitiestoIgnoreList();
109#ifdef LOG_OBSERVER
110 cout << observerLog().getLog();
111#endif
112#ifndef NDEBUG
113 ObserverLog::purgeInstance();
114#endif
115 Memory::getState();
116}
117
118/** We give a list of all times per action and a total time.
119 *
120 */
121void printTimings()
122{
123 const MoleCuilder::ActionRegistry &AR = MoleCuilder::ActionRegistry::getInstance();
124 const Chronos &Chron = Chronos::getInstance();
125 std::cout << "(Non-zero) Times used per Action [seconds]:" << std::endl;
126 for (MoleCuilder::ActionRegistry::const_iterator iter = AR.getBeginIter(); iter != AR.getEndIter(); ++iter)
127 if (Chron.getTime(iter->first) != 0.) { // dont give if action has not been used
128 std::cout << " " << setiosflags(ios::left) << setw(24) << setfill('.') << iter->first;
129 std::cout << setiosflags(ios::left) << setprecision(6) << fixed << Chron.getTime(iter->first) << std::endl;
130 }
131 std::cout << "Total Time: " << Chron.SumUpTotalTime() << " seconds" << std::endl;
132 std::cout << "Total Actions called: " << Chron.SumUpTotalFunctions() << std::endl;
133}
134
135/** Dump current memory chunks.
136 *
137 */
138void dumpMemory()
139{
140 ofstream ost("molecuilder.memdump");
141 Memory::dumpMemory(ost);
142}
143
144/** Save the current World to output files and exit.
145 *
146 * @return retrieved from World::getExitFlag()
147 */
148int saveAll()
149{
150 FormatParserStorage::getInstance().SaveAll();
151 ChangeTracker::getInstance().saveStatus();
152
153 int ExitFlag = World::getInstance().getExitFlag();
154 return (ExitFlag == 1 ? 0 : ExitFlag);
155}
Note: See TracBrowser for help on using the repository browser.