source: src/bin/mpqc/mpqc.cc@ d392067

Last change on this file since d392067 was d392067, checked in by Frederik Heber <heber@…>, 13 years ago

Extracted performing gradient calculation into own function.

  • Property mode set to 100644
File size: 40.7 KB
Line 
1//
2// mpqc.cc
3//
4// Copyright (C) 1996 Limit Point Systems, Inc.
5//
6// Author: Edward Seidl <seidl@janed.com>
7// Maintainer: LPS
8//
9// This file is part of MPQC.
10//
11// MPQC is free software; you can redistribute it and/or modify
12// it under the terms of the GNU General Public License as published by
13// the Free Software Foundation; either version 2, or (at your option)
14// any later version.
15//
16// MPQC is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with the MPQC; see the file COPYING. If not, write to
23// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24//
25// The U.S. Government is granted a limited license as per AL 91-7.
26//
27
28// This is needed to make GNU extensions available, such as
29// feenableexcept and fedisableexcept.
30#ifndef _GNU_SOURCE
31# define _GNU_SOURCE
32#endif
33
34#ifdef HAVE_CONFIG_H
35#include <scconfig.h>
36#endif
37
38#ifdef HAVE_TIME_H
39#include <time.h>
40#endif
41
42#include <scdirlist.h>
43
44#include <new>
45#include <stdexcept>
46#include <string.h>
47#include <unistd.h>
48#include <sys/stat.h>
49#include <fstream>
50
51#include <boost/bind.hpp>
52#include <boost/function.hpp>
53
54#include <scconfig.h>
55#ifdef HAVE_SSTREAM
56# include <sstream>
57#else
58# include <strstream.h>
59#endif
60
61#ifdef HAVE_SYS_RESOURCE_H
62# include <sys/resource.h>
63#endif
64#ifdef HAVE_SYS_TIME_H
65# include <sys/time.h>
66#endif
67
68#include <util/options/GetLongOpt.h>
69#include <util/class/scexception.h>
70#include <util/misc/newstring.h>
71#include <util/keyval/keyval.h>
72#include <util/state/state_bin.h>
73#include <util/group/message.h>
74#include <util/group/memory.h>
75#include <util/group/mstate.h>
76#include <util/group/thread.h>
77#include <util/group/pregtime.h>
78#include <util/misc/bug.h>
79#include <util/misc/formio.h>
80#include <util/misc/exenv.h>
81#ifdef HAVE_CHEMISTRY_CCA
82 #include <util/misc/ccaenv.h>
83#endif
84#include <util/render/render.h>
85
86#include <math/optimize/opt.h>
87
88#include <chemistry/molecule/coor.h>
89#include <chemistry/molecule/energy.h>
90#include <chemistry/molecule/molfreq.h>
91#include <chemistry/molecule/fdhess.h>
92#include <chemistry/molecule/formula.h>
93#include <chemistry/qc/wfn/wfn.h>
94
95// Force linkages:
96#include <util/group/linkage.h>
97#include <chemistry/qc/wfn/linkage.h>
98#include <chemistry/qc/scf/linkage.h>
99#include <chemistry/qc/dft/linkage.h>
100#include <chemistry/qc/mbpt/linkage.h>
101#ifdef HAVE_SC_SRC_LIB_CHEMISTRY_QC_MBPTR12
102# include <chemistry/qc/mbptr12/linkage.h>
103#endif
104#ifdef HAVE_SC_SRC_LIB_CHEMISTRY_QC_CINTS
105# include <chemistry/qc/cints/linkage.h>
106#endif
107//#include <chemistry/qc/psi/linkage.h>
108#include <util/state/linkage.h>
109#ifdef HAVE_SC_SRC_LIB_CHEMISTRY_QC_CC
110# include <chemistry/qc/cc/linkage.h>
111#endif
112#ifdef HAVE_SC_SRC_LIB_CHEMISTRY_QC_PSI
113# include <chemistry/qc/psi/linkage.h>
114#endif
115#ifdef HAVE_SC_SRC_LIB_CHEMISTRY_QC_INTCCA
116# include <chemistry/qc/intcca/linkage.h>
117#endif
118
119#ifdef HAVE_MPI
120#define MPICH_SKIP_MPICXX
121#include <mpi.h>
122#include <util/group/messmpi.h>
123#endif
124
125using namespace std;
126using namespace sc;
127
128#include "mpqcin.h"
129
130//////////////////////////////////////////////////////////////////////////
131
132const KeyValValueboolean truevalue(1), falsevalue(0);
133const char *devnull = "/dev/null";
134
135
136static void
137trash_stack_b(int &i, char *&ichar)
138{
139 char stack;
140 ichar = &stack;
141 ichar -= 10;
142 for (i=0; i<1000; i++) {
143 *ichar-- = 0xfe;
144 }
145}
146
147static void
148trash_stack()
149{
150 int i;
151 char *ichar;
152 trash_stack_b(i,ichar);
153}
154
155static void
156clean_up(void)
157{
158 MemoryGrp::set_default_memorygrp(0);
159 MessageGrp::set_default_messagegrp(0);
160 ThreadGrp::set_default_threadgrp(0);
161 SCMatrixKit::set_default_matrixkit(0);
162 Integral::set_default_integral(0);
163 RegionTimer::set_default_regiontimer(0);
164}
165
166#include <signal.h>
167
168#ifdef HAVE_FENV_H
169# include <fenv.h>
170#endif
171
172static void
173print_unseen(const Ref<ParsedKeyVal> &parsedkv,
174 const char *input)
175{
176 if (parsedkv->have_unseen()) {
177 ExEnv::out0() << endl;
178 ExEnv::out0() << indent
179 << "The following keywords in \"" << input << "\" were ignored:"
180 << endl;
181 ExEnv::out0() << incindent;
182 parsedkv->print_unseen(ExEnv::out0());
183 ExEnv::out0() << decindent;
184 }
185}
186
187double EvaluateDensity(
188 SCVector3 &r,
189 Ref<Integral> &intgrl,
190 GaussianBasisSet::ValueData &vdat,
191 Ref<Wavefunction> &wfn);
192
193/** Places all known options into \a options and parses them from argc,argv.
194 *
195 * \param options options structure
196 * \param argc argument count
197 * \param argv argument array
198 * \return return value by GetLongOpt::parse() function
199 */
200int ParseOptions(
201 GetLongOpt &options,
202 int argc,
203 char **argv)
204{
205 options.usage("[options] [filename]");
206 options.enroll("f", GetLongOpt::MandatoryValue,
207 "the name of an object format input file", 0);
208 options.enroll("o", GetLongOpt::MandatoryValue,
209 "the name of the output file", 0);
210 options.enroll("n", GetLongOpt::NoValue,
211 "listen for incoming object format input files", 0);
212 options.enroll("messagegrp", GetLongOpt::MandatoryValue,
213 "which message group to use", 0);
214 options.enroll("threadgrp", GetLongOpt::MandatoryValue,
215 "which thread group to use", 0);
216 options.enroll("memorygrp", GetLongOpt::MandatoryValue,
217 "which memory group to use", 0);
218 options.enroll("integral", GetLongOpt::MandatoryValue,
219 "which integral evaluator to use", 0);
220 options.enroll("l", GetLongOpt::MandatoryValue, "basis set limit", "0");
221 options.enroll("W", GetLongOpt::MandatoryValue,
222 "set the working directory", ".");
223 options.enroll("c", GetLongOpt::NoValue, "check input then exit", 0);
224 options.enroll("v", GetLongOpt::NoValue, "print the version number", 0);
225 options.enroll("w", GetLongOpt::NoValue, "print the warranty", 0);
226 options.enroll("L", GetLongOpt::NoValue, "print the license", 0);
227 options.enroll("k", GetLongOpt::NoValue, "print key/value assignments", 0);
228 options.enroll("i", GetLongOpt::NoValue, "convert simple to OO input", 0);
229 options.enroll("d", GetLongOpt::NoValue, "debug", 0);
230 options.enroll("h", GetLongOpt::NoValue, "print this message", 0);
231 options.enroll("cca-path", GetLongOpt::OptionalValue,
232 "cca component path", "");
233 options.enroll("cca-load", GetLongOpt::OptionalValue,
234 "cca components to load", "");
235
236 int optind = options.parse(argc, argv);
237
238 return optind;
239}
240
241/** Checks for each known option and acts accordingly.
242 *
243 * \param options option structure
244 * \param *output name of outputfile on return
245 * \param *outstream open output stream on return
246 */
247void ComputeOptions(
248 GetLongOpt &options,
249 const char *&output,
250 ostream *&outstream)
251{
252 output = options.retrieve("o");
253 outstream = 0;
254 if (output != 0) {
255 outstream = new ofstream(output);
256 ExEnv::set_out(outstream);
257 }
258
259 if (options.retrieve("h")) {
260 ExEnv::out0()
261 << indent << "MPQC version " << SC_VERSION << endl
262 << indent << "compiled for " << TARGET_ARCH << endl
263 << SCFormIO::copyright << endl;
264 options.usage(ExEnv::out0());
265 exit(0);
266 }
267
268 if (options.retrieve("v")) {
269 ExEnv::out0()
270 << indent << "MPQC version " << SC_VERSION << endl
271 << indent << "compiled for " << TARGET_ARCH << endl
272 << SCFormIO::copyright;
273 exit(0);
274 }
275
276 if (options.retrieve("w")) {
277 ExEnv::out0()
278 << indent << "MPQC version " << SC_VERSION << endl
279 << indent << "compiled for " << TARGET_ARCH << endl
280 << SCFormIO::copyright << endl
281 << SCFormIO::warranty;
282 exit(0);
283 }
284
285 if (options.retrieve("L")) {
286 ExEnv::out0()
287 << indent << "MPQC version " << SC_VERSION << endl
288 << indent << "compiled for " << TARGET_ARCH << endl
289 << SCFormIO::copyright << endl
290 << SCFormIO::license;
291 exit(0);
292 }
293
294 if (options.retrieve("d"))
295 SCFormIO::set_debug(1);
296
297 // set the working dir
298 if (strcmp(options.retrieve("W"),"."))
299 int retval = chdir(options.retrieve("W"));
300
301 // check that n and f/o are not given at the same time
302 if ((options.retrieve("n")) && ((options.retrieve("f")) || (options.retrieve("o")))) {
303 throw invalid_argument("-n must not be given with -f or -o");
304 }
305}
306
307/** Sets object and generic input file names.
308 *
309 * \param object_input filename of object-oriented input
310 * \param generic_input filename of generic input
311 * \param options option structure
312 * \param argc argument count
313 * \param argv argument array
314 */
315void getInputFileNames(
316 const char *&object_input,
317 const char *&generic_input,
318 GetLongOpt &options,
319 int argc,
320 char **argv)
321{
322 // initialize keyval input
323 object_input = options.retrieve("f");
324 generic_input = 0;
325 if (argc - optind == 0) {
326 generic_input = 0;
327 }
328 else if (argc - optind == 1) {
329 generic_input = argv[optind];
330 }
331 else {
332 options.usage();
333 throw invalid_argument("extra arguments given");
334 }
335
336 if (object_input == 0 && generic_input == 0) {
337 generic_input = "mpqc.in";
338 }
339 else if (object_input && generic_input) {
340 options.usage();
341 throw invalid_argument("only one of -f and a file argument can be given");
342 }
343}
344
345/** Gets the MPI Message group.
346 *
347 * \param grp reference to obtained group
348 * \param argc argument count
349 * \param argv argument array
350 */
351void getMessageGroup(
352 Ref<MessageGrp> &grp,
353 int argc,
354 char **argv)
355{
356#if defined(HAVE_MPI) && defined(ALWAYS_USE_MPI)
357 grp = new MPIMessageGrp(&argc, &argv);
358#endif
359 if (grp.null()) grp = MessageGrp::initial_messagegrp(argc, argv);
360 if (grp.nonnull())
361 MessageGrp::set_default_messagegrp(grp);
362 else
363 grp = MessageGrp::get_default_messagegrp();
364}
365
366/** Sets the base name of output files.
367 *
368 * \param input input file name
369 * \param output output file name
370 */
371void setOutputBaseName(const char *input, const char *output)
372{
373 const char *basename_source;
374 if (output) basename_source = output;
375 else basename_source = input;
376 int nfilebase = (int) (::strrchr(basename_source, '.') - basename_source);
377 char *basename = new char[nfilebase + 1];
378 strncpy(basename, basename_source, nfilebase);
379 basename[nfilebase] = '\0';
380 SCFormIO::set_default_basename(basename);
381 delete[] basename;
382}
383
384/** Prints current key values.
385 *
386 * \param keyval key value structure
387 * \param opt optimization structure
388 * \param molname name of molecule
389 * \param restartfile name of restartfile
390 */
391void printOptions(
392 Ref<KeyVal> &keyval,
393 Ref<Optimize> &opt,
394 const char *molname,
395 const char *restartfile)
396{
397 int restart = keyval->booleanvalue("restart",truevalue);
398
399 int checkpoint = keyval->booleanvalue("checkpoint",truevalue);
400
401 int savestate = keyval->booleanvalue("savestate",truevalue);
402
403 int do_energy = keyval->booleanvalue("do_energy",truevalue);
404
405 int do_grad = keyval->booleanvalue("do_gradient",falsevalue);
406
407 int do_opt = keyval->booleanvalue("optimize",truevalue);
408
409 int do_pdb = keyval->booleanvalue("write_pdb",falsevalue);
410
411 int print_mole = keyval->booleanvalue("print_mole",truevalue);
412
413 int print_timings = keyval->booleanvalue("print_timings",truevalue);
414
415 // sanity checks for the benefit of reasonable looking output
416 if (opt.null()) do_opt=0;
417
418 ExEnv::out0() << endl << indent
419 << "MPQC options:" << endl << incindent
420 << indent << "matrixkit = <"
421 << SCMatrixKit::default_matrixkit()->class_name() << ">" << endl
422 << indent << "filename = " << molname << endl
423 << indent << "restart_file = " << restartfile << endl
424 << indent << "restart = " << (restart ? "yes" : "no") << endl
425 << indent << "checkpoint = " << (checkpoint ? "yes" : "no") << endl
426 << indent << "savestate = " << (savestate ? "yes" : "no") << endl
427 << indent << "do_energy = " << (do_energy ? "yes" : "no") << endl
428 << indent << "do_gradient = " << (do_grad ? "yes" : "no") << endl
429 << indent << "optimize = " << (do_opt ? "yes" : "no") << endl
430 << indent << "write_pdb = " << (do_pdb ? "yes" : "no") << endl
431 << indent << "print_mole = " << (print_mole ? "yes" : "no") << endl
432 << indent << "print_timings = " << (print_timings ? "yes" : "no")
433 << endl << decindent;
434
435}
436
437/** Saves the current state to checkpoint file.
438 *
439 * \param keyval key value structure
440 * \param opt optimization structure
441 * \param grp message group
442 * \param mole MolecularEnergy object
443 * \param molname name of molecule
444 * \param ckptfile name of check point file
445 */
446void saveState(
447 char *wfn_file,
448 int savestate,
449 Ref<Optimize> &opt,
450 Ref<MessageGrp> &grp,
451 Ref<MolecularEnergy> &mole,
452 char *&molname,
453 char *&ckptfile)
454{
455 // function stuff
456 if (savestate) {
457 if (opt.nonnull()) {
458 if (grp->me() == 0) {
459 ckptfile = new char[strlen(molname)+6];
460 sprintf(ckptfile,"%s.ckpt",molname);
461 }
462 else {
463 ckptfile = new char[strlen(devnull)+1];
464 strcpy(ckptfile, devnull);
465 }
466
467 StateOutBin so(ckptfile);
468 SavableState::save_state(opt.pointer(),so);
469 so.close();
470
471 delete[] ckptfile;
472 }
473
474 if (mole.nonnull()) {
475 if (grp->me() == 0) {
476 if (wfn_file == 0) {
477 wfn_file = new char[strlen(molname)+6];
478 sprintf(wfn_file,"%s.wfn",molname);
479 }
480 }
481 else {
482 delete[] wfn_file;
483 wfn_file = new char[strlen(devnull)+1];
484 strcpy(wfn_file, devnull);
485 }
486
487 StateOutBin so(wfn_file);
488 SavableState::save_state(mole.pointer(),so);
489 so.close();
490
491 }
492 }
493 delete[] wfn_file;
494}
495
496/** Sets up indentation and output modes.
497 *
498 * \param grp message group
499 */
500void setupSCFormIO(
501 Ref<MessageGrp> &grp
502 )
503{
504 SCFormIO::setindent(ExEnv::outn(), 2);
505 SCFormIO::setindent(ExEnv::errn(), 2);
506 SCFormIO::setindent(cout, 2);
507 SCFormIO::setindent(cerr, 2);
508
509 SCFormIO::set_printnode(0);
510 if (grp->n() > 1)
511 SCFormIO::init_mp(grp->me());
512}
513
514/** Initialises the timer.
515 *
516 * \param grp message group
517 * \param keyval key value structure
518 * \param tim timing structure
519 */
520void initTimings(
521 Ref<MessageGrp> &grp,
522 Ref<KeyVal> &keyval,
523 Ref<RegionTimer> &tim
524 )
525{
526 grp->sync(); // make sure nodes are sync'ed before starting timings
527 if (keyval->exists("timer")) tim << keyval->describedclassvalue("timer");
528 else tim = new ParallelRegionTimer(grp,"mpqc",1,1);
529 RegionTimer::set_default_regiontimer(tim);
530
531 if (tim.nonnull()) tim->enter("input");
532}
533
534/** Prints the header of the output.
535 *
536 * \param tim timing structure
537 */
538void makeAnnouncement(
539 Ref<RegionTimer> &tim
540 )
541{
542 const char title1[] = "MPQC: Massively Parallel Quantum Chemistry";
543 int ntitle1 = sizeof(title1);
544 const char title2[] = "Version " SC_VERSION;
545 int ntitle2 = sizeof(title2);
546 ExEnv::out0() << endl;
547 ExEnv::out0() << indent;
548 for (int i=0; i<(80-ntitle1)/2; i++) ExEnv::out0() << ' ';
549 ExEnv::out0() << title1 << endl;
550 ExEnv::out0() << indent;
551 for (int i=0; i<(80-ntitle2)/2; i++) ExEnv::out0() << ' ';
552 ExEnv::out0() << title2 << endl << endl;
553
554 const char *tstr = 0;
555#if defined(HAVE_TIME) && defined(HAVE_CTIME)
556 time_t t;
557 time(&t);
558 tstr = ctime(&t);
559#endif
560 if (!tstr) {
561 tstr = "UNKNOWN";
562 }
563
564 ExEnv::out0()
565 << indent << scprintf("Machine: %s", TARGET_ARCH) << endl
566 << indent << scprintf("User: %s@%s",
567 ExEnv::username(), ExEnv::hostname()) << endl
568 << indent << scprintf("Start Time: %s", tstr) << endl;
569}
570
571/** Parse the input file into the key value container.
572 *
573 * \param grp message group
574 * \param parsedkev keyvalue container on return
575 * \param options options structure
576 * \param input input file name
577 * \param generic_input filename of generic input
578 */
579void parseInputfile(
580 Ref<MessageGrp> &grp,
581 Ref<ParsedKeyVal> &parsedkv,
582 GetLongOpt &options,
583 const char *&input,
584 const char *&generic_input
585 )
586{
587 // read the input file on only node 0
588 char *in_char_array;
589 if (grp->me() == 0) {
590 ifstream is(input);
591#ifdef HAVE_SSTREAM
592 ostringstream ostrs;
593 is >> ostrs.rdbuf();
594 int n = 1 + strlen(ostrs.str().c_str());
595 in_char_array = strcpy(new char[n],ostrs.str().c_str());
596#else
597 ostrstream ostrs;
598 is >> ostrs.rdbuf();
599 ostrs << ends;
600 in_char_array = ostrs.str();
601 int n = ostrs.pcount();
602#endif
603 grp->bcast(n);
604 grp->bcast(in_char_array, n);
605 }
606 else {
607 int n;
608 grp->bcast(n);
609 in_char_array = new char[n];
610 grp->bcast(in_char_array, n);
611 }
612
613 int use_simple_input;
614 if (generic_input && grp->me() == 0) {
615 MPQCIn mpqcin;
616 use_simple_input = mpqcin.check_string(in_char_array);
617 }
618 else {
619 use_simple_input = 0;
620 }
621 grp->bcast(use_simple_input);
622
623 if (use_simple_input) {
624 MPQCIn mpqcin;
625 char *simple_input_text = mpqcin.parse_string(in_char_array);
626 if (options.retrieve("i")) {
627 ExEnv::out0() << "Generated object-oriented input file:" << endl
628 << simple_input_text
629 << endl;
630 exit(0);
631 }
632 parsedkv = new ParsedKeyVal();
633 parsedkv->parse_string(simple_input_text);
634 delete[] simple_input_text;
635 }
636 else {
637 parsedkv = new ParsedKeyVal();
638 parsedkv->parse_string(in_char_array);
639 }
640 delete[] in_char_array;
641}
642
643/** Get the thread group.
644 *
645 * \param keyval keyvalue container
646 * \param thread thread group on return
647 * \param argc argument count
648 * \param argv argument array
649 */
650void getThreadGroup(
651 Ref<KeyVal> &keyval,
652 Ref<ThreadGrp> &thread,
653 int argc,
654 char **argv)
655{
656 //first try the commandline and environment
657 thread = ThreadGrp::initial_threadgrp(argc, argv);
658
659 // if we still don't have a group, try reading the thread group
660 // from the input
661 if (thread.null()) {
662 thread << keyval->describedclassvalue("thread");
663 }
664
665 if (thread.nonnull())
666 ThreadGrp::set_default_threadgrp(thread);
667 else
668 thread = ThreadGrp::get_default_threadgrp();
669}
670
671/** Get the memory group.
672 *
673 * \param keyval keyvalue container
674 * \param memory memory group on return
675 * \param argc argument count
676 * \param argv argument array
677 */
678void getMemoryGroup(
679 Ref<KeyVal> &keyval,
680 Ref<MemoryGrp> &memory,
681 int argc,
682 char **argv)
683{
684 // first try the commandline and environment
685 memory = MemoryGrp::initial_memorygrp(argc, argv);
686
687 // if we still don't have a group, try reading the memory group
688 // from the input
689 if (memory.null()) {
690 memory << keyval->describedclassvalue("memory");
691 }
692
693 if (memory.nonnull())
694 MemoryGrp::set_default_memorygrp(memory);
695 else
696 memory = MemoryGrp::get_default_memorygrp();
697}
698
699/** Prepares CCA component if available.
700 *
701 * \param keyval keyvalue container
702 * \param options parsed command line options
703 */
704void prepareCCA(
705 Ref<KeyVal> &keyval,
706 GetLongOpt &options
707 )
708{
709#ifdef HAVE_CHEMISTRY_CCA
710 // initialize cca framework
711 KeyValValuestring emptystring("");
712 bool do_cca = keyval->booleanvalue("do_cca",falsevalue);
713
714 string cca_path(options.retrieve("cca-path"));
715 string cca_load(options.retrieve("cca-load"));
716 if(cca_path.size()==0)
717 cca_path = keyval->stringvalue("cca_path",emptystring);
718 if(cca_load.size()==0)
719 cca_load = keyval->stringvalue("cca_load",emptystring);
720
721 if( !do_cca && (cca_load.size() > 0 || cca_path.size() > 0) )
722 do_cca = true;
723
724 if(cca_path.size()==0) {
725 #ifdef CCA_PATH
726 cca_path = CCA_PATH;
727 #endif
728 }
729 if(cca_load.size()==0) {
730 cca_load += "MPQC.IntegralEvaluatorFactory";
731 }
732
733 if( cca_load.size() > 0 && cca_path.size() > 0 && do_cca ) {
734 string cca_args = "--path " + cca_path + " --load " + cca_load;
735 ExEnv::out0() << endl << indent << "Initializing CCA framework with args: "
736 << endl << indent << cca_args << endl;
737 CCAEnv::init( cca_args );
738 }
739#endif
740}
741
742/** Setup debugger.
743 *
744 * \param keyval keyvalue container
745 * \param grp message group
746 * \param debugger debugger structure
747 * \param options parsed command line options
748 * \param argv argument array
749 */
750void setupDebugger(
751 Ref<KeyVal> &keyval,
752 Ref<MessageGrp> &grp,
753 Ref<Debugger> &debugger,
754 GetLongOpt &options,
755 char **argv)
756{
757 debugger << keyval->describedclassvalue("debug");
758 if (debugger.nonnull()) {
759 Debugger::set_default_debugger(debugger);
760 debugger->set_exec(argv[0]);
761 debugger->set_prefix(grp->me());
762 if (options.retrieve("d"))
763 debugger->debug("Starting debugger because -d given on command line.");
764 }
765}
766
767/** Get integral factory.
768 *
769 * \param keyval keyvalue container
770 * \param integral integral group on return
771 * \param argc argument count
772 * \param argv argument array
773 */
774void getIntegralFactory(
775 Ref<KeyVal> &keyval,
776 Ref<Integral> &integral,
777 int argc,
778 char **argv)
779{
780 // first try commandline and environment
781 integral = Integral::initial_integral(argc, argv);
782
783 // if we still don't have a integral, try reading the integral
784 // from the input
785 if (integral.null()) {
786 integral << keyval->describedclassvalue("integrals");
787 }
788
789 if (integral.nonnull())
790 Integral::set_default_integral(integral);
791 else
792 integral = Integral::get_default_integral();
793
794}
795
796void performRestart(
797 Ref<KeyVal> &keyval,
798 Ref<MessageGrp> &grp,
799 Ref<Optimize> &opt,
800 Ref<MolecularEnergy> &mole,
801 char *&restartfile
802 )
803{
804 int restart = keyval->booleanvalue("restart",truevalue);
805 struct stat sb;
806 int statresult, statsize;
807 if (restart) {
808 if (grp->me() == 0) {
809 statresult = stat(restartfile,&sb);
810 statsize = (statresult==0) ? sb.st_size : 0;
811 }
812 grp->bcast(statresult);
813 grp->bcast(statsize);
814 }
815 if (restart && statresult==0 && statsize) {
816 BcastStateInBin si(grp,restartfile);
817 if (keyval->exists("override")) {
818 si.set_override(new PrefixKeyVal(keyval,"override"));
819 }
820 char *suf = strrchr(restartfile,'.');
821 if (!strcmp(suf,".wfn")) {
822 mole << SavableState::key_restore_state(si,"mole");
823 ExEnv::out0() << endl
824 << indent << "Restored <" << mole->class_name()
825 << "> from " << restartfile << endl;
826
827 opt << keyval->describedclassvalue("opt");
828 if (opt.nonnull())
829 opt->set_function(mole.pointer());
830 }
831 else {
832 opt << SavableState::key_restore_state(si,"opt");
833 if (opt.nonnull()) {
834 mole << opt->function();
835 ExEnv::out0() << endl << indent
836 << "Restored <Optimize> from " << restartfile << endl;
837 }
838 }
839 } else {
840 mole << keyval->describedclassvalue("mole");
841 opt << keyval->describedclassvalue("opt");
842 }
843}
844
845char *setMolecularCheckpointFile(
846 Ref<KeyVal> &keyval,
847 Ref<MessageGrp> &grp,
848 Ref<MolecularEnergy> &mole,
849 char *mole_ckpt_file
850 )
851{
852 int checkpoint = keyval->booleanvalue("checkpoint",truevalue);
853 int checkpoint_freq = keyval->intvalue("checkpoint_freq",KeyValValueint(1));
854 if (mole.nonnull()) {
855 MolecularFormula mf(mole->molecule());
856 ExEnv::out0() << endl << indent
857 << "Molecular formula " << mf.formula() << endl;
858 if (checkpoint) {
859 mole->set_checkpoint();
860 if (grp->me() == 0) mole->set_checkpoint_file(mole_ckpt_file);
861 else mole->set_checkpoint_file(devnull);
862 mole->set_checkpoint_freq(checkpoint_freq);
863 }
864 }
865}
866
867/** Checks whether limit on command-line exceeds the basis functions.
868 *
869 * \param options parsed command-line options
870 * \param mole molecular energy object
871 * \return 0 - not exceeded, 1 - exceeded
872 */
873int checkBasisSetLimit(
874 GetLongOpt &options,
875 Ref<MolecularEnergy> &mole
876 )
877{
878 int check = (options.retrieve("c") != 0);
879 int limit = atoi(options.retrieve("l"));
880 if (limit) {
881 Ref<Wavefunction> wfn; wfn << mole;
882 if (wfn.nonnull() && wfn->ao_dimension()->n() > limit) {
883 ExEnv::out0() << endl << indent
884 << "The limit of " << limit << " basis functions has been exceeded."
885 << endl;
886 check = 1;
887 }
888 }
889 return check;
890}
891
892/** Performs the energy optimization.
893 *
894 * \param opt optimization object
895 * \param mole molecular energy object
896 * \return 0 - not read for frequency calculation, 1 - ready
897 */
898int performEnergyOptimization(
899 Ref<Optimize> &opt,
900 Ref<MolecularEnergy> &mole
901 )
902{
903 int ready_for_freq = 0;
904 int result = opt->optimize();
905 if (result) {
906 ExEnv::out0() << indent
907 << "The optimization has converged." << endl << endl;
908 ExEnv::out0() << indent
909 << scprintf("Value of the MolecularEnergy: %15.10f",
910 mole->energy())
911 << endl << endl;
912 ready_for_freq = 1;
913 } else {
914 ExEnv::out0() << indent
915 << "The optimization has NOT converged." << endl << endl;
916 ready_for_freq = 0;
917 }
918 return ready_for_freq;
919}
920
921/** Performs gradient calculation.
922 *
923 * \param mole molecular energy object
924 */
925void performGradientCalculation(
926 Ref<MolecularEnergy> &mole
927 )
928{
929 mole->do_gradient(1);
930 ExEnv::out0() << endl << indent
931 << scprintf("Value of the MolecularEnergy: %15.10f",
932 mole->energy())
933 << endl;
934 if (mole->value_result().actual_accuracy()
935 > mole->value_result().desired_accuracy()) {
936 ExEnv::out0() << indent
937 << "WARNING: desired accuracy not achieved in energy" << endl;
938 }
939 ExEnv::out0() << endl;
940 // Use result_noupdate since the energy might not have converged
941 // to the desired accuracy in which case grabbing the result will
942 // start up the calculation again. However the gradient might
943 // not have been computed (if we are restarting and the gradient
944 // isn't in the save file for example).
945 RefSCVector grad;
946 if (mole->gradient_result().computed()) {
947 grad = mole->gradient_result().result_noupdate();
948 }
949 else {
950 grad = mole->gradient();
951 }
952 if (grad.nonnull()) {
953 grad.print("Gradient of the MolecularEnergy:");
954 if (mole->gradient_result().actual_accuracy()
955 > mole->gradient_result().desired_accuracy()) {
956 ExEnv::out0() << indent
957 << "WARNING: desired accuracy not achieved in gradient" << endl;
958 }
959 }
960}
961
962int
963try_main(int argc, char *argv[])
964{
965 //trash_stack();
966
967 int i;
968 atexit(clean_up);
969
970#ifdef HAVE_FEENABLEEXCEPT
971 // this uses a glibc extension to trap on individual exceptions
972# ifdef FE_DIVBYZERO
973 feenableexcept(FE_DIVBYZERO);
974# endif
975# ifdef FE_INVALID
976 feenableexcept(FE_INVALID);
977# endif
978# ifdef FE_OVERFLOW
979 feenableexcept(FE_OVERFLOW);
980# endif
981#endif
982
983#ifdef HAVE_FEDISABLEEXCEPT
984 // this uses a glibc extension to not trap on individual exceptions
985# ifdef FE_UNDERFLOW
986 fedisableexcept(FE_UNDERFLOW);
987# endif
988# ifdef FE_INEXACT
989 fedisableexcept(FE_INEXACT);
990# endif
991#endif
992
993#if defined(HAVE_SETRLIMIT)
994 struct rlimit rlim;
995 rlim.rlim_cur = 0;
996 rlim.rlim_max = 0;
997 setrlimit(RLIMIT_CORE,&rlim);
998#endif
999
1000 ExEnv::init(argc, argv);
1001
1002 // parse commandline options
1003 GetLongOpt options;
1004 int optind = ParseOptions(options, argc, argv);
1005 const char *output = 0;
1006 ostream *outstream = 0;
1007 ComputeOptions(options, output, outstream);
1008
1009 // get the message group. first try the commandline and environment
1010 Ref<MessageGrp> grp;
1011 getMessageGroup(grp, argc, argv);
1012
1013 // get input file names, either object-oriented or generic
1014 const char *object_input = 0;
1015 const char *generic_input = 0;
1016 getInputFileNames(object_input, generic_input, options, argc, argv);
1017 const char *input;
1018 if (object_input) input = object_input;
1019 if (generic_input) input = generic_input;
1020
1021 // parse input into keyvalue container
1022 Ref<ParsedKeyVal> parsedkv;
1023 parseInputfile(grp, parsedkv, options, input, generic_input);
1024 if (options.retrieve("k")) parsedkv->verbose(1);
1025 Ref<KeyVal> keyval = new PrefixKeyVal(parsedkv.pointer(),"mpqc");
1026
1027 // get the basename for output files
1028 setOutputBaseName(input, output);
1029
1030 // set up output classes
1031 setupSCFormIO(grp);
1032
1033 // initialize timing for mpqc
1034 Ref<RegionTimer> tim;
1035 initTimings(grp, keyval, tim);
1036
1037 // announce ourselves
1038 makeAnnouncement(tim);
1039
1040 // get the thread group.
1041 Ref<ThreadGrp> thread;
1042 getThreadGroup(keyval, thread, argc, argv);
1043
1044 // get the memory group.
1045 Ref<MemoryGrp> memory;
1046 getMemoryGroup(keyval, memory, argc, argv);
1047
1048 ExEnv::out0() << indent
1049 << "Using " << grp->class_name()
1050 << " for message passing (number of nodes = " << grp->n() << ")." << endl
1051 << indent
1052 << "Using " << thread->class_name()
1053 << " for threading (number of threads = " << thread->nthread() << ")." << endl
1054 << indent
1055 << "Using " << memory->class_name()
1056 << " for distributed shared memory." << endl
1057 << indent
1058 << "Total number of processors = " << grp->n() * thread->nthread() << endl;
1059
1060 // prepare CCA if available
1061 prepareCCA(keyval, options);
1062
1063 // now set up the debugger
1064 Ref<Debugger> debugger;
1065 setupDebugger(keyval, grp, debugger, options, argv);
1066
1067 // now check to see what matrix kit to use
1068 if (keyval->exists("matrixkit"))
1069 SCMatrixKit::set_default_matrixkit(
1070 dynamic_cast<SCMatrixKit*>(
1071 keyval->describedclassvalue("matrixkit").pointer()));
1072
1073 // get the integral factory.
1074 Ref<Integral> integral;
1075 getIntegralFactory(keyval, integral, argc, argv);
1076 ExEnv::out0() << endl << indent
1077 << "Using " << integral->class_name()
1078 << " by default for molecular integrals evaluation" << endl << endl;
1079
1080 // create some filenames for molecule, checkpoint, basename of output
1081 const char *basename = SCFormIO::default_basename();
1082 KeyValValueString molnamedef(basename);
1083 char * molname = keyval->pcharvalue("filename", molnamedef);
1084 if (strcmp(molname, basename))
1085 SCFormIO::set_default_basename(molname);
1086
1087 char * ckptfile = new char[strlen(molname)+6];
1088 sprintf(ckptfile,"%s.ckpt",molname);
1089
1090 KeyValValueString restartfiledef(ckptfile);
1091 char * restartfile = keyval->pcharvalue("restart_file", restartfiledef);
1092
1093 char * wfn_file = keyval->pcharvalue("wfn_file");
1094 if (wfn_file == 0) {
1095 wfn_file = new char[strlen(molname)+6];
1096 sprintf(wfn_file,"%s.wfn",molname);
1097 }
1098 char *mole_ckpt_file = new char[strlen(wfn_file)+1];
1099 sprintf(mole_ckpt_file,"%s",wfn_file);
1100
1101 int savestate = keyval->booleanvalue("savestate",truevalue);
1102
1103 // setup molecular energy and optimization instances
1104 Ref<MolecularEnergy> mole;
1105 Ref<Optimize> opt;
1106
1107 // read in restart file if we do restart
1108 performRestart(keyval, grp, opt, mole, restartfile);
1109
1110 // setup molecule checkpoint file
1111 setMolecularCheckpointFile(keyval, grp, mole, mole_ckpt_file);
1112 delete[] mole_ckpt_file;
1113
1114 int checkpoint = keyval->booleanvalue("checkpoint",truevalue);
1115 if (checkpoint && opt.nonnull()) {
1116 opt->set_checkpoint();
1117 if (grp->me() == 0) opt->set_checkpoint_file(ckptfile);
1118 else opt->set_checkpoint_file(devnull);
1119 }
1120
1121 // see if frequencies are wanted
1122 Ref<MolecularHessian> molhess;
1123 molhess << keyval->describedclassvalue("hess");
1124 Ref<MolecularFrequencies> molfreq;
1125 molfreq << keyval->describedclassvalue("freq");
1126
1127 // check basis set limit
1128 const int check = checkBasisSetLimit(options, mole);
1129 if (check) {
1130 ExEnv::out0() << endl << indent
1131 << "Exiting since the check option is on." << endl;
1132 exit(0);
1133 }
1134
1135 // from now on we time the calculations
1136 if (tim.nonnull()) tim->change("calc");
1137
1138 int do_energy = keyval->booleanvalue("do_energy",truevalue);
1139
1140 int do_grad = keyval->booleanvalue("do_gradient",falsevalue);
1141
1142 int do_opt = keyval->booleanvalue("optimize",truevalue);
1143
1144 int do_pdb = keyval->booleanvalue("write_pdb",falsevalue);
1145
1146 int print_mole = keyval->booleanvalue("print_mole",truevalue);
1147
1148 int print_timings = keyval->booleanvalue("print_timings",truevalue);
1149
1150 // print all current options (keyvalues)
1151 printOptions(keyval, opt, molname, restartfile);
1152
1153 // see if any pictures are desired
1154 Ref<Render> renderer;
1155 renderer << keyval->describedclassvalue("renderer");
1156
1157 // If we have a renderer, then we will read in some more info
1158 // below. Otherwise we can get rid of the keyval's, to eliminate
1159 // superfluous references to objects that we might otherwise be
1160 // able to delete. We cannot read in the remaining rendering
1161 // objects now, since some of their KeyVal CTOR's are heavyweight,
1162 // requiring optimized geometries, etc.
1163 if (renderer.null()) {
1164 if (parsedkv.nonnull()) print_unseen(parsedkv, input);
1165 keyval = 0;
1166 parsedkv = 0;
1167 }
1168
1169 delete[] restartfile;
1170 delete[] ckptfile;
1171
1172 int ready_for_freq = 1;
1173 if (mole.nonnull()) {
1174 if (((do_opt && opt.nonnull()) || do_grad)
1175 && !mole->gradient_implemented()) {
1176 ExEnv::out0() << indent
1177 << "WARNING: optimization or gradient requested but the given"
1178 << endl
1179 << " MolecularEnergy object cannot do gradients."
1180 << endl;
1181 }
1182
1183 if (do_opt && opt.nonnull() && mole->gradient_implemented()) {
1184
1185 ready_for_freq = performEnergyOptimization(opt, mole);
1186
1187 } else if (do_grad && mole->gradient_implemented()) {
1188
1189 performGradientCalculation(mole);
1190
1191 } else if (do_energy && mole->value_implemented()) {
1192 ExEnv::out0() << endl << indent
1193 << scprintf("Value of the MolecularEnergy: %15.10f",
1194 mole->energy())
1195 << endl << endl;
1196 }
1197 }
1198
1199 // stop timing of calculations
1200 if (tim.nonnull()) tim->exit("calc");
1201
1202 // save this before doing the frequency stuff since that obsoletes the
1203 saveState(wfn_file, savestate, opt, grp, mole, molname, ckptfile);
1204
1205 // Frequency calculation.
1206 if (ready_for_freq && molfreq.nonnull()) {
1207 RefSymmSCMatrix xhessian;
1208 if (molhess.nonnull()) {
1209 // if "hess" input was given, use it to compute the hessian
1210 xhessian = molhess->cartesian_hessian();
1211 }
1212 else if (mole->hessian_implemented()) {
1213 // if mole can compute the hessian, use that hessian
1214 xhessian = mole->get_cartesian_hessian();
1215 }
1216 else if (mole->gradient_implemented()) {
1217 // if mole can compute gradients, use gradients at finite
1218 // displacements to compute the hessian
1219 molhess = new FinDispMolecularHessian(mole);
1220 xhessian = molhess->cartesian_hessian();
1221 }
1222 else {
1223 ExEnv::out0() << "mpqc: WARNING: Frequencies cannot be computed" << endl;
1224 }
1225
1226 if (xhessian.nonnull()) {
1227 char *hessfile = SCFormIO::fileext_to_filename(".hess");
1228 MolecularHessian::write_cartesian_hessian(hessfile,
1229 mole->molecule(), xhessian);
1230 delete[] hessfile;
1231
1232 molfreq->compute_frequencies(xhessian);
1233 // DEGENERACY IS NOT CORRECT FOR NON-SINGLET CASES:
1234 molfreq->thermochemistry(1);
1235 }
1236 }
1237
1238 if (renderer.nonnull()) {
1239 Ref<RenderedObject> rendered;
1240 rendered << keyval->describedclassvalue("rendered");
1241 Ref<AnimatedObject> animated;
1242 animated << keyval->describedclassvalue("rendered");
1243 if (rendered.nonnull()) {
1244 if (tim.nonnull()) tim->enter("render");
1245 if (grp->me() == 0) renderer->render(rendered);
1246 if (tim.nonnull()) tim->exit("render");
1247 }
1248 else if (animated.nonnull()) {
1249 if (tim.nonnull()) tim->enter("render");
1250 if (grp->me() == 0) renderer->animate(animated);
1251 if (tim.nonnull()) tim->exit("render");
1252 }
1253 else {
1254 if (tim.nonnull()) tim->enter("render");
1255 int n = keyval->count("rendered");
1256 for (i=0; i<n; i++) {
1257 rendered << keyval->describedclassvalue("rendered",i);
1258 animated << keyval->describedclassvalue("rendered",i);
1259 if (rendered.nonnull()) {
1260 // make sure the object has a name so we don't overwrite its file
1261 if (rendered->name() == 0) {
1262 char ic[64];
1263 sprintf(ic,"%02d",i);
1264 rendered->set_name(ic);
1265 }
1266 if (grp->me() == 0) renderer->render(rendered);
1267 }
1268 else if (animated.nonnull()) {
1269 // make sure the object has a name so we don't overwrite its file
1270 if (animated->name() == 0) {
1271 char ic[64];
1272 sprintf(ic,"%02d",i);
1273 animated->set_name(ic);
1274 }
1275 if (grp->me() == 0) renderer->animate(animated);
1276 }
1277 }
1278 if (tim.nonnull()) tim->exit("render");
1279 }
1280 Ref<MolFreqAnimate> molfreqanim;
1281 molfreqanim << keyval->describedclassvalue("animate_modes");
1282 if (ready_for_freq && molfreq.nonnull()
1283 && molfreqanim.nonnull()) {
1284 if (tim.nonnull()) tim->enter("render");
1285 molfreq->animate(renderer, molfreqanim);
1286 if (tim.nonnull()) tim->exit("render");
1287 }
1288 }
1289
1290 if (mole.nonnull()) {
1291 if (print_mole)
1292 mole->print(ExEnv::out0());
1293
1294 if (do_pdb && grp->me() == 0) {
1295 ckptfile = new char[strlen(molname)+5];
1296 sprintf(ckptfile, "%s.pdb", molname);
1297 ofstream pdbfile(ckptfile);
1298 mole->molecule()->print_pdb(pdbfile);
1299 delete[] ckptfile;
1300 }
1301
1302 }
1303 else {
1304 ExEnv::out0() << "mpqc: The molecular energy object is null" << endl
1305 << " make sure \"mole\" specifies a MolecularEnergy derivative"
1306 << endl;
1307 }
1308 if (parsedkv.nonnull()) print_unseen(parsedkv, input);
1309
1310 if (print_timings)
1311 if (tim.nonnull()) tim->print(ExEnv::out0());
1312
1313 // here, we may gather the results
1314 // we start to construct the MPQC_Data object
1315 {
1316 Ref<Wavefunction> wfn;
1317 wfn << mole;
1318 ExEnv::out0() << "The number of atomic orbitals: " << wfn->ao_dimension()->n() << endl;
1319 ExEnv::out0() << "The AO density matrix is ";
1320 wfn->ao_density()->print(ExEnv::out0());
1321 ExEnv::out0() << "The natural density matrix is ";
1322 wfn->natural_density()->print(ExEnv::out0());
1323 ExEnv::out0() << "The Gaussian basis is " << wfn->basis()->name() << endl;
1324 ExEnv::out0() << "The Gaussians sit at the following centers: " << endl;
1325 for (int nr = 0; nr< wfn->basis()->ncenter(); ++nr) {
1326 ExEnv::out0() << nr << " basis function has its center at ";
1327 for (int i=0; i < 3; ++i)
1328 ExEnv::out0() << wfn->basis()->r(nr,i) << "\t";
1329 ExEnv::out0() << endl;
1330 }
1331 // GaussianShell is the actual orbital functions it seems ...
1332 //ExEnv::out0() << "There are the following Gaussian Shells: " << endl;
1333 SCVector3 r;
1334 r.x() = r.y() = r.z() = 10;
1335 ExEnv::out0() << "We get the following value at " << r << "." << endl;
1336 Ref<Integral> intgrl = Integral::get_default_integral();
1337 GaussianBasisSet::ValueData vdat(wfn->basis(), integral);
1338 ExEnv::out0() << "Value at (10,10,10) is " << EvaluateDensity(r, intgrl, vdat, wfn) << endl;
1339 boost::function<double (SCVector3 &r)> evaluator =
1340 boost::bind(&EvaluateDensity, _1, boost::ref(intgrl), boost::ref(vdat), boost::ref(wfn));
1341 ExEnv::out0() << "Check against values at " << r << "." << endl;
1342 int nbasis = wfn->basis()->nbasis();
1343 double *b_val = new double[nbasis];
1344 wfn->basis()->values(r, &vdat, b_val);
1345 for (int i=0; i<nbasis; i++) {
1346 //ExEnv::out0() << "Shell nr. " << nr << ": ";
1347 ExEnv::out0() << "Value at (10,10,10) is " << b_val[i] << endl;
1348 }
1349 // perform test integration of density
1350 double delta = 1.;
1351 double sum = 0.;
1352 for (r.x() = -10. ; r.x() < 10.; r.x() += delta)
1353 for (r.y() = -10. ; r.y() < 10.; r.y() += delta)
1354 for (r.z() = -10. ; r.z() < 10.; r.z() += delta) {
1355 wfn->basis()->values(r, &vdat, b_val);
1356 for (int i=0; i<nbasis; i++)
1357 sum += wfn->ao_density()->get_element(i,i)*b_val[i];
1358 }
1359 sum /= pow(20/delta,3);
1360 ExEnv::out0() << "Sum over domain [0:20]^3 with " << delta << " delta is " << sum << "." << endl;
1361 delete[] b_val;
1362 }
1363
1364 delete[] molname;
1365 SCFormIO::set_default_basename(0);
1366
1367 renderer = 0;
1368 molfreq = 0;
1369 molhess = 0;
1370 opt = 0;
1371 mole = 0;
1372 integral = 0;
1373 debugger = 0;
1374 thread = 0;
1375 tim = 0;
1376 keyval = 0;
1377 parsedkv = 0;
1378 grp = 0;
1379 memory = 0;
1380 clean_up();
1381
1382#if defined(HAVE_TIME) && defined(HAVE_CTIME)
1383 time_t t;
1384 time(&t);
1385 const char *tstr = ctime(&t);
1386#endif
1387 if (!tstr) {
1388 tstr = "UNKNOWN";
1389 }
1390 ExEnv::out0() << endl
1391 << indent << scprintf("End Time: %s", tstr) << endl;
1392
1393 if (output != 0) {
1394 ExEnv::set_out(&cout);
1395 delete outstream;
1396 }
1397
1398 return 0;
1399}
1400
1401double EvaluateDensity(SCVector3 &r, Ref<Integral> &intgrl, GaussianBasisSet::ValueData &vdat, Ref<Wavefunction> &wfn)
1402{
1403 ExEnv::out0() << "We get the following values at " << r << "." << endl;
1404 int nbasis = wfn->basis()->nbasis();
1405 double *b_val = new double[nbasis];
1406 wfn->basis()->values(r, &vdat, b_val);
1407 double sum=0.;
1408 for (int i=0; i<nbasis; i++)
1409 sum += b_val[i];
1410 delete[] b_val;
1411 return sum;
1412}
1413
1414int
1415main(int argc, char *argv[])
1416{
1417 try {
1418 try_main(argc, argv);
1419 }
1420 catch (SCException &e) {
1421 cout << argv[0] << ": ERROR: SC EXCEPTION RAISED:" << endl
1422 << e.what()
1423 << endl;
1424 clean_up();
1425 throw;
1426 }
1427 catch (bad_alloc &e) {
1428 cout << argv[0] << ": ERROR: MEMORY ALLOCATION FAILED:" << endl
1429 << e.what()
1430 << endl;
1431 clean_up();
1432 throw;
1433 }
1434 catch (exception &e) {
1435 cout << argv[0] << ": ERROR: EXCEPTION RAISED:" << endl
1436 << e.what()
1437 << endl;
1438 clean_up();
1439 throw;
1440 }
1441 catch (...) {
1442 cout << argv[0] << ": ERROR: UNKNOWN EXCEPTION RAISED" << endl;
1443 clean_up();
1444 throw;
1445 }
1446 return 0;
1447}
1448
1449/////////////////////////////////////////////////////////////////////////////
1450
1451// Local Variables:
1452// mode: c++
1453// c-file-style: "ETS"
1454// End:
Note: See TracBrowser for help on using the repository browser.