source: src/Jobs/MPQCJob_Work.cpp@ 0ee9cb3

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 0ee9cb3 was fbf005, checked in by Frederik Heber <heber@…>, 8 years ago

HUGE: Extracted libmolecuilder_mpqc that is now linked to poolworker.

  • This stops the problems with MemDebug and mpqc when linking against libLinearAlgebra in debug mode: static global variables in libLinAlg are allocated using MemDebug (prefixed with a checksum) but are deallocated using normal libc's free() on exit. This causes an invalid free() as the ptr given to free points inside the block and not at its start. The problem comes from mpqc's use of own new and delete implementation. I'm guessing its reference counting is the culprit. Hence, we need to separate these two compilations from another in different units/libraries. Therefore, we have split off libmolecuilder_mpqc, .._mpqc_extract and additionally place the MPQCJob::Work() implementation inside libMolecuilderJobs_Work.
  • libmolecuilder_mpqc contains all MPQC's code in mpqc.cc (and linked libraries) that is not the main() function.
  • libmolecuilder_mpqc_extract contains functions that extract results such as energies, forces, charge grids from the obtained mpqc solution. These were added by myself to the mpqc code before.
  • molecuilder_mpqc is then linked against a NoOp .._extract library version. Thereby, it does not use any of the Molecuilder or related libraries and does not come in contact with MemDebug.
  • molecuilder_poolworker however is linked with the full .._extract library and hence performs these extractions.
  • poolworker now executes MPQCJob, MPQCCommandJob, and VMGJob and therefore needs to enforce binding to all of them.
  • TESTS: renamed molecuilder_mpqc.in to molecuilder_poolworker.in.
  • Property mode set to 100644
File size: 4.6 KB
Line 
1/* Project: MoleCuilder
2 * Description: creates and alters molecular systems
3 * Copyright (C) 2017 Frederik Heber. All rights reserved.
4 *
5 *
6 * This file is part of MoleCuilder.
7 *
8 * MoleCuilder is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * MoleCuilder is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22/** \file MPCJob_Work.cpp
23 *
24 * Function implementations for the class vector.
25 *
26 */
27
28// include config.h
29#ifdef HAVE_CONFIG_H
30#include <config.h>
31#endif
32
33#include <sstream>
34
35#include "MPQCJob.hpp"
36
37#include "CodePatterns/Log.hpp"
38
39#ifdef HAVE_JOBMARKET
40// include headers that implement a archive in simple text format
41// otherwise BOOST_CLASS_EXPORT_IMPLEMENT has no effect
42#include <boost/archive/text_oarchive.hpp>
43#include <boost/archive/text_iarchive.hpp>
44#include <boost/tokenizer.hpp>
45
46#include "JobMarket/Results/FragmentResult.hpp"
47
48#include <fstream>
49#include <iostream>
50#include <stdlib.h>
51
52#include <util/class/scexception.h>
53#include <util/group/message.h>
54
55#include "mpqc.h"
56
57using namespace std;
58
59using namespace sc;
60
61FragmentResult::ptr MPQCJob::Work()
62{
63 char mpqc[] = "mpqc" ;
64 char **argv = new char*[1];
65 argv[0] = &mpqc[0];
66 int argc = 1;
67
68 // now comes the actual work
69 mpqc::InitValues initvalues;
70 int nfilebase = (int) inputfile.length();
71 initvalues.in_char_array = new char[nfilebase + 1];
72 strncpy(initvalues.in_char_array, inputfile.c_str(), nfilebase);
73 initvalues.in_char_array[nfilebase] = '\0';
74 initvalues.grp = MessageGrp::get_default_messagegrp();
75 // create unique, temporary name and check whether it exists
76 char *tempfilename = NULL;
77 {
78 std::ifstream test;
79 do {
80 if (initvalues.output != NULL) // free buffer from last round
81 delete initvalues.output;
82 char filename_template[] = "mpqc_temp_XXXXXX\0";
83 char filename_suffix[] = ".in\0";
84 tempfilename = (char *) malloc ( (strlen(filename_template)+strlen(filename_suffix)+2)*(sizeof(char)));
85 strncpy(tempfilename, mktemp(filename_template), strlen(filename_template));
86 tempfilename[strlen(filename_template)] = '\0';
87 strncat(tempfilename, filename_suffix, strlen(filename_suffix));
88 initvalues.output = tempfilename;
89 //free(tempfilename); // don't free! output takes over pointer!
90 test.open(initvalues.output);
91 } while (test.good()); // test whether file does not(!) exist
92 test.close();
93 }
94 // put info how to sample the density into MPQCData
95 MPQCData data(grid);
96 data.DoLongrange = DoLongrange; // set whether we sample the density
97 data.DoValenceOnly = DoValenceOnly; // set whether we sample just valence electron and nuclei densities
98// now call work horse
99 try {
100 mpqc::mainFunction(initvalues, argc, argv, static_cast<void *>(&data));
101 }
102 catch (SCException &e) {
103 cout << argv[0] << ": ERROR: SC EXCEPTION RAISED:" << endl
104 << e.what()
105 << endl;
106 detail::clean_up();
107 }
108
109 //delete[] in_char_array; // is deleted in mainFunction()
110 if (initvalues.output != 0) {
111 free(tempfilename);
112 }
113 delete[] argv;
114 initvalues.grp = NULL;
115
116 // place into returnstream
117 std::stringstream returnstream;
118 boost::archive::text_oarchive oa(returnstream);
119 oa << data;
120
121 FragmentResult::ptr s( new FragmentResult(getId(), returnstream.str()) );
122 if (s->exitflag != 0)
123 cerr << "Job #" << s->getId() << " failed to reach desired accuracy." << endl;
124
125 return s;
126}
127#else
128FragmentResult::ptr MPQCJob::Work()
129{
130 // instantiate empty data
131 const MPQCData data;
132 std::stringstream returnstream;
133 boost::archive::text_oarchive oa(returnstream);
134 oa << data;
135
136 // create the result
137 FragmentResult::ptr ptr( new FragmentResult(getId(), returnstream.str()) );
138 if (data.desired_accuracy != 0.) {
139 ptr->exitflag = data.accuracy < data.desired_accuracy ? 0 : 1;
140 if (ptr->exitflag != 0)
141 ELOG(1, "Job #" << ptr->getId() << " failed to reach desired accuracy.");
142 } else {
143 LOG(3, "INFO: No precision returned from MPQC job, not checking.");
144 }
145
146 return ptr;
147}
148#endif
149
150// we need to explicitly instantiate the serialization functions as
151// its is only serialized through its base class FragmentJob
152BOOST_CLASS_EXPORT_IMPLEMENT(MPQCJob)
Note: See TracBrowser for help on using the repository browser.