Changeset 7218f8
- Timestamp:
- Nov 3, 2009, 12:37:55 PM (16 years ago)
- Branches:
- 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, Candidate_v1.7.0, 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
- Children:
- 2aeefd
- Parents:
- fa649a
- git-author:
- Frederik Heber <heber@…> (11/03/09 08:41:45)
- git-committer:
- Frederik Heber <heber@…> (11/03/09 12:37:55)
- Location:
- src
- Files:
-
- 12 edited
-
builder.cpp (modified) (4 diffs)
-
config.cpp (modified) (1 diff)
-
helpers.hpp (modified) (1 diff)
-
memoryallocator.hpp (modified) (3 diffs)
-
memoryusageobserver.cpp (modified) (1 diff)
-
molecule.cpp (modified) (2 diffs)
-
molecule_dynamics.cpp (modified) (3 diffs)
-
molecule_fragmentation.cpp (modified) (14 diffs)
-
molecule_graph.cpp (modified) (10 diffs)
-
moleculelist.cpp (modified) (9 diffs)
-
stackclass.hpp (modified) (1 diff)
-
unittests/memoryallocatorunittest.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/builder.cpp
rfa649a r7218f8 1574 1574 int *MinimumRingSize = new int[mol->AtomCount]; 1575 1575 atom ***ListOfLocalAtoms = NULL; 1576 int FragmentCounter = 0;1577 1576 class StackClass<bond *> *BackEdgeStack = NULL; 1578 1577 class StackClass<bond *> *LocalBackEdgeStack = NULL; … … 1580 1579 Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, BackEdgeStack); 1581 1580 if (Subgraphs != NULL) { 1582 Subgraphs->next->FillBondStructureFromReference((ofstream *)&cout, mol, (FragmentCounter = 0), ListOfLocalAtoms, false); // we want to keep the created ListOfLocalAtoms1581 int FragmentCounter = 0; 1583 1582 while (Subgraphs->next != NULL) { 1584 1583 Subgraphs = Subgraphs->next; 1584 Subgraphs->FillBondStructureFromReference((ofstream *)&cout, mol, FragmentCounter, ListOfLocalAtoms, false); // we want to keep the created ListOfLocalAtoms 1585 1585 LocalBackEdgeStack = new StackClass<bond *> (Subgraphs->Leaf->BondCount); 1586 Subgraphs->Leaf->PickLocalBackEdges((ofstream *)&cout, ListOfLocalAtoms[FragmentCounter ++], BackEdgeStack, LocalBackEdgeStack);1587 Subgraphs->Leaf->CyclicStructureAnalysis((ofstream *)&cout, BackEdgeStack, MinimumRingSize);1586 Subgraphs->Leaf->PickLocalBackEdges((ofstream *)&cout, ListOfLocalAtoms[FragmentCounter], BackEdgeStack, LocalBackEdgeStack); 1587 Subgraphs->Leaf->CyclicStructureAnalysis((ofstream *)&cout, LocalBackEdgeStack, MinimumRingSize); 1588 1588 delete(LocalBackEdgeStack); 1589 1589 delete(Subgraphs->previous); 1590 FragmentCounter++; 1590 1591 } 1591 1592 delete(Subgraphs); 1592 1593 for (int i=0;i<FragmentCounter;i++) 1593 Free(&ListOfLocalAtoms[ FragmentCounter]);1594 Free(&ListOfLocalAtoms[i]); 1594 1595 Free(&ListOfLocalAtoms); 1595 1596 } … … 2115 2116 switch(j) { 2116 2117 case 255: // something went wrong 2118 case 2: // just for -f option 2119 case 1: // just for -v and -h options 2117 2120 delete(molecules); // also free's all molecules contained 2118 2121 delete(periode); 2122 delete(configuration); 2119 2123 cout << Verbose(0) << "Maximum of allocated memory: " 2120 2124 << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl; 2121 2125 cout << Verbose(0) << "Remaining non-freed memory: " 2122 2126 << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl; 2123 return j; 2124 break; 2125 case 1: // just for -v and -h options 2126 delete(molecules); // also free's all molecules contained 2127 delete(periode); 2128 cout << Verbose(0) << "Maximum of allocated memory: " 2129 << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl; 2130 cout << Verbose(0) << "Remaining non-freed memory: " 2131 << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl; 2132 return 0; 2133 break; 2134 case 2: // just for -f option 2135 delete(molecules); // also free's all molecules contained 2136 delete(periode); 2137 cout << Verbose(0) << "Maximum of allocated memory: " 2138 << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl; 2139 cout << Verbose(0) << "Remaining non-freed memory: " 2140 << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl; 2141 return 2; 2142 break; 2127 MemoryUsageObserver::getInstance()->purgeInstance(); 2128 return (j == 1 ? 0 : j); 2143 2129 default: 2144 2130 break; … … 2155 2141 } 2156 2142 } 2143 mol->ActiveFlag = true; 2157 2144 molecules->insert(mol); 2158 2145 } -
src/config.cpp
rfa649a r7218f8 199 199 Free(&ThermostatNames[j]); 200 200 Free(&ThermostatNames); 201 if (BG != NULL) 202 delete(BG); 201 203 }; 202 204 -
src/helpers.hpp
rfa649a r7218f8 98 98 } 99 99 100 // allocat and fill101 LookupTable = Malloc<T*>(count, "CreateFatherLookupTable - **LookupTable");100 // allocate and fill 101 LookupTable = Calloc<T*>(count, "CreateFatherLookupTable - **LookupTable"); 102 102 if (LookupTable == NULL) { 103 103 cerr << "LookupTable memory allocation failed!" << endl; -
src/memoryallocator.hpp
rfa649a r7218f8 55 55 template <> char* Malloc<char>(size_t size, const char* output); 56 56 57 /* *Allocates a memory range using calloc().57 /* Allocates a memory range using calloc(). 58 58 * Prints the provided error message in case of a failure. 59 59 * … … 61 61 * \param failure message which is printed if the allocation fails 62 62 * \return pointer to the allocated memory range, will be NULL if a failure occurred 63 */63 */ 64 64 template <typename X> X* Calloc(size_t size, const char* output) 65 65 { 66 66 X* buffer = NULL; 67 buffer = (X*) calloc(size of(X) * size, (size_t) 0);67 buffer = (X*) calloc(size, sizeof(X)); 68 68 69 69 if (buffer != NULL) { … … 76 76 return buffer; 77 77 }; 78 78 79 79 80 /** Reallocates a memory range using realloc(). If the provided pointer to the old -
src/memoryusageobserver.cpp
rfa649a r7218f8 23 23 */ 24 24 MemoryUsageObserver::~MemoryUsageObserver() { 25 for (map<void*, size_t>::iterator current = memoryUsers.begin(); current != memoryUsers.end(); current++) { 25 while (!memoryUsers.empty()) { 26 map<void*, size_t>::iterator current = memoryUsers.begin(); 27 free(current->first); 26 28 memoryUsers.erase(current); 27 29 } -
src/molecule.cpp
rfa649a r7218f8 957 957 if (result) { 958 958 *out << Verbose(5) << "Calculating distances" << endl; 959 Distances = Malloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: Distances");960 OtherDistances = Malloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances");959 Distances = Calloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: Distances"); 960 OtherDistances = Calloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances"); 961 961 SetIndexedArrayForEachAtomTo ( Distances, &atom::nr, &atom::DistanceSquaredToVector, (const Vector &)CenterOfGravity); 962 962 SetIndexedArrayForEachAtomTo ( OtherDistances, &atom::nr, &atom::DistanceSquaredToVector, (const Vector &)CenterOfGravity); … … 964 964 /// ... sort each list (using heapsort (o(N log N)) from GSL) 965 965 *out << Verbose(5) << "Sorting distances" << endl; 966 PermMap = Malloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap");967 OtherPermMap = Malloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap");966 PermMap = Calloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap"); 967 OtherPermMap = Calloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap"); 968 968 gsl_heapsort_index (PermMap, Distances, AtomCount, sizeof(double), CompareDoubles); 969 969 gsl_heapsort_index (OtherPermMap, OtherDistances, AtomCount, sizeof(double), CompareDoubles); 970 PermutationMap = Malloc<int>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");970 PermutationMap = Calloc<int>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap"); 971 971 *out << Verbose(5) << "Combining Permutation Maps" << endl; 972 972 for(int i=AtomCount;i--;) -
src/molecule_dynamics.cpp
rfa649a r7218f8 193 193 { 194 194 stringstream zeile1, zeile2; 195 int *DoubleList = Malloc<int>(AtomCount, "PrintPermutationMap: *DoubleList");195 int *DoubleList = Calloc<int>(AtomCount, "PrintPermutationMap: *DoubleList"); 196 196 int doubles = 0; 197 for (int i=0;i<AtomCount;i++)198 DoubleList[i] = 0;199 197 zeile1 << "PermutationMap: "; 200 198 zeile2 << " "; … … 243 241 void CreateInitialLists(ofstream *out, molecule *mol, struct EvaluatePotential &Params) 244 242 { 245 for (int i=mol->AtomCount; i--;)246 Params.DoubleList[i] = 0; // stores for how many atoms in startstep this atom is a target in endstep247 248 243 atom *Walker = mol->start; 249 244 while (Walker->next != mol->end) { … … 347 342 double Potential, OldPotential, OlderPotential; 348 343 struct EvaluatePotential Params; 349 Params.PermutationMap = Malloc<atom*>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.**PermutationMap");344 Params.PermutationMap = Calloc<atom*>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.**PermutationMap"); 350 345 Params.DistanceList = Malloc<DistanceMap*>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.**DistanceList"); 351 346 Params.DistanceIterators = Malloc<DistanceMap::iterator>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.*DistanceIterators"); 352 Params.DoubleList = Malloc<int>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.*DoubleList");347 Params.DoubleList = Calloc<int>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.*DoubleList"); 353 348 Params.StepList = Malloc<DistanceMap::iterator>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.*StepList"); 354 349 int round; -
src/molecule_fragmentation.cpp
rfa649a r7218f8 123 123 } 124 124 125 Free(&filename); 125 126 return status; 126 127 }; … … 574 575 // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs ===== 575 576 Subgraphs = DepthFirstSearchAnalysis(out, BackEdgeStack); 576 // fill the bond structure of the individually stored subgraphs 577 Subgraphs->next->FillBondStructureFromReference(out, this, (FragmentCounter = 0), ListOfLocalAtoms, false); // we want to keep the created ListOfLocalAtoms 577 578 578 // analysis of the cycles (print rings, get minimum cycle length) for each subgraph 579 579 for(int i=AtomCount;i--;) … … 583 583 while (MolecularWalker->next != NULL) { 584 584 MolecularWalker = MolecularWalker->next; 585 // fill the bond structure of the individually stored subgraphs 586 MolecularWalker->FillBondStructureFromReference(out, this, FragmentCounter, ListOfLocalAtoms, false); // we want to keep the created ListOfLocalAtoms 585 587 *out << Verbose(0) << "Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl; 586 588 LocalBackEdgeStack = new StackClass<bond *> (MolecularWalker->Leaf->BondCount); … … 599 601 delete(LocalBackEdgeStack); 600 602 } 603 delete(BackEdgeStack); 601 604 602 605 // ===== 3. if structure still valid, parse key set file and others ===== … … 663 666 // ===== 8b. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass ===== 664 667 //if (FragmentationToDo) { // we should always store the fragments again as coordination might have changed slightly without changing bond structure 665 // allocate memory for the pointer array and transmorph graphs into full molecular fragments666 BondFragments = new MoleculeListClass();667 int k=0;668 for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {669 KeySet test = (*runner).first;670 *out << "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "." << endl;671 BondFragments->insert(StoreFragmentFromKeySet(out, test, configuration));672 k++;673 }674 *out << k << "/" << BondFragments->ListOfMolecules.size() << " fragments generated from the keysets." << endl;675 676 // ===== 9. Save fragments' configuration and keyset files et al to disk ===677 if (BondFragments->ListOfMolecules.size() != 0) {678 // create the SortIndex from BFS labels to order in the config file679 CreateMappingLabelsToConfigSequence(out, SortIndex);680 681 *out << Verbose(1) << "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs" << endl;682 if (BondFragments->OutputConfigForListOfFragments(out, configuration, SortIndex))683 *out << Verbose(1) << "All configs written." << endl;684 else685 *out << Verbose(1) << "Some config writing failed." << endl;686 687 // store force index reference file688 BondFragments->StoreForcesFile(out, configuration->configpath, SortIndex);689 690 // store keysets file691 StoreKeySetFile(out, TotalGraph, configuration->configpath);692 693 // store Adjacency file694 StoreAdjacencyToFile(out, configuration->configpath);695 696 // store Hydrogen saturation correction file697 BondFragments->AddHydrogenCorrection(out, configuration->configpath);698 699 // store adaptive orders into file700 StoreOrderAtSiteFile(out, configuration->configpath);701 702 // restore orbital and Stop values703 CalculateOrbitals(*configuration);704 705 // free memory for bond part706 *out << Verbose(1) << "Freeing bond memory" << endl;707 delete(FragmentList); // remove bond molecule from memory708 Free(&SortIndex);709 } else710 *out << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl;711 //} else712 // *out << Verbose(1) << "No fragments to store." << endl;668 // allocate memory for the pointer array and transmorph graphs into full molecular fragments 669 BondFragments = new MoleculeListClass(); 670 int k=0; 671 for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) { 672 KeySet test = (*runner).first; 673 *out << "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "." << endl; 674 BondFragments->insert(StoreFragmentFromKeySet(out, test, configuration)); 675 k++; 676 } 677 *out << k << "/" << BondFragments->ListOfMolecules.size() << " fragments generated from the keysets." << endl; 678 679 // ===== 9. Save fragments' configuration and keyset files et al to disk === 680 if (BondFragments->ListOfMolecules.size() != 0) { 681 // create the SortIndex from BFS labels to order in the config file 682 CreateMappingLabelsToConfigSequence(out, SortIndex); 683 684 *out << Verbose(1) << "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs" << endl; 685 if (BondFragments->OutputConfigForListOfFragments(out, configuration, SortIndex)) 686 *out << Verbose(1) << "All configs written." << endl; 687 else 688 *out << Verbose(1) << "Some config writing failed." << endl; 689 690 // store force index reference file 691 BondFragments->StoreForcesFile(out, configuration->configpath, SortIndex); 692 693 // store keysets file 694 StoreKeySetFile(out, TotalGraph, configuration->configpath); 695 696 // store Adjacency file 697 StoreAdjacencyToFile(out, configuration->configpath); 698 699 // store Hydrogen saturation correction file 700 BondFragments->AddHydrogenCorrection(out, configuration->configpath); 701 702 // store adaptive orders into file 703 StoreOrderAtSiteFile(out, configuration->configpath); 704 705 // restore orbital and Stop values 706 CalculateOrbitals(*configuration); 707 708 // free memory for bond part 709 *out << Verbose(1) << "Freeing bond memory" << endl; 710 delete(FragmentList); // remove bond molecule from memory 711 Free(&SortIndex); 712 } else { 713 *out << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl; 714 } 715 delete(BondFragments); 713 716 *out << Verbose(0) << "End of bond fragmentation." << endl; 714 717 … … 751 754 bool molecule::ParseOrderAtSiteFromFile(ofstream *out, char *path) 752 755 { 753 unsigned char *OrderArray = Malloc<unsigned char>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");754 bool *MaxArray = Malloc<bool>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");756 unsigned char *OrderArray = Calloc<unsigned char>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray"); 757 bool *MaxArray = Calloc<bool>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray"); 755 758 bool status; 756 759 int AtomNr, value; … … 759 762 760 763 *out << Verbose(1) << "Begin of ParseOrderAtSiteFromFile" << endl; 761 for(int i=AtomCount;i--;)762 OrderArray[i] = 0;763 764 line << path << "/" << FRAGMENTPREFIX << ORDERATSITEFILE; 764 765 file.open(line.str().c_str()); 765 766 if (file != NULL) { 766 for (int i=AtomCount;i--;) { // initialise with 0767 OrderArray[i] = 0;768 MaxArray[i] = 0;769 }770 767 while (!file.eof()) { // parse from file 771 768 AtomNr = -1; … … 830 827 * \param *Leaf fragment molecule 831 828 * \param &Leaflet pointer to KeySet structure 832 * \param **SonList list which atom of \a *Leaf is a son of which atom in \a *mol829 * \param **SonList calloc'd list which atom of \a *Leaf is a son of which atom in \a *mol 833 830 * \return number of atoms in fragment 834 831 */ … … 840 837 for(int i=NDIM*2;i--;) 841 838 Leaf->cell_size[i] = mol->cell_size[i]; 842 843 // initialise SonList (indicates when we need to replace a bond with hydrogen instead)844 for(int i=mol->AtomCount;i--;)845 SonList[i] = NULL;846 839 847 840 // first create the minimal set of atoms from the KeySet … … 924 917 molecule * molecule::StoreFragmentFromKeySet(ofstream *out, KeySet &Leaflet, bool IsAngstroem) 925 918 { 926 atom **SonList = Malloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");919 atom **SonList = Calloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList"); 927 920 molecule *Leaf = new molecule(elemente); 928 921 … … 1389 1382 1390 1383 // prepare the subset and call the generator 1391 BondsList = Malloc<bond*>(FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");1384 BondsList = Calloc<bond*>(FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList"); 1392 1385 BondsList[0] = FragmentSearch.BondsPerSPList[0]->next; // on SP level 0 there's only the root bond 1393 1386 … … 1544 1537 // FragmentLowerOrdersList is a 2D-array of pointer to MoleculeListClass objects, one dimension represents the ANOVA expansion of a single order (i.e. 5) 1545 1538 // with all needed lower orders that are subtracted, the other dimension is the BondOrder (i.e. from 1 to 5) 1546 NumMoleculesOfOrder = Malloc<int>(UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");1547 FragmentLowerOrdersList = Malloc<Graph**>(UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");1539 NumMoleculesOfOrder = Calloc<int>(UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder"); 1540 FragmentLowerOrdersList = Calloc<Graph**>(UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList"); 1548 1541 1549 1542 // initialise the fragments structure 1550 FragmentSearch.ShortestPathList = Malloc<int>(AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");1551 1543 FragmentSearch.FragmentCounter = 0; 1552 1544 FragmentSearch.FragmentSet = new KeySet; 1553 1545 FragmentSearch.Root = FindAtom(RootKeyNr); 1546 FragmentSearch.ShortestPathList = Malloc<int>(AtomCount, "molecule::PowerSetGenerator: *ShortestPathList"); 1554 1547 for (int i=AtomCount;i--;) { 1555 1548 FragmentSearch.ShortestPathList[i] = -1; … … 1587 1580 // allocate memory for all lower level orders in this 1D-array of ptrs 1588 1581 NumLevels = 1 << (Order-1); // (int)pow(2,Order); 1589 FragmentLowerOrdersList[RootNr] = Malloc<Graph*>(NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]"); 1590 for (int i=0;i<NumLevels;i++) 1591 FragmentLowerOrdersList[RootNr][i] = NULL; 1582 FragmentLowerOrdersList[RootNr] = Calloc<Graph*>(NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]"); 1592 1583 1593 1584 // create top order where nothing is reduced … … 1665 1656 *out << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl; 1666 1657 1667 ColorList = Malloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");1658 ColorList = Calloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList"); 1668 1659 while (flag) { 1669 1660 // remove bonds that are beyond bonddistance -
src/molecule_graph.cpp
rfa649a r7218f8 126 126 127 127 // create a list to map Tesselpoint::nr to atom * 128 AtomMap = Malloc<atom *> (AtomCount, "molecule::CreateAdjacencyList - **AtomCount");128 AtomMap = Calloc<atom *> (AtomCount, "molecule::CreateAdjacencyList - **AtomCount"); 129 129 Walker = start; 130 130 while (Walker->next != end) { … … 437 437 * \param *out output stream for debugging 438 438 * \param &DFS accounting structure to allocate 439 * \param AtomCount number of nodes in graph 440 * \param BondCount number of edges in graph 441 */ 442 void DepthFirstSearchAnalysis_Init(ofstream *out, struct DFSAccounting &DFS, int AtomCount, int BondCount) 443 { 444 DFS.AtomStack = new StackClass<atom *> (AtomCount); 439 * \param *mol molecule with AtomCount, BondCount and all atoms 440 */ 441 void DepthFirstSearchAnalysis_Init(ofstream *out, struct DFSAccounting &DFS, const molecule * const mol) 442 { 443 DFS.AtomStack = new StackClass<atom *> (mol->AtomCount); 445 444 DFS.CurrentGraphNr = 0; 446 445 DFS.ComponentNumber = 0; 447 446 DFS.BackStepping = false; 447 mol->ResetAllBondsToUnused(); 448 mol->SetAtomValueToValue(-1, &atom::GraphNr); 449 mol->ActOnAllAtoms(&atom::InitComponentNr); 450 DFS.BackEdgeStack->ClearStack(); 448 451 } 449 452 ; … … 456 459 { 457 460 delete (DFS.AtomStack); 461 // delete (DFS.BackEdgeStack); // DON'T free, see DepthFirstSearchAnalysis(), is returned as allocated 458 462 } 459 463 ; … … 479 483 480 484 *out << Verbose(0) << "Begin of DepthFirstSearchAnalysis" << endl; 481 DepthFirstSearchAnalysis_Init(out, DFS, AtomCount, BondCount); 485 DepthFirstSearchAnalysis_Init(out, DFS, this); 486 482 487 DFS.Root = start->next; 483 484 ResetAllBondsToUnused();485 SetAtomValueToValue(-1, &atom::GraphNr);486 ActOnAllAtoms(&atom::InitComponentNr);487 DFS.BackEdgeStack->ClearStack();488 488 while (DFS.Root != end) { // if there any atoms at all 489 // (1) mark all edges unused, empty stack, set atom->GraphNr = 0for all489 // (1) mark all edges unused, empty stack, set atom->GraphNr = -1 for all 490 490 DFS.AtomStack->ClearStack(); 491 491 … … 602 602 { 603 603 BFS.AtomCount = AtomCount; 604 BFS.PredecessorList = Malloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList");604 BFS.PredecessorList = Calloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList"); 605 605 BFS.ShortestPathList = Malloc<int> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ShortestPathList"); 606 BFS.ColorList = Malloc<enum Shading> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ColorList");606 BFS.ColorList = Calloc<enum Shading> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ColorList"); 607 607 BFS.BFSStack = new StackClass<atom *> (AtomCount); 608 608 609 for (int i = AtomCount; i--;) { 610 BFS.PredecessorList[i] = NULL; 609 for (int i = AtomCount; i--;) 611 610 BFS.ShortestPathList[i] = -1; 612 BFS.ColorList[i] = white;613 }614 611 }; 615 612 … … 1002 999 1003 1000 // allocate storage structure 1004 CurrentBonds = Malloc<int> (8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom1001 CurrentBonds = Calloc<int> (8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom 1005 1002 return true; 1006 1003 } … … 1137 1134 BFS.AtomCount = AtomCount; 1138 1135 BFS.BondOrder = BondOrder; 1139 BFS.PredecessorList = Malloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList");1140 BFS.ShortestPathList = Malloc<int> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ShortestPathList");1136 BFS.PredecessorList = Calloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList"); 1137 BFS.ShortestPathList = Calloc<int> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ShortestPathList"); 1141 1138 BFS.ColorList = Malloc<enum Shading> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ColorList"); 1142 1139 BFS.BFSStack = new StackClass<atom *> (AtomCount); … … 1148 1145 // initialise each vertex as white with no predecessor, empty queue, color Root lightgray 1149 1146 for (int i = AtomCount; i--;) { 1150 BFS.PredecessorList[i] = NULL;1151 1147 BFS.ShortestPathList[i] = -1; 1152 1148 if ((AddedAtomList != NULL) && (AddedAtomList[i] != NULL)) // mark already present atoms (i.e. Root and maybe others) as visited … … 1155 1151 BFS.ColorList[i] = white; 1156 1152 } 1157 BFS.ShortestPathList[Root->nr] = 0;1153 //BFS.ShortestPathList[Root->nr] = 0; //is set due to Calloc() 1158 1154 } 1159 1155 ; … … 1302 1298 { 1303 1299 // reset parent list 1304 ParentList = Malloc<atom*> (AtomCount, "molecule::BuildInducedSubgraph_Init: **ParentList");1300 ParentList = Calloc<atom*> (AtomCount, "molecule::BuildInducedSubgraph_Init: **ParentList"); 1305 1301 *out << Verbose(3) << "Resetting ParentList." << endl; 1306 for (int i = AtomCount; i--;)1307 ParentList[i] = NULL;1308 1302 } 1309 1303 ; -
src/moleculelist.cpp
rfa649a r7218f8 422 422 423 423 // 0b. allocate memory for constants 424 FitConstant = Malloc<double**>(3, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");424 FitConstant = Calloc<double**>(3, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant"); 425 425 for (int k = 0; k < 3; k++) { 426 FitConstant[k] = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");426 FitConstant[k] = Calloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]"); 427 427 for (int i = a; i--;) { 428 FitConstant[k][i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");428 FitConstant[k][i] = Calloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]"); 429 429 } 430 430 } … … 471 471 472 472 // 0d. allocate final correction matrix 473 correction = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **correction");473 correction = Calloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **correction"); 474 474 for (int i = a; i--;) 475 correction[i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *correction[]");475 correction[i] = Calloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *correction[]"); 476 476 477 477 // 1a. go through every molecule in the list … … 548 548 output.close(); 549 549 // 6. free memory of parsed matrices 550 FitConstant = Malloc<double**>(a, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");551 550 for (int k = 0; k < 3; k++) { 552 FitConstant[k] = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");553 551 for (int i = a; i--;) { 554 FitConstant[k][i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]"); 555 } 556 } 552 Free(&FitConstant[k][i]); 553 } 554 Free(&FitConstant[k]); 555 } 556 Free(&FitConstant); 557 557 cout << "done." << endl; 558 558 return true; … … 712 712 //outputFragment.close(); 713 713 //outputFragment.clear(); 714 delete (FragmentNumber); 715 //Free(&FragmentNumber); 714 Free(&FragmentNumber); 716 715 } 717 716 cout << " done." << endl; … … 848 847 } 849 848 } 850 FragmentCounter++;851 if (next != NULL)852 status = next->FillBondStructureFromReference(out, reference, FragmentCounter, ListOfLocalAtoms);853 FragmentCounter--;849 // FragmentCounter++; 850 // if (next != NULL) 851 // status = next->FillBondStructureFromReference(out, reference, FragmentCounter, ListOfLocalAtoms); 852 // FragmentCounter--; 854 853 } 855 854 … … 860 859 Free(&ListOfLocalAtoms); 861 860 } 862 FragmentCounter--;863 861 *out << Verbose(1) << "End of FillBondStructureFromReference." << endl; 864 862 return status; … … 907 905 908 906 /** Fills a lookup list of father's Atom::nr -> atom for each subgraph. 909 * \param *out output stream fro debugging907 * \param *out output stream from debugging 910 908 * \param ***ListOfLocalAtoms Lookup table for each subgraph and index of each atom in global molecule, may be NULL on start, then it is filled 911 909 * \param FragmentCounter counts the fragments as we move along the list 912 910 * \param GlobalAtomCount number of atoms in the complete molecule 913 911 * \param &FreeList true - ***ListOfLocalAtoms is free'd before return, false - it is not 914 * \return true - succes , false - failure912 * \return true - success, false - failure 915 913 */ 916 914 bool MoleculeLeafClass::FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, const int FragmentCounter, const int GlobalAtomCount, bool &FreeList) … … 921 919 if (ListOfLocalAtoms == NULL) { // allocated initial pointer 922 920 // allocate and set each field to NULL 923 ListOfLocalAtoms = Malloc<atom**>(Counter, "MoleculeLeafClass::FillBondStructureFromReference- ***ListOfLocalAtoms");921 ListOfLocalAtoms = Calloc<atom**>(Counter, "MoleculeLeafClass::FillListOfLocalAtoms - ***ListOfLocalAtoms"); 924 922 if (ListOfLocalAtoms != NULL) { 925 for (int i = Counter; i--;)926 ListOfLocalAtoms[i] = NULL;927 923 FreeList = FreeList && true; 928 924 } else … … 965 961 if (FragmentList == NULL) { 966 962 KeySetCounter = Count(); 967 FragmentList = Malloc<Graph*>(KeySetCounter, "MoleculeLeafClass::AssignKeySetsToFragment - **FragmentList"); 968 for (int i = KeySetCounter; i--;) 969 FragmentList[i] = NULL; 963 FragmentList = Calloc<Graph*>(KeySetCounter, "MoleculeLeafClass::AssignKeySetsToFragment - **FragmentList"); 970 964 KeySetCounter = 0; 971 965 } -
src/stackclass.hpp
rfa649a r7218f8 48 48 /** Constructor of class StackClass. 49 49 */ 50 template <typename T> StackClass<T>::StackClass(int dimension) : EntryCount(dimension), CurrentLastEntry(0), CurrentFirstEntry(0), NextFreeField(0)51 { 52 StackList = Malloc<T>(EntryCount, "StackClass::StackClass: **StackList");50 template <typename T> StackClass<T>::StackClass(int dimension) : StackList(NULL), EntryCount(dimension), CurrentLastEntry(0), CurrentFirstEntry(0), NextFreeField(0) 51 { 52 StackList = Calloc<T>(EntryCount, "StackClass::StackClass: **StackList"); 53 53 }; 54 54 -
src/unittests/memoryallocatorunittest.cpp
rfa649a r7218f8 28 28 void MemoryAllocatorTest::tearDown() 29 29 { 30 MemoryUsageObserver::getInstance()->purgeInstance(); 30 31 }; 31 32 … … 49 50 50 51 char** buffer4 = NULL; 51 buffer4 = Malloc<char*>(1, ""); 52 buffer4 = Malloc<char*>(10, ""); 53 for (int i=0;i<10;i++) 54 buffer4[i] = NULL; 52 55 Free(&buffer4); 53 56 }; … … 59 62 { 60 63 int* buffer1 = NULL; 61 buffer1 = Calloc<int>(1 , "");64 buffer1 = Calloc<int>(10, ""); 62 65 Free(&buffer1); 63 66 64 67 long* buffer2 = NULL; 65 buffer2 = Calloc<long>(1 , "");68 buffer2 = Calloc<long>(10, ""); 66 69 Free(&buffer2); 67 70 68 char* buffer3 = NULL; 69 buffer3 = Calloc<char>(1, ""); 71 char** buffer3 = NULL; 72 buffer3 = Calloc<char *>(10, ""); 73 for (int i=0;i<10;i++) 74 buffer3[i] = NULL; 70 75 Free(&buffer3); 71 76 };
Note:
See TracChangeset
for help on using the changeset viewer.
