[0b990d] | 1 | //
|
---|
| 2 | // scpr.cc
|
---|
| 3 | //
|
---|
| 4 | // Copyright (C) 1997 Limit Point Systems, Inc.
|
---|
| 5 | //
|
---|
| 6 | // Author: Curtis Janssen <cljanss@limitpt.com>
|
---|
| 7 | // Maintainer: LPS
|
---|
| 8 | //
|
---|
| 9 | // This file is part of the SC Toolkit utilities.
|
---|
| 10 | //
|
---|
| 11 | // The SC Toolkit utilities are free software; you can redistribute them
|
---|
| 12 | // and/or modify them under the terms of the GNU General Public License as
|
---|
| 13 | // published by the Free Software Foundation; either version 2, or (at your
|
---|
| 14 | // option) any later version.
|
---|
| 15 | //
|
---|
| 16 | // The SC Toolkit utilities are distributed in the hope that they will be
|
---|
| 17 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 19 | // General Public License for more details.
|
---|
| 20 | //
|
---|
| 21 | // You should have received a copy of the GNU General Public License along
|
---|
| 22 | // with the SC Toolkit utilities; 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 | #ifdef HAVE_CONFIG_H
|
---|
| 29 | #include <scconfig.h>
|
---|
| 30 | #endif
|
---|
| 31 |
|
---|
| 32 | #include <unistd.h>
|
---|
| 33 | #include <new>
|
---|
| 34 |
|
---|
| 35 | #include <util/misc/exenv.h>
|
---|
| 36 | #include <util/misc/formio.h>
|
---|
| 37 | #include <util/group/mstate.h>
|
---|
| 38 | #include <util/group/message.h>
|
---|
| 39 | #include <util/group/thread.h>
|
---|
| 40 | #include <util/group/memory.h>
|
---|
| 41 |
|
---|
| 42 | // Force linkages:
|
---|
| 43 | #include <chemistry/qc/wfn/linkage.h>
|
---|
| 44 | #include <chemistry/qc/dft/linkage.h>
|
---|
| 45 | #include <chemistry/qc/mbpt/linkage.h>
|
---|
| 46 | #ifdef HAVE_SC_SRC_LIB_CHEMISTRY_QC_MBPTR12
|
---|
| 47 | # include <chemistry/qc/mbptr12/linkage.h>
|
---|
| 48 | #endif
|
---|
| 49 | #ifdef HAVE_SC_SRC_LIB_CHEMISTRY_QC_CINTS
|
---|
| 50 | # include <chemistry/qc/cints/linkage.h>
|
---|
| 51 | #endif
|
---|
| 52 | //#include <chemistry/qc/psi/linkage.h>
|
---|
| 53 | #include <util/state/linkage.h>
|
---|
| 54 |
|
---|
| 55 | using namespace std;
|
---|
| 56 | using namespace sc;
|
---|
| 57 |
|
---|
| 58 | #ifdef HAVE_MPI
|
---|
| 59 | #define MPICH_SKIP_MPICXX
|
---|
| 60 | #include <mpi.h>
|
---|
| 61 | #endif
|
---|
| 62 |
|
---|
| 63 | //////////////////////////////////////////////////////////////////////////
|
---|
| 64 |
|
---|
| 65 | static void
|
---|
| 66 | clean_up(void)
|
---|
| 67 | {
|
---|
| 68 | MessageGrp::set_default_messagegrp(0);
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | static void
|
---|
| 72 | out_of_memory()
|
---|
| 73 | {
|
---|
| 74 | ExEnv::errn() << "ERROR: out of memory" << endl;
|
---|
| 75 | abort();
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | int
|
---|
| 79 | main(int argc, char *argv[])
|
---|
| 80 | {
|
---|
| 81 | atexit(clean_up);
|
---|
| 82 | std::set_new_handler(out_of_memory);
|
---|
| 83 |
|
---|
| 84 | ExEnv::init(argc, argv);
|
---|
| 85 | ExEnv::set_out(&cout);
|
---|
| 86 |
|
---|
| 87 | #ifdef HAVE_MPI
|
---|
| 88 | // MPI is allowed wait until MPI_Init to fill in argc and argv,
|
---|
| 89 | // so we may have to call MPI_Init before we even know that we
|
---|
| 90 | // want an MPIMessageGrp. The command name is used to let scpr
|
---|
| 91 | // know that an early init is needed.
|
---|
| 92 | if (!strcmp(ExEnv::program_name(), "scpr-mpi")) {
|
---|
| 93 | MPI_Init(&argc, &argv);
|
---|
| 94 | }
|
---|
| 95 | #endif
|
---|
| 96 |
|
---|
| 97 | int i;
|
---|
| 98 | int debug = 0;
|
---|
| 99 | int version = 0;
|
---|
| 100 | int warranty = 0;
|
---|
| 101 | int license = 0;
|
---|
| 102 | int help = 0;
|
---|
| 103 | const char *working_dir = 0;
|
---|
| 104 | char **files = 0;
|
---|
| 105 | char **objects = 0;
|
---|
| 106 | int nfile = 0;
|
---|
| 107 | int nobject = 0;
|
---|
| 108 | for (i=1; i<argc; i++) {
|
---|
| 109 | char *arg = argv[i];
|
---|
| 110 | if (!strcmp(arg,"-messagegrp")) i++;
|
---|
| 111 | else if (!strcmp(arg,"-memorygrp")) i++;
|
---|
| 112 | else if (!strcmp(arg,"-threadgrp")) i++;
|
---|
| 113 | else if (!strcmp(arg,"-W")) working_dir = argv[++i];
|
---|
| 114 | else if (!strcmp(arg,"-d")) debug = 1;
|
---|
| 115 | else if (!strcmp(arg,"-h")) help = 1;
|
---|
| 116 | else if (!strcmp(arg,"-l")) SCFormIO::setverbose(ExEnv::outn(),1);
|
---|
| 117 | else if (!strcmp(arg,"-v")) version = 1;
|
---|
| 118 | else if (!strcmp(arg,"-w")) warranty = 1;
|
---|
| 119 | else if (!strcmp(arg,"-L")) license = 1;
|
---|
| 120 | else if (!strcmp(arg,"-o")) {
|
---|
| 121 | if (argc > i+1) {
|
---|
| 122 | char **newobjects = new char *[nobject+1];
|
---|
| 123 | memcpy(newobjects, objects, sizeof(char*)*nobject);
|
---|
| 124 | delete[] objects;
|
---|
| 125 | objects = newobjects;
|
---|
| 126 | objects[nobject++] = argv[++i];
|
---|
| 127 | }
|
---|
| 128 | else help = 1;
|
---|
| 129 | }
|
---|
| 130 | else {
|
---|
| 131 | char **newfiles = new char *[nfile+1];
|
---|
| 132 | memcpy(newfiles, files, sizeof(char*)*nfile);
|
---|
| 133 | delete[] files;
|
---|
| 134 | files = newfiles;
|
---|
| 135 | files[nfile++] = arg;
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | if (help || nobject == 0 || nfile == 0) {
|
---|
| 140 | ExEnv::out0()
|
---|
| 141 | << indent << "scpr version " << SC_VERSION << endl
|
---|
| 142 | << SCFormIO::copyright << endl
|
---|
| 143 | << indent << "usage: " << argv[0] << " [options] file ..." << endl
|
---|
| 144 | << indent << "where options are chosen from:" << endl
|
---|
| 145 | << indent << "-o <$val> (print the object with the name $val)"<<endl
|
---|
| 146 | << indent << "-memorygrp <$val> (which memory group to use)" << endl
|
---|
| 147 | << indent << "-threadgrp <$val> (which thread group to use)" << endl
|
---|
| 148 | << indent << "-messagegrp <$val> (which message group to use)"<<endl
|
---|
| 149 | << indent << "-W <$val> (set the working directory)" << endl
|
---|
| 150 | << indent << "-d (turn on debugging)" << endl
|
---|
| 151 | << indent << "-l (verbose printing)" << endl
|
---|
| 152 | << indent << "-v (print the version)" << endl
|
---|
| 153 | << indent << "-w (print the warranty)" << endl
|
---|
| 154 | << indent << "-L (print the license)" << endl
|
---|
| 155 | << indent << "-h (print this help)" << endl;
|
---|
| 156 |
|
---|
| 157 | ExEnv::out0() << endl
|
---|
| 158 | << indent << "object names take the form classname:ordinal_number"
|
---|
| 159 | << endl
|
---|
| 160 | << indent << "at least one file and object name must be given"
|
---|
| 161 | << endl;
|
---|
| 162 | exit(0);
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | if (version) {
|
---|
| 166 | ExEnv::out0()
|
---|
| 167 | << indent << "scpr version " << SC_VERSION << endl
|
---|
| 168 | << SCFormIO::copyright;
|
---|
| 169 | exit(0);
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | if (warranty) {
|
---|
| 173 | ExEnv::out0()
|
---|
| 174 | << indent << "scpr version " << SC_VERSION << endl
|
---|
| 175 | << SCFormIO::copyright << endl
|
---|
| 176 | << SCFormIO::warranty;
|
---|
| 177 | exit(0);
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | if (license) {
|
---|
| 181 | ExEnv::out0()
|
---|
| 182 | << indent << "scpr version " << SC_VERSION << endl
|
---|
| 183 | << SCFormIO::copyright << endl
|
---|
| 184 | << SCFormIO::license;
|
---|
| 185 | exit(0);
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | // set the working dir
|
---|
| 189 | if (working_dir && strcmp(working_dir,"."))
|
---|
| 190 | chdir(working_dir);
|
---|
| 191 |
|
---|
| 192 | // get the message group. first try the commandline and environment
|
---|
| 193 | Ref<MessageGrp> grp = MessageGrp::initial_messagegrp(argc, argv);
|
---|
| 194 | if (grp.nonnull())
|
---|
| 195 | MessageGrp::set_default_messagegrp(grp);
|
---|
| 196 | else
|
---|
| 197 | grp = MessageGrp::get_default_messagegrp();
|
---|
| 198 |
|
---|
| 199 | // get the thread group. first try the commandline and environment
|
---|
| 200 | Ref<ThreadGrp> thread = ThreadGrp::initial_threadgrp(argc, argv);
|
---|
| 201 | if (thread.nonnull())
|
---|
| 202 | ThreadGrp::set_default_threadgrp(thread);
|
---|
| 203 | else
|
---|
| 204 | thread = ThreadGrp::get_default_threadgrp();
|
---|
| 205 |
|
---|
| 206 | // set up output classes
|
---|
| 207 | SCFormIO::setindent(ExEnv::outn(), 0);
|
---|
| 208 | SCFormIO::setindent(ExEnv::errn(), 0);
|
---|
| 209 | SCFormIO::setindent(cout, 0);
|
---|
| 210 | SCFormIO::setindent(cerr, 0);
|
---|
| 211 |
|
---|
| 212 | SCFormIO::set_printnode(0);
|
---|
| 213 | if (grp->n() > 1)
|
---|
| 214 | SCFormIO::init_mp(grp->me());
|
---|
| 215 |
|
---|
| 216 | if (debug)
|
---|
| 217 | SCFormIO::set_debug(1);
|
---|
| 218 |
|
---|
| 219 | for (i=0; i<nfile; i++) {
|
---|
| 220 | if (nfile > 1) {
|
---|
| 221 | ExEnv::out0() << indent << files[i] << ":" << endl;
|
---|
| 222 | ExEnv::out0() << incindent;
|
---|
| 223 | }
|
---|
| 224 | BcastStateInBin s(grp,files[i]);
|
---|
| 225 | for (int j=0; j<nobject; j++) {
|
---|
| 226 | if (nobject > 1) {
|
---|
| 227 | ExEnv::out0() << indent << objects[j] << ":" << endl;
|
---|
| 228 | ExEnv::out0() << incindent;
|
---|
| 229 | }
|
---|
| 230 | Ref<SavableState> o;
|
---|
| 231 | o << SavableState::dir_restore_state(s,objects[j]);
|
---|
| 232 | o->print(ExEnv::out0());
|
---|
| 233 | if (nobject > 1) ExEnv::out0() << decindent;
|
---|
| 234 | }
|
---|
| 235 | if (nfile > 1) ExEnv::out0() << decindent;
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | delete[] files;
|
---|
| 239 |
|
---|
| 240 | return 0;
|
---|
| 241 | }
|
---|
| 242 |
|
---|
| 243 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 244 |
|
---|
| 245 | // Local Variables:
|
---|
| 246 | // mode: c++
|
---|
| 247 | // c-file-style: "CLJ"
|
---|
| 248 | // End:
|
---|