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

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

Placed const char devnull as global const.

  • Property mode set to 100644
File size: 39.5 KB
RevLine 
[5d30c1]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
[62dabe]51#include <boost/bind.hpp>
52#include <boost/function.hpp>
53
[5d30c1]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
[a8458d]132const KeyValValueboolean truevalue(1), falsevalue(0);
[dca43b]133const char *devnull = "/dev/null";
[a8458d]134
135
[5d30c1]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
[62dabe]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 */
[36d8ab]200int ParseOptions(
201 GetLongOpt &options,
202 int argc,
203 char **argv)
[5d30c1]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);
[31c708]210 options.enroll("n", GetLongOpt::NoValue,
211 "listen for incoming object format input files", 0);
[5d30c1]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);
[62dabe]231 options.enroll("cca-path", GetLongOpt::OptionalValue,
[5d30c1]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
[62dabe]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 */
[36d8ab]247void ComputeOptions(
248 GetLongOpt &options,
249 const char *&output,
250 ostream *&outstream)
[62dabe]251{
252 output = options.retrieve("o");
253 outstream = 0;
[5d30c1]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 }
[62dabe]267
[5d30c1]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 }
[62dabe]275
[5d30c1]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 }
[62dabe]284
[5d30c1]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
[8860a6]294 if (options.retrieve("d"))
295 SCFormIO::set_debug(1);
296
[5d30c1]297 // set the working dir
298 if (strcmp(options.retrieve("W"),"."))
[62dabe]299 int retval = chdir(options.retrieve("W"));
[5d30c1]300
[31c708]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 }
[62dabe]305}
306
[36d8ab]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
[aa42a9]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 */
[36d8ab]351void getMessageGroup(
352 Ref<MessageGrp> &grp,
353 int argc,
354 char **argv)
[aa42a9]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
[203fe4]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
[d39b2b]384/** Prints current key values.
385 *
386 * \param keyval key value structure
387 * \param opt optimization structure
388 * \param molname name of molecule
[a98b86]389 * \param restartfile name of restartfile
[d39b2b]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
[a98b86]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 const char *devnull = "/dev/null";
456
457 // function stuff
458 if (savestate) {
459 if (opt.nonnull()) {
460 if (grp->me() == 0) {
461 ckptfile = new char[strlen(molname)+6];
462 sprintf(ckptfile,"%s.ckpt",molname);
463 }
464 else {
465 ckptfile = new char[strlen(devnull)+1];
466 strcpy(ckptfile, devnull);
467 }
468
469 StateOutBin so(ckptfile);
470 SavableState::save_state(opt.pointer(),so);
471 so.close();
472
473 delete[] ckptfile;
474 }
475
476 if (mole.nonnull()) {
477 if (grp->me() == 0) {
478 if (wfn_file == 0) {
479 wfn_file = new char[strlen(molname)+6];
480 sprintf(wfn_file,"%s.wfn",molname);
481 }
482 }
483 else {
484 delete[] wfn_file;
485 wfn_file = new char[strlen(devnull)+1];
486 strcpy(wfn_file, devnull);
487 }
488
489 StateOutBin so(wfn_file);
490 SavableState::save_state(mole.pointer(),so);
491 so.close();
492
493 }
494 }
495 delete[] wfn_file;
496}
497
[8860a6]498/** Sets up indentation and output modes.
499 *
500 * \param grp message group
501 */
502void setupSCFormIO(
503 Ref<MessageGrp> &grp
504 )
505{
506 SCFormIO::setindent(ExEnv::outn(), 2);
507 SCFormIO::setindent(ExEnv::errn(), 2);
508 SCFormIO::setindent(cout, 2);
509 SCFormIO::setindent(cerr, 2);
510
511 SCFormIO::set_printnode(0);
512 if (grp->n() > 1)
513 SCFormIO::init_mp(grp->me());
514}
515
[c676ca]516/** Initialises the timer.
517 *
518 * \param grp message group
519 * \param keyval key value structure
520 * \param tim timing structure
521 */
522void initTimings(
523 Ref<MessageGrp> &grp,
524 Ref<KeyVal> &keyval,
525 Ref<RegionTimer> &tim
526 )
527{
528 grp->sync(); // make sure nodes are sync'ed before starting timings
529 if (keyval->exists("timer")) tim << keyval->describedclassvalue("timer");
530 else tim = new ParallelRegionTimer(grp,"mpqc",1,1);
531 RegionTimer::set_default_regiontimer(tim);
532
533 if (tim.nonnull()) tim->enter("input");
534}
535
[3d4397]536/** Prints the header of the output.
537 *
538 * \param tim timing structure
539 */
540void makeAnnouncement(
541 Ref<RegionTimer> &tim
542 )
543{
544 const char title1[] = "MPQC: Massively Parallel Quantum Chemistry";
545 int ntitle1 = sizeof(title1);
546 const char title2[] = "Version " SC_VERSION;
547 int ntitle2 = sizeof(title2);
548 ExEnv::out0() << endl;
549 ExEnv::out0() << indent;
550 for (int i=0; i<(80-ntitle1)/2; i++) ExEnv::out0() << ' ';
551 ExEnv::out0() << title1 << endl;
552 ExEnv::out0() << indent;
553 for (int i=0; i<(80-ntitle2)/2; i++) ExEnv::out0() << ' ';
554 ExEnv::out0() << title2 << endl << endl;
555
556 const char *tstr = 0;
557#if defined(HAVE_TIME) && defined(HAVE_CTIME)
558 time_t t;
559 time(&t);
560 tstr = ctime(&t);
561#endif
562 if (!tstr) {
563 tstr = "UNKNOWN";
564 }
565
566 ExEnv::out0()
567 << indent << scprintf("Machine: %s", TARGET_ARCH) << endl
568 << indent << scprintf("User: %s@%s",
569 ExEnv::username(), ExEnv::hostname()) << endl
570 << indent << scprintf("Start Time: %s", tstr) << endl;
571}
572
[41f82c]573/** Parse the input file into the key value container.
574 *
575 * \param grp message group
[3cb97b]576 * \param parsedkev keyvalue container on return
[41f82c]577 * \param options options structure
578 * \param input input file name
579 * \param generic_input filename of generic input
580 */
581void parseInputfile(
582 Ref<MessageGrp> &grp,
583 Ref<ParsedKeyVal> &parsedkv,
584 GetLongOpt &options,
585 const char *&input,
586 const char *&generic_input
587 )
588{
589 // read the input file on only node 0
590 char *in_char_array;
591 if (grp->me() == 0) {
592 ifstream is(input);
593#ifdef HAVE_SSTREAM
594 ostringstream ostrs;
595 is >> ostrs.rdbuf();
596 int n = 1 + strlen(ostrs.str().c_str());
597 in_char_array = strcpy(new char[n],ostrs.str().c_str());
598#else
599 ostrstream ostrs;
600 is >> ostrs.rdbuf();
601 ostrs << ends;
602 in_char_array = ostrs.str();
603 int n = ostrs.pcount();
604#endif
605 grp->bcast(n);
606 grp->bcast(in_char_array, n);
607 }
608 else {
609 int n;
610 grp->bcast(n);
611 in_char_array = new char[n];
612 grp->bcast(in_char_array, n);
613 }
614
615 int use_simple_input;
616 if (generic_input && grp->me() == 0) {
617 MPQCIn mpqcin;
618 use_simple_input = mpqcin.check_string(in_char_array);
619 }
620 else {
621 use_simple_input = 0;
622 }
623 grp->bcast(use_simple_input);
624
625 if (use_simple_input) {
626 MPQCIn mpqcin;
627 char *simple_input_text = mpqcin.parse_string(in_char_array);
628 if (options.retrieve("i")) {
629 ExEnv::out0() << "Generated object-oriented input file:" << endl
630 << simple_input_text
631 << endl;
632 exit(0);
633 }
634 parsedkv = new ParsedKeyVal();
635 parsedkv->parse_string(simple_input_text);
636 delete[] simple_input_text;
637 }
638 else {
639 parsedkv = new ParsedKeyVal();
640 parsedkv->parse_string(in_char_array);
641 }
642 delete[] in_char_array;
643}
644
[3cb97b]645/** Get the thread group.
646 *
647 * \param keyval keyvalue container
648 * \param thread thread group on return
649 * \param argc argument count
650 * \param argv argument array
651 */
652void getThreadGroup(
653 Ref<KeyVal> &keyval,
654 Ref<ThreadGrp> &thread,
655 int argc,
656 char **argv)
657{
658 //first try the commandline and environment
659 thread = ThreadGrp::initial_threadgrp(argc, argv);
660
661 // if we still don't have a group, try reading the thread group
662 // from the input
663 if (thread.null()) {
664 thread << keyval->describedclassvalue("thread");
665 }
666
667 if (thread.nonnull())
668 ThreadGrp::set_default_threadgrp(thread);
669 else
670 thread = ThreadGrp::get_default_threadgrp();
671}
672
[7ed4e8]673/** Get the memory group.
674 *
675 * \param keyval keyvalue container
676 * \param memory memory group on return
677 * \param argc argument count
678 * \param argv argument array
679 */
680void getMemoryGroup(
681 Ref<KeyVal> &keyval,
682 Ref<MemoryGrp> &memory,
683 int argc,
684 char **argv)
685{
686 // first try the commandline and environment
687 memory = MemoryGrp::initial_memorygrp(argc, argv);
688
689 // if we still don't have a group, try reading the memory group
690 // from the input
691 if (memory.null()) {
692 memory << keyval->describedclassvalue("memory");
693 }
694
695 if (memory.nonnull())
696 MemoryGrp::set_default_memorygrp(memory);
697 else
698 memory = MemoryGrp::get_default_memorygrp();
699}
700
[09bc09]701/** Prepares CCA component if available.
702 *
703 * \param keyval keyvalue container
704 * \param options parsed command line options
705 */
706void prepareCCA(
707 Ref<KeyVal> &keyval,
708 GetLongOpt &options
709 )
710{
711#ifdef HAVE_CHEMISTRY_CCA
712 // initialize cca framework
713 KeyValValuestring emptystring("");
714 bool do_cca = keyval->booleanvalue("do_cca",falsevalue);
715
716 string cca_path(options.retrieve("cca-path"));
717 string cca_load(options.retrieve("cca-load"));
718 if(cca_path.size()==0)
719 cca_path = keyval->stringvalue("cca_path",emptystring);
720 if(cca_load.size()==0)
721 cca_load = keyval->stringvalue("cca_load",emptystring);
722
723 if( !do_cca && (cca_load.size() > 0 || cca_path.size() > 0) )
724 do_cca = true;
725
726 if(cca_path.size()==0) {
727 #ifdef CCA_PATH
728 cca_path = CCA_PATH;
729 #endif
730 }
731 if(cca_load.size()==0) {
732 cca_load += "MPQC.IntegralEvaluatorFactory";
733 }
734
735 if( cca_load.size() > 0 && cca_path.size() > 0 && do_cca ) {
736 string cca_args = "--path " + cca_path + " --load " + cca_load;
737 ExEnv::out0() << endl << indent << "Initializing CCA framework with args: "
738 << endl << indent << cca_args << endl;
739 CCAEnv::init( cca_args );
740 }
741#endif
742}
743
[f5403d]744/** Setup debugger.
745 *
746 * \param keyval keyvalue container
747 * \param grp message group
748 * \param debugger debugger structure
749 * \param options parsed command line options
750 * \param argv argument array
751 */
752void setupDebugger(
753 Ref<KeyVal> &keyval,
754 Ref<MessageGrp> &grp,
755 Ref<Debugger> &debugger,
756 GetLongOpt &options,
757 char **argv)
758{
759 debugger << keyval->describedclassvalue("debug");
760 if (debugger.nonnull()) {
761 Debugger::set_default_debugger(debugger);
762 debugger->set_exec(argv[0]);
763 debugger->set_prefix(grp->me());
764 if (options.retrieve("d"))
765 debugger->debug("Starting debugger because -d given on command line.");
766 }
767}
768
[09bc09]769/** Get integral factory.
770 *
771 * \param keyval keyvalue container
772 * \param integral integral group on return
773 * \param argc argument count
774 * \param argv argument array
775 */
776void getIntegralFactory(
777 Ref<KeyVal> &keyval,
778 Ref<Integral> &integral,
779 int argc,
780 char **argv)
781{
782 // first try commandline and environment
783 integral = Integral::initial_integral(argc, argv);
784
785 // if we still don't have a integral, try reading the integral
786 // from the input
787 if (integral.null()) {
788 integral << keyval->describedclassvalue("integrals");
789 }
790
791 if (integral.nonnull())
792 Integral::set_default_integral(integral);
793 else
794 integral = Integral::get_default_integral();
795
796}
797
[666f70]798void performRestart(
799 Ref<KeyVal> &keyval,
800 Ref<MessageGrp> &grp,
801 Ref<Optimize> &opt,
802 Ref<MolecularEnergy> &mole,
803 char *&restartfile
804 )
805{
806 int restart = keyval->booleanvalue("restart",truevalue);
807 struct stat sb;
808 int statresult, statsize;
809 if (restart) {
810 if (grp->me() == 0) {
811 statresult = stat(restartfile,&sb);
812 statsize = (statresult==0) ? sb.st_size : 0;
813 }
814 grp->bcast(statresult);
815 grp->bcast(statsize);
816 }
817 if (restart && statresult==0 && statsize) {
818 BcastStateInBin si(grp,restartfile);
819 if (keyval->exists("override")) {
820 si.set_override(new PrefixKeyVal(keyval,"override"));
821 }
822 char *suf = strrchr(restartfile,'.');
823 if (!strcmp(suf,".wfn")) {
824 mole << SavableState::key_restore_state(si,"mole");
825 ExEnv::out0() << endl
826 << indent << "Restored <" << mole->class_name()
827 << "> from " << restartfile << endl;
828
829 opt << keyval->describedclassvalue("opt");
830 if (opt.nonnull())
831 opt->set_function(mole.pointer());
832 }
833 else {
834 opt << SavableState::key_restore_state(si,"opt");
835 if (opt.nonnull()) {
836 mole << opt->function();
837 ExEnv::out0() << endl << indent
838 << "Restored <Optimize> from " << restartfile << endl;
839 }
840 }
841 } else {
842 mole << keyval->describedclassvalue("mole");
843 opt << keyval->describedclassvalue("opt");
844 }
845}
846
847
[62dabe]848int
849try_main(int argc, char *argv[])
850{
851 //trash_stack();
852
853 int i;
854 atexit(clean_up);
855
856#ifdef HAVE_FEENABLEEXCEPT
857 // this uses a glibc extension to trap on individual exceptions
858# ifdef FE_DIVBYZERO
859 feenableexcept(FE_DIVBYZERO);
860# endif
861# ifdef FE_INVALID
862 feenableexcept(FE_INVALID);
863# endif
864# ifdef FE_OVERFLOW
865 feenableexcept(FE_OVERFLOW);
866# endif
867#endif
868
869#ifdef HAVE_FEDISABLEEXCEPT
870 // this uses a glibc extension to not trap on individual exceptions
871# ifdef FE_UNDERFLOW
872 fedisableexcept(FE_UNDERFLOW);
873# endif
874# ifdef FE_INEXACT
875 fedisableexcept(FE_INEXACT);
876# endif
877#endif
878
879#if defined(HAVE_SETRLIMIT)
880 struct rlimit rlim;
881 rlim.rlim_cur = 0;
882 rlim.rlim_max = 0;
883 setrlimit(RLIMIT_CORE,&rlim);
884#endif
885
886 ExEnv::init(argc, argv);
887
888 // parse commandline options
889 GetLongOpt options;
890 int optind = ParseOptions(options, argc, argv);
891 const char *output = 0;
892 ostream *outstream = 0;
893 ComputeOptions(options, output, outstream);
[31c708]894
[5d30c1]895 // get the message group. first try the commandline and environment
[62dabe]896 Ref<MessageGrp> grp;
[aa42a9]897 getMessageGroup(grp, argc, argv);
[5d30c1]898
[36d8ab]899 // get input file names, either object-oriented or generic
900 const char *object_input = 0;
901 const char *generic_input = 0;
902 getInputFileNames(object_input, generic_input, options, argc, argv);
[5d30c1]903 const char *input;
904 if (object_input) input = object_input;
905 if (generic_input) input = generic_input;
906
[41f82c]907 // parse input into keyvalue container
[5d30c1]908 Ref<ParsedKeyVal> parsedkv;
[41f82c]909 parseInputfile(grp, parsedkv, options, input, generic_input);
[5d30c1]910 if (options.retrieve("k")) parsedkv->verbose(1);
911 Ref<KeyVal> keyval = new PrefixKeyVal(parsedkv.pointer(),"mpqc");
912
913 // get the basename for output files
[203fe4]914 setOutputBaseName(input, output);
[5d30c1]915
916 // set up output classes
[8860a6]917 setupSCFormIO(grp);
[5d30c1]918
919 // initialize timing for mpqc
920 Ref<RegionTimer> tim;
[c676ca]921 initTimings(grp, keyval, tim);
[5d30c1]922
923 // announce ourselves
[3d4397]924 makeAnnouncement(tim);
[5d30c1]925
[3cb97b]926 // get the thread group.
927 Ref<ThreadGrp> thread;
928 getThreadGroup(keyval, thread, argc, argv);
[5d30c1]929
[7ed4e8]930 // get the memory group.
931 Ref<MemoryGrp> memory;
932 getMemoryGroup(keyval, memory, argc, argv);
[5d30c1]933
934 ExEnv::out0() << indent
935 << "Using " << grp->class_name()
936 << " for message passing (number of nodes = " << grp->n() << ")." << endl
937 << indent
938 << "Using " << thread->class_name()
939 << " for threading (number of threads = " << thread->nthread() << ")." << endl
940 << indent
941 << "Using " << memory->class_name()
942 << " for distributed shared memory." << endl
943 << indent
944 << "Total number of processors = " << grp->n() * thread->nthread() << endl;
945
[666f70]946 // prepare CCA if available
[09bc09]947 prepareCCA(keyval, options);
[5d30c1]948
949 // now set up the debugger
[f5403d]950 Ref<Debugger> debugger;
951 setupDebugger(keyval, grp, debugger, options, argv);
[5d30c1]952
953 // now check to see what matrix kit to use
954 if (keyval->exists("matrixkit"))
955 SCMatrixKit::set_default_matrixkit(
956 dynamic_cast<SCMatrixKit*>(
957 keyval->describedclassvalue("matrixkit").pointer()));
958
[09bc09]959 // get the integral factory.
960 Ref<Integral> integral;
961 getIntegralFactory(keyval, integral, argc, argv);
[5d30c1]962 ExEnv::out0() << endl << indent
963 << "Using " << integral->class_name()
964 << " by default for molecular integrals evaluation" << endl << endl;
965
966 // check for a molecular energy and optimizer
[203fe4]967 const char *basename = SCFormIO::default_basename();
[5d30c1]968 KeyValValueString molnamedef(basename);
969 char * molname = keyval->pcharvalue("filename", molnamedef);
970 if (strcmp(molname, basename))
971 SCFormIO::set_default_basename(molname);
972
973 char * ckptfile = new char[strlen(molname)+6];
974 sprintf(ckptfile,"%s.ckpt",molname);
975
976 KeyValValueString restartfiledef(ckptfile);
977 char * restartfile = keyval->pcharvalue("restart_file", restartfiledef);
978
979 char * wfn_file = keyval->pcharvalue("wfn_file");
980 if (wfn_file == 0) {
981 wfn_file = new char[strlen(molname)+6];
982 sprintf(wfn_file,"%s.wfn",molname);
983 }
984 char *mole_ckpt_file = new char[strlen(wfn_file)+1];
985 sprintf(mole_ckpt_file,"%s",wfn_file);
986
987 int restart = keyval->booleanvalue("restart",truevalue);
988
989 int checkpoint = keyval->booleanvalue("checkpoint",truevalue);
990 int checkpoint_freq = keyval->intvalue("checkpoint_freq",KeyValValueint(1));
991
992 int savestate = keyval->booleanvalue("savestate",truevalue);
993
994 Ref<MolecularEnergy> mole;
995 Ref<Optimize> opt;
996
[666f70]997 performRestart(keyval, grp, opt, mole, restartfile);
[5d30c1]998
999 if (mole.nonnull()) {
1000 MolecularFormula mf(mole->molecule());
1001 ExEnv::out0() << endl << indent
1002 << "Molecular formula " << mf.formula() << endl;
1003 if (checkpoint) {
1004 mole->set_checkpoint();
1005 if (grp->me() == 0) mole->set_checkpoint_file(mole_ckpt_file);
1006 else mole->set_checkpoint_file(devnull);
1007 mole->set_checkpoint_freq(checkpoint_freq);
1008 }
1009 }
1010 delete[] mole_ckpt_file;
1011
1012 if (checkpoint && opt.nonnull()) {
1013 opt->set_checkpoint();
1014 if (grp->me() == 0) opt->set_checkpoint_file(ckptfile);
1015 else opt->set_checkpoint_file(devnull);
1016 }
1017
1018 // see if frequencies are wanted
1019
1020 Ref<MolecularHessian> molhess;
1021 molhess << keyval->describedclassvalue("hess");
1022 Ref<MolecularFrequencies> molfreq;
1023 molfreq << keyval->describedclassvalue("freq");
1024
1025 int check = (options.retrieve("c") != 0);
1026 int limit = atoi(options.retrieve("l"));
1027 if (limit) {
1028 Ref<Wavefunction> wfn; wfn << mole;
1029 if (wfn.nonnull() && wfn->ao_dimension()->n() > limit) {
1030 ExEnv::out0() << endl << indent
1031 << "The limit of " << limit << " basis functions has been exceeded."
1032 << endl;
1033 check = 1;
1034 }
1035 }
1036
1037 if (check) {
1038 ExEnv::out0() << endl << indent
1039 << "Exiting since the check option is on." << endl;
1040 exit(0);
1041 }
1042
1043 if (tim.nonnull()) tim->change("calc");
1044
1045 int do_energy = keyval->booleanvalue("do_energy",truevalue);
[d39b2b]1046
[5d30c1]1047 int do_grad = keyval->booleanvalue("do_gradient",falsevalue);
1048
1049 int do_opt = keyval->booleanvalue("optimize",truevalue);
[d39b2b]1050
[5d30c1]1051 int do_pdb = keyval->booleanvalue("write_pdb",falsevalue);
[d39b2b]1052
[5d30c1]1053 int print_mole = keyval->booleanvalue("print_mole",truevalue);
[d39b2b]1054
[5d30c1]1055 int print_timings = keyval->booleanvalue("print_timings",truevalue);
1056
[d39b2b]1057 // print all current options (keyvalues)
1058 printOptions(keyval, opt, molname, restartfile);
1059
[5d30c1]1060 // see if any pictures are desired
1061 Ref<Render> renderer;
1062 renderer << keyval->describedclassvalue("renderer");
1063
1064 // If we have a renderer, then we will read in some more info
1065 // below. Otherwise we can get rid of the keyval's, to eliminate
1066 // superfluous references to objects that we might otherwise be
1067 // able to delete. We cannot read in the remaining rendering
1068 // objects now, since some of their KeyVal CTOR's are heavyweight,
1069 // requiring optimized geometries, etc.
1070 if (renderer.null()) {
1071 if (parsedkv.nonnull()) print_unseen(parsedkv, input);
1072 keyval = 0;
1073 parsedkv = 0;
1074 }
1075
1076 delete[] restartfile;
1077 delete[] ckptfile;
1078
1079 int ready_for_freq = 1;
1080 if (mole.nonnull()) {
1081 if (((do_opt && opt.nonnull()) || do_grad)
1082 && !mole->gradient_implemented()) {
1083 ExEnv::out0() << indent
1084 << "WARNING: optimization or gradient requested but the given"
1085 << endl
1086 << " MolecularEnergy object cannot do gradients."
1087 << endl;
1088 }
1089
1090 if (do_opt && opt.nonnull() && mole->gradient_implemented()) {
1091 int result = opt->optimize();
1092 if (result) {
1093 ExEnv::out0() << indent
1094 << "The optimization has converged." << endl << endl;
1095 ExEnv::out0() << indent
1096 << scprintf("Value of the MolecularEnergy: %15.10f",
1097 mole->energy())
1098 << endl << endl;
1099 } else {
1100 ExEnv::out0() << indent
1101 << "The optimization has NOT converged." << endl << endl;
1102 ready_for_freq = 0;
1103 }
1104 } else if (do_grad && mole->gradient_implemented()) {
1105 mole->do_gradient(1);
1106 ExEnv::out0() << endl << indent
1107 << scprintf("Value of the MolecularEnergy: %15.10f",
1108 mole->energy())
1109 << endl;
1110 if (mole->value_result().actual_accuracy()
1111 > mole->value_result().desired_accuracy()) {
1112 ExEnv::out0() << indent
1113 << "WARNING: desired accuracy not achieved in energy" << endl;
1114 }
1115 ExEnv::out0() << endl;
1116 // Use result_noupdate since the energy might not have converged
1117 // to the desired accuracy in which case grabbing the result will
1118 // start up the calculation again. However the gradient might
1119 // not have been computed (if we are restarting and the gradient
1120 // isn't in the save file for example).
1121 RefSCVector grad;
1122 if (mole->gradient_result().computed()) {
1123 grad = mole->gradient_result().result_noupdate();
1124 }
1125 else {
1126 grad = mole->gradient();
1127 }
1128 if (grad.nonnull()) {
1129 grad.print("Gradient of the MolecularEnergy:");
1130 if (mole->gradient_result().actual_accuracy()
1131 > mole->gradient_result().desired_accuracy()) {
1132 ExEnv::out0() << indent
1133 << "WARNING: desired accuracy not achieved in gradient" << endl;
1134 }
1135 }
1136 } else if (do_energy && mole->value_implemented()) {
1137 ExEnv::out0() << endl << indent
1138 << scprintf("Value of the MolecularEnergy: %15.10f",
1139 mole->energy())
1140 << endl << endl;
1141 }
1142 }
1143
1144 if (tim.nonnull()) tim->exit("calc");
1145
1146 // save this before doing the frequency stuff since that obsoletes the
[a98b86]1147 saveState(wfn_file, savestate, opt, grp, mole, molname, ckptfile);
[5d30c1]1148
1149 // Frequency calculation.
1150 if (ready_for_freq && molfreq.nonnull()) {
1151 RefSymmSCMatrix xhessian;
1152 if (molhess.nonnull()) {
1153 // if "hess" input was given, use it to compute the hessian
1154 xhessian = molhess->cartesian_hessian();
1155 }
1156 else if (mole->hessian_implemented()) {
1157 // if mole can compute the hessian, use that hessian
1158 xhessian = mole->get_cartesian_hessian();
1159 }
1160 else if (mole->gradient_implemented()) {
1161 // if mole can compute gradients, use gradients at finite
1162 // displacements to compute the hessian
1163 molhess = new FinDispMolecularHessian(mole);
1164 xhessian = molhess->cartesian_hessian();
1165 }
1166 else {
1167 ExEnv::out0() << "mpqc: WARNING: Frequencies cannot be computed" << endl;
1168 }
1169
1170 if (xhessian.nonnull()) {
1171 char *hessfile = SCFormIO::fileext_to_filename(".hess");
1172 MolecularHessian::write_cartesian_hessian(hessfile,
1173 mole->molecule(), xhessian);
1174 delete[] hessfile;
1175
1176 molfreq->compute_frequencies(xhessian);
1177 // DEGENERACY IS NOT CORRECT FOR NON-SINGLET CASES:
1178 molfreq->thermochemistry(1);
1179 }
1180 }
1181
1182 if (renderer.nonnull()) {
1183 Ref<RenderedObject> rendered;
1184 rendered << keyval->describedclassvalue("rendered");
1185 Ref<AnimatedObject> animated;
1186 animated << keyval->describedclassvalue("rendered");
1187 if (rendered.nonnull()) {
1188 if (tim.nonnull()) tim->enter("render");
1189 if (grp->me() == 0) renderer->render(rendered);
1190 if (tim.nonnull()) tim->exit("render");
1191 }
1192 else if (animated.nonnull()) {
1193 if (tim.nonnull()) tim->enter("render");
1194 if (grp->me() == 0) renderer->animate(animated);
1195 if (tim.nonnull()) tim->exit("render");
1196 }
1197 else {
1198 if (tim.nonnull()) tim->enter("render");
1199 int n = keyval->count("rendered");
1200 for (i=0; i<n; i++) {
1201 rendered << keyval->describedclassvalue("rendered",i);
1202 animated << keyval->describedclassvalue("rendered",i);
1203 if (rendered.nonnull()) {
1204 // make sure the object has a name so we don't overwrite its file
1205 if (rendered->name() == 0) {
1206 char ic[64];
1207 sprintf(ic,"%02d",i);
1208 rendered->set_name(ic);
1209 }
1210 if (grp->me() == 0) renderer->render(rendered);
1211 }
1212 else if (animated.nonnull()) {
1213 // make sure the object has a name so we don't overwrite its file
1214 if (animated->name() == 0) {
1215 char ic[64];
1216 sprintf(ic,"%02d",i);
1217 animated->set_name(ic);
1218 }
1219 if (grp->me() == 0) renderer->animate(animated);
1220 }
1221 }
1222 if (tim.nonnull()) tim->exit("render");
1223 }
1224 Ref<MolFreqAnimate> molfreqanim;
1225 molfreqanim << keyval->describedclassvalue("animate_modes");
1226 if (ready_for_freq && molfreq.nonnull()
1227 && molfreqanim.nonnull()) {
1228 if (tim.nonnull()) tim->enter("render");
1229 molfreq->animate(renderer, molfreqanim);
1230 if (tim.nonnull()) tim->exit("render");
1231 }
1232 }
1233
1234 if (mole.nonnull()) {
1235 if (print_mole)
1236 mole->print(ExEnv::out0());
1237
1238 if (do_pdb && grp->me() == 0) {
1239 ckptfile = new char[strlen(molname)+5];
1240 sprintf(ckptfile, "%s.pdb", molname);
1241 ofstream pdbfile(ckptfile);
1242 mole->molecule()->print_pdb(pdbfile);
1243 delete[] ckptfile;
1244 }
1245
1246 }
1247 else {
1248 ExEnv::out0() << "mpqc: The molecular energy object is null" << endl
1249 << " make sure \"mole\" specifies a MolecularEnergy derivative"
1250 << endl;
1251 }
1252 if (parsedkv.nonnull()) print_unseen(parsedkv, input);
1253
1254 if (print_timings)
1255 if (tim.nonnull()) tim->print(ExEnv::out0());
1256
[027140]1257 // here, we may gather the results
1258 // we start to construct the MPQC_Data object
1259 {
1260 Ref<Wavefunction> wfn;
1261 wfn << mole;
1262 ExEnv::out0() << "The number of atomic orbitals: " << wfn->ao_dimension()->n() << endl;
1263 ExEnv::out0() << "The AO density matrix is ";
1264 wfn->ao_density()->print(ExEnv::out0());
[62dabe]1265 ExEnv::out0() << "The natural density matrix is ";
1266 wfn->natural_density()->print(ExEnv::out0());
[027140]1267 ExEnv::out0() << "The Gaussian basis is " << wfn->basis()->name() << endl;
[d11832]1268 ExEnv::out0() << "The Gaussians sit at the following centers: " << endl;
1269 for (int nr = 0; nr< wfn->basis()->ncenter(); ++nr) {
1270 ExEnv::out0() << nr << " basis function has its center at ";
1271 for (int i=0; i < 3; ++i)
1272 ExEnv::out0() << wfn->basis()->r(nr,i) << "\t";
1273 ExEnv::out0() << endl;
1274 }
[62dabe]1275 // GaussianShell is the actual orbital functions it seems ...
1276 //ExEnv::out0() << "There are the following Gaussian Shells: " << endl;
1277 SCVector3 r;
1278 r.x() = r.y() = r.z() = 10;
1279 ExEnv::out0() << "We get the following value at " << r << "." << endl;
1280 Ref<Integral> intgrl = Integral::get_default_integral();
1281 GaussianBasisSet::ValueData vdat(wfn->basis(), integral);
1282 ExEnv::out0() << "Value at (10,10,10) is " << EvaluateDensity(r, intgrl, vdat, wfn) << endl;
1283 boost::function<double (SCVector3 &r)> evaluator =
1284 boost::bind(&EvaluateDensity, _1, boost::ref(intgrl), boost::ref(vdat), boost::ref(wfn));
1285 ExEnv::out0() << "Check against values at " << r << "." << endl;
1286 int nbasis = wfn->basis()->nbasis();
1287 double *b_val = new double[nbasis];
1288 wfn->basis()->values(r, &vdat, b_val);
1289 for (int i=0; i<nbasis; i++) {
1290 //ExEnv::out0() << "Shell nr. " << nr << ": ";
1291 ExEnv::out0() << "Value at (10,10,10) is " << b_val[i] << endl;
[d11832]1292 }
[62dabe]1293 // perform test integration of density
1294 double delta = 1.;
1295 double sum = 0.;
1296 for (r.x() = -10. ; r.x() < 10.; r.x() += delta)
1297 for (r.y() = -10. ; r.y() < 10.; r.y() += delta)
1298 for (r.z() = -10. ; r.z() < 10.; r.z() += delta) {
1299 wfn->basis()->values(r, &vdat, b_val);
1300 for (int i=0; i<nbasis; i++)
1301 sum += wfn->ao_density()->get_element(i,i)*b_val[i];
1302 }
1303 sum /= pow(20/delta,3);
1304 ExEnv::out0() << "Sum over domain [0:20]^3 with " << delta << " delta is " << sum << "." << endl;
1305 delete[] b_val;
[027140]1306 }
1307
[5d30c1]1308 delete[] molname;
1309 SCFormIO::set_default_basename(0);
1310
1311 renderer = 0;
1312 molfreq = 0;
1313 molhess = 0;
1314 opt = 0;
1315 mole = 0;
1316 integral = 0;
1317 debugger = 0;
1318 thread = 0;
1319 tim = 0;
1320 keyval = 0;
1321 parsedkv = 0;
1322 grp = 0;
1323 memory = 0;
1324 clean_up();
1325
1326#if defined(HAVE_TIME) && defined(HAVE_CTIME)
[3d4397]1327 time_t t;
[5d30c1]1328 time(&t);
[3d4397]1329 const char *tstr = ctime(&t);
[5d30c1]1330#endif
1331 if (!tstr) {
1332 tstr = "UNKNOWN";
1333 }
1334 ExEnv::out0() << endl
1335 << indent << scprintf("End Time: %s", tstr) << endl;
1336
1337 if (output != 0) {
1338 ExEnv::set_out(&cout);
1339 delete outstream;
1340 }
1341
1342 return 0;
1343}
1344
[62dabe]1345double EvaluateDensity(SCVector3 &r, Ref<Integral> &intgrl, GaussianBasisSet::ValueData &vdat, Ref<Wavefunction> &wfn)
1346{
1347 ExEnv::out0() << "We get the following values at " << r << "." << endl;
1348 int nbasis = wfn->basis()->nbasis();
1349 double *b_val = new double[nbasis];
1350 wfn->basis()->values(r, &vdat, b_val);
1351 double sum=0.;
1352 for (int i=0; i<nbasis; i++)
1353 sum += b_val[i];
1354 delete[] b_val;
1355 return sum;
1356}
1357
[5d30c1]1358int
1359main(int argc, char *argv[])
1360{
1361 try {
1362 try_main(argc, argv);
1363 }
1364 catch (SCException &e) {
1365 cout << argv[0] << ": ERROR: SC EXCEPTION RAISED:" << endl
1366 << e.what()
1367 << endl;
1368 clean_up();
1369 throw;
1370 }
1371 catch (bad_alloc &e) {
1372 cout << argv[0] << ": ERROR: MEMORY ALLOCATION FAILED:" << endl
1373 << e.what()
1374 << endl;
1375 clean_up();
1376 throw;
1377 }
1378 catch (exception &e) {
1379 cout << argv[0] << ": ERROR: EXCEPTION RAISED:" << endl
1380 << e.what()
1381 << endl;
1382 clean_up();
1383 throw;
1384 }
1385 catch (...) {
1386 cout << argv[0] << ": ERROR: UNKNOWN EXCEPTION RAISED" << endl;
1387 clean_up();
1388 throw;
1389 }
1390 return 0;
1391}
1392
1393/////////////////////////////////////////////////////////////////////////////
1394
1395// Local Variables:
1396// mode: c++
1397// c-file-style: "ETS"
1398// End:
Note: See TracBrowser for help on using the repository browser.