Changeset 4aba27


Ignore:
Timestamp:
Jul 11, 2012, 9:31:41 AM (13 years ago)
Author:
Frederik Heber <heber@…>
Children:
16135f
Parents:
850bce
git-author:
Frederik Heber <heber@…> (07/11/12 09:24:59)
git-committer:
Frederik Heber <heber@…> (07/11/12 09:31:41)
Message:

Shifted some allocations from mainFunction into try_main().

  • MessageGrp has to persist through the all calculations.
  • basename was removed too early.
  • split off final_clean_up() from clean_up().
  • we use mktemp to generate a unique temporary output name, otherwise temporary state files interfer with one another (and cause bad dimension from SCVector()).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/bin/mpqc/mpqc.cc

    r850bce r4aba27  
    177177{
    178178  MemoryGrp::set_default_memorygrp(0);
    179   MessageGrp::set_default_messagegrp(0);
    180179  ThreadGrp::set_default_threadgrp(0);
    181180  SCMatrixKit::set_default_matrixkit(0);
    182181  Integral::set_default_integral(0);
    183182  RegionTimer::set_default_regiontimer(0);
     183}
     184
     185static void
     186final_clean_up(void)
     187{
     188  MessageGrp::set_default_messagegrp(0);
    184189}
    185190
     
    12051210/** Performs the main work to calculate the ground state energies, gradients, etc.
    12061211 *
     1212 * @param grp message group
    12071213 * @param values temporary value storage for parsed command-line
    12081214 * @param input input file name
     
    12131219 */
    12141220void mainFunction(
     1221    Ref<MessageGrp> grp,
    12151222    struct OptionValues &values,
     1223    const char *&output,
    12161224    const char *&input,
    12171225    const char *&generic_input,
     
    12241232    )
    12251233{
    1226   // get the message group.  first try the commandline and environment
    1227   Ref<MessageGrp> grp;
    1228   getMessageGroup(grp, argc, argv);
     1234  // get the basename for output files
     1235  setOutputBaseName(input, output);
    12291236
    12301237  // parse input into keyvalue container
     
    12531260  Ref<ThreadGrp> thread;
    12541261  getThreadGroup(keyval, thread, argc, argv);
    1255  
     1262
    12561263  // get the memory group.
    12571264  Ref<MemoryGrp> memory;
     
    14971504       }
    14981505     }
    1499      // GaussianShell is the actual orbital functions it seems ...
    1500      //ExEnv::out0() << "There are the following Gaussian Shells: " << endl;
    1501      SCVector3 r;
    1502      r.x() = r.y() = r.z() = 10;
    1503      ExEnv::out0() << "We get the following value at " << r << "." << endl;
    1504      Ref<Integral> intgrl = Integral::get_default_integral();
    1505      GaussianBasisSet::ValueData vdat(wfn->basis(), integral);
    1506      ExEnv::out0() << "Value at (10,10,10) is " << EvaluateDensity(r, intgrl, vdat, wfn) << endl;
    1507      boost::function<double (SCVector3 &r)> evaluator =
    1508          boost::bind(&EvaluateDensity, _1, boost::ref(intgrl), boost::ref(vdat), boost::ref(wfn));
    1509      ExEnv::out0() << "Check against values at " << r << "." << endl;
    1510      int nbasis = wfn->basis()->nbasis();
    1511      double *b_val = new double[nbasis];
    1512      wfn->basis()->values(r, &vdat, b_val);
    1513      for (int i=0; i<nbasis; i++) {
    1514        //ExEnv::out0() << "Shell nr. " << nr << ": ";
    1515        ExEnv::out0() << "Value at (10,10,10) is " << b_val[i] << endl;
    1516      }
    1517      // perform test integration of density
    1518      double delta = 1.;
    1519      double sum = 0.;
    1520      for (r.x() = -10. ; r.x() < 10.; r.x() += delta)
    1521        for (r.y() = -10. ; r.y() < 10.; r.y() += delta)
    1522          for (r.z() = -10. ; r.z() < 10.; r.z() += delta) {
    1523            wfn->basis()->values(r, &vdat, b_val);
    1524            for (int i=0; i<nbasis; i++)
    1525              sum += wfn->ao_density()->get_element(i,i)*b_val[i];
    1526          }
    1527      sum /= pow(20/delta,3);
    1528      ExEnv::out0() << "Sum over domain [0:20]^3 with " << delta << " delta is " << sum << "." << endl;
    1529      delete[] b_val;
     1506//     // GaussianShell is the actual orbital functions it seems ...
     1507//     //ExEnv::out0() << "There are the following Gaussian Shells: " << endl;
     1508//     SCVector3 r;
     1509//     r.x() = r.y() = r.z() = 10;
     1510//     ExEnv::out0() << "We get the following value at " << r << "." << endl;
     1511//     Ref<Integral> intgrl = Integral::get_default_integral();
     1512//     GaussianBasisSet::ValueData vdat(wfn->basis(), integral);
     1513//     ExEnv::out0() << "Value at (10,10,10) is " << EvaluateDensity(r, intgrl, vdat, wfn) << endl;
     1514//     boost::function<double (SCVector3 &r)> evaluator =
     1515//         boost::bind(&EvaluateDensity, _1, boost::ref(intgrl), boost::ref(vdat), boost::ref(wfn));
     1516//     ExEnv::out0() << "Check against values at " << r << "." << endl;
     1517//     int nbasis = wfn->basis()->nbasis();
     1518//     double *b_val = new double[nbasis];
     1519//     wfn->basis()->values(r, &vdat, b_val);
     1520//     for (int i=0; i<nbasis; i++) {
     1521//       //ExEnv::out0() << "Shell nr. " << nr << ": ";
     1522//       ExEnv::out0() << "Value at (10,10,10) is " << b_val[i] << endl;
     1523//     }
     1524//     // perform test integration of density
     1525//     double delta = 1.;
     1526//     double sum = 0.;
     1527//     for (r.x() = -10. ; r.x() < 10.; r.x() += delta)
     1528//       for (r.y() = -10. ; r.y() < 10.; r.y() += delta)
     1529//         for (r.z() = -10. ; r.z() < 10.; r.z() += delta) {
     1530//           wfn->basis()->values(r, &vdat, b_val);
     1531//           for (int i=0; i<nbasis; i++)
     1532//             sum += wfn->ao_density()->get_element(i,i)*b_val[i];
     1533//         }
     1534//     sum /= pow(20/delta,3);
     1535//     ExEnv::out0() << "Sum over domain [0:20]^3 with " << delta << " delta is " << sum << "." << endl;
     1536//     delete[] b_val;
    15301537  }
    15311538
     
    15441551  keyval = 0;
    15451552  parsedkv = 0;
    1546   grp = 0;
    15471553  memory = 0;
    15481554  clean_up();
     
    15961602  const char *generic_input = 0;
    15971603  MPQCData data;
    1598   mainFunction(values, input, generic_input, in_char_array, argc, argv, data);
    1599   delete[] in_char_array;
     1604  Ref<MessageGrp> grp = MessageGrp::get_default_messagegrp();
     1605  char filename_template[] = "mpqc_temp_XXXXXX";
     1606  const char *output = mktemp(filename_template);
     1607  mainFunction(grp, values, output, input, generic_input, in_char_array, argc, argv, data);
     1608//  delete[] in_char_array;
    16001609
    16011610//  if (output != 0) {
     
    16421651  if (generic_input) input = generic_input;
    16431652
    1644   // get the basename for output files
    1645   setOutputBaseName(input, output);
     1653  // get the message group.  first try the commandline and environment
     1654  Ref<MessageGrp> grp;
     1655  getMessageGroup(grp, argc, argv);
    16461656
    16471657  // check if we got option "-n"
     
    16891699#ifdef HAVE_MPQCDATA
    16901700    MPQCData data;
    1691     mainFunction(values, input, generic_input, in_char_array, argc, argv, data);
     1701    mainFunction(grp, values, output, input, generic_input, in_char_array, argc, argv, data);
    16921702#else
    1693     mainFunction(values, input, generic_input, in_char_array, argc, argv);
     1703    mainFunction(grp, values, output, input, generic_input, in_char_array, argc, argv);
    16941704#endif
    16951705  }
     
    16991709    delete outstream;
    17001710  }
     1711
     1712  grp = 0;
     1713  final_clean_up();
    17011714
    17021715  return exitflag;
Note: See TracChangeset for help on using the changeset viewer.