source: src/builder_init.cpp@ f4d063

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 f4d063 was f4d063, checked in by Frederik Heber <heber@…>, 14 years ago

MEMFIX: MemDebug ignores all unknown sources. Removed all dependencies around main(), moved to builder_init.?pp.

  • this has been an attempt to fix the warning of a memory leak that actually results into the libboost_filesystem.so over which we have no control. As of now, i I do not quite look through the whole affair. That is, I have a now idea why Till's new memory allocator is used during the initialization of some external library already, but apparently it must have to do with lookup tables present in the exectuable already. Hence, we can not do much about.
  • Nonetheless, we split up main() into some initializating functions which have been outsourced to builder_init.cpp.
  • The only fix then is that we ignore all values of unknown source in MemDebug.
  • Note: We only do accouting of stuff allocated on the heap (e.g. int *test = new int;) and not on stack (int test;)! However, stack space is limited anyway.
  • Property mode set to 100644
File size: 6.4 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * builder_init.cpp
10 *
11 * Created on: Dec 15, 2010
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "Helpers/MemDebug.hpp"
21
22#include "bondgraph.hpp"
23#include "config.hpp"
24#include "Helpers/Log.hpp"
25#include "molecule.hpp"
26#include "periodentafel.hpp"
27#include "tesselationhelpers.hpp"
28#include "UIElements/UIFactory.hpp"
29#include "UIElements/Menu/MenuDescription.hpp"
30#include "UIElements/TextUI/TextUIFactory.hpp"
31#include "UIElements/CommandLineUI/CommandLineUIFactory.hpp"
32#include "UIElements/CommandLineUI/CommandLineParser.hpp"
33#ifdef USE_GUI_QT
34#include "UIElements/Qt4/QtUIFactory.hpp"
35#endif
36#include "UIElements/MainWindow.hpp"
37#include "UIElements/Dialog.hpp"
38//#include "Menu/ActionMenuItem.hpp"
39#include "Helpers/Verbose.hpp"
40#include "World.hpp"
41
42#include "Actions/ActionRegistry.hpp"
43#include "Actions/ActionHistory.hpp"
44
45#include "Parser/ChangeTracker.hpp"
46#include "Parser/FormatParserStorage.hpp"
47
48#include "UIElements/UIFactory.hpp"
49#include "UIElements/TextUI/TextUIFactory.hpp"
50#include "UIElements/CommandLineUI/CommandLineUIFactory.hpp"
51#include "UIElements/MainWindow.hpp"
52#include "UIElements/Dialog.hpp"
53
54#include "version.h"
55
56#include "builder_init.hpp"
57
58/** Print some initial information output the program.
59 *
60 */
61void ProgramHeader()
62{
63 // print version check and copyright notice
64 cout << MOLECUILDERVERSION << endl;
65 cout << "MoleCuilder comes with ABSOLUTELY NO WARRANTY; for details type" << endl;
66 cout << "`molecuilder --warranty'." << endl;
67 cout << "`MoleCuilder - to create and alter molecular systems." << endl;
68 cout << "Copyright (C) 2010 University Bonn. All rights reserved." << endl;
69}
70
71/** General stuff to intialize before UI.
72 *
73 */
74void initGeneral()
75{
76 // while we are non interactive, we want to abort from asserts
77 ASSERT_DO(Assert::Abort);
78 ASSERT_HOOK(dumpMemory);
79
80 ProgramHeader();
81
82 setVerbosity(0);
83 // need to init the history before any action is created
84 ActionHistory::init();
85
86 // from this moment on, we need to be sure to deeinitialize in the correct order
87 // this is handled by the cleanup function
88 atexit(cleanUp);
89}
90
91/** Initialize specific UIFactory.
92 *
93 * @param argc argument count
94 * @param argv argument array
95 */
96void initUI(int argc, char **argv)
97{
98 std::string BondGraphFileName("\n");
99 // Parse command line options and if present create respective UI
100 // construct bond graph
101 if (World::getInstance().getConfig()->BG == NULL) {
102 World::getInstance().getConfig()->BG = new BondGraph(World::getInstance().getConfig()->GetIsAngstroem());
103 if (World::getInstance().getConfig()->BG->LoadBondLengthTable(BondGraphFileName)) {
104 DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl);
105 } else {
106 DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl);
107 }
108 }
109 // handle remaining arguments by CommandLineParser
110 if (argc>1) {
111 CommandLineParser::getInstance().InitializeCommandArguments();
112 CommandLineParser::getInstance().Run(argc,argv);
113 DoLog(0) && (Log() << Verbose(0) << "Setting UI to CommandLine." << endl);
114 UIFactory::registerFactory(new CommandLineUIFactory::description());
115 UIFactory::makeUserInterface("CommandLine");
116 } else {
117 // In the interactive mode, we can leave the user the choice in case of error
118 ASSERT_DO(Assert::Ask);
119 #ifdef USE_GUI_QT
120 DoLog(0) && (Log() << Verbose(0) << "Setting UI to Qt4." << endl);
121 UIFactory::registerFactory(new QtUIFactory::description());
122 UIFactory::makeUserInterface("Qt4");
123 #else
124 DoLog(0) && (Log() << Verbose(0) << "Setting UI to Text." << endl);
125 cout << MOLECUILDERVERSION << endl;
126 UIFactory::registerFactory(new TextUIFactory::description());
127 UIFactory::makeUserInterface("Text");
128 #endif
129 }
130}
131
132/** Create MainWindow and displays.
133 * I.e. here all the Actions are parsed and done.
134 */
135void doUI()
136{
137 MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow();
138 mainWindow->display();
139 delete mainWindow;
140}
141
142
143/** In this function all dynamicly allocated member variables to static/global
144 * variables are added to the ignore list of Memory/MemDebug.
145 *
146 * Use this to prevent their listing in the Memory::getState() at the end of the
147 * program. Check with valgrind that truely no memory leak occurs!
148 */
149void AddStaticEntitiestoIgnoreList()
150{
151 // zeroVec and unitVec are global variables (on the stack) but vectorContent
152 // within is situated on the heap and has to be ignored
153 Memory::ignore(zeroVec.get());
154 Memory::ignore(unitVec[0].get());
155 Memory::ignore(unitVec[1].get());
156 Memory::ignore(unitVec[2].get());
157}
158
159/** Cleans all singleton instances in an orderly fashion.
160 * C++ does not guarantee any specific sequence of removal of single instances
161 * which have static/global variables. Some singletons depend on others hence we
162 * acertain a specific ordering here, which is is used via the atexit() hook.
163 */
164void cleanUp()
165{
166 FormatParserStorage::purgeInstance();
167 ChangeTracker::purgeInstance();
168 World::purgeInstance();
169 MenuDescription::purgeInstance();
170 UIFactory::purgeInstance();
171 ValueStorage::purgeInstance();
172 CommandLineParser::purgeInstance();
173 ActionRegistry::purgeInstance();
174 OptionRegistry::purgeInstance();
175 ActionHistory::purgeInstance();
176 // we have to remove these two static as otherwise their boost::shared_ptrs are still present
177 Action::removeStaticStateEntities();
178 // put some static variables' dynamic contents on the Memory::ignore map to avoid their
179 // admonishing lateron
180 AddStaticEntitiestoIgnoreList();
181 logger::purgeInstance();
182 errorLogger::purgeInstance();
183#ifdef LOG_OBSERVER
184 cout << observerLog().getLog();
185#endif
186 Memory::getState();
187}
188
189/** Dump current memory chunks.
190 *
191 */
192void dumpMemory()
193{
194 ofstream ost("molecuilder.memdump");
195 Memory::dumpMemory(ost);
196}
197
198/** Save the current World to output files and exit.
199 *
200 * @return retrieved from World::getExitFlag()
201 */
202int saveAll()
203{
204 int test[500000];
205 for (size_t i=0;i<500000;++i) {
206 test[i] = (int)i;
207 }
208 FormatParserStorage::getInstance().SaveAll();
209 ChangeTracker::getInstance().saveStatus();
210
211 int ExitFlag = World::getInstance().getExitFlag();
212 return (ExitFlag == 1 ? 0 : ExitFlag);
213}
Note: See TracBrowser for help on using the repository browser.