~ubuntu-branches/ubuntu/trusty/nwchem/trusty-proposed

« back to all changes in this revision

Viewing changes to src/tools/ga-5-1/tascel/src/TerminationDetector.cc

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Daniel Leidert, Andreas Tille, Michael Banck
  • Date: 2013-07-04 12:14:55 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130704121455-5tvsx2qabor3nrui
Tags: 6.3-1
* New upstream release.
* Fixes anisotropic properties (Closes: #696361).
* New features include:
  + Multi-reference coupled cluster (MRCC) approaches
  + Hybrid DFT calculations with short-range HF 
  + New density-functionals including Minnesota (M08, M11) and HSE hybrid
    functionals
  + X-ray absorption spectroscopy (XAS) with TDDFT
  + Analytical gradients for the COSMO solvation model
  + Transition densities from TDDFT 
  + DFT+U and Electron-Transfer (ET) methods for plane wave calculations
  + Exploitation of space group symmetry in plane wave geometry optimizations
  + Local density of states (LDOS) collective variable added to Metadynamics
  + Various new XC functionals added for plane wave calculations, including
    hybrid and range-corrected ones
  + Electric field gradients with relativistic corrections 
  + Nudged Elastic Band optimization method
  + Updated basis sets and ECPs 

[ Daniel Leidert ]
* debian/watch: Fixed.

[ Andreas Tille ]
* debian/upstream: References

[ Michael Banck ]
* debian/upstream (Name): New field.
* debian/patches/02_makefile_flags.patch: Refreshed.
* debian/patches/06_statfs_kfreebsd.patch: Likewise.
* debian/patches/07_ga_target_force_linux.patch: Likewise.
* debian/patches/05_avoid_inline_assembler.patch: Removed, no longer needed.
* debian/patches/09_backported_6.1.1_fixes.patch: Likewise.
* debian/control (Build-Depends): Added gfortran-4.7 and gcc-4.7.
* debian/patches/10_force_gcc-4.7.patch: New patch, explicitly sets
  gfortran-4.7 and gcc-4.7, fixes test suite hang with gcc-4.8 (Closes:
  #701328, #713262).
* debian/testsuite: Added tests for COSMO analytical gradients and MRCC.
* debian/rules (MRCC_METHODS): New variable, required to enable MRCC methods.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#if HAVE_CONFIG_H
2
 
# include "config.h"
3
 
#endif
4
 
 
5
 
#include <mpi.h>
6
 
 
7
 
#include "Comm.h"
8
 
#include "TerminationDetector.h"
9
 
 
10
 
using namespace std;
11
 
using namespace tascel;
12
 
using namespace tascel::comm;
13
 
 
14
 
 
15
 
void
16
 
TerminationDetector::resetUpPhase() {
17
 
  if (child[0] >= 0) {
18
 
    MPI_Irecv(&cvote[0], 1, MPI_INT, child[0], child[0], MPI_COMM_WORLD, &creq[0]);
19
 
  }
20
 
  if (child[1] >= 0) {
21
 
    MPI_Irecv(&cvote[1], 1, MPI_INT, child[1], child[1], MPI_COMM_WORLD, &creq[1]);
22
 
  }
23
 
  myvote = 1; //yes
24
 
  dirUp = false;
25
 
}
26
 
 
27
 
void
28
 
TerminationDetector::resetDownPhase() {
29
 
  if (parent >= 0) {
30
 
    MPI_Irecv(&pdecision, 1, MPI_INT, parent, parent, MPI_COMM_WORLD, &preq);
31
 
  }
32
 
  dirUp = true;
33
 
}
34
 
 
35
 
TerminationDetector::TerminationDetector() {
36
 
  child[0] = (2 * me() + 1 < nproc()) ? 2 * me() + 1 : -1;
37
 
  child[1] = (2 * me() + 2 < nproc()) ? 2 * me() + 2 : -1;
38
 
  parent = (me != 0) ? (me() - 1) / 2 : -1;
39
 
  pdecision = 0;
40
 
  resetUpPhase();
41
 
  resetDownPhase(); //this should after up. we start with the up phase
42
 
}
43
 
 
44
 
TerminationDetector::~TerminationDetector() {
45
 
  if (child[0] >= 0) {
46
 
    MPI_Cancel(&creq[0]);
47
 
  }
48
 
  if (child[1] >= 0) {
49
 
    MPI_Cancel(&creq[1]);
50
 
  }
51
 
  if (parent >= 0) {
52
 
    MPI_Cancel(&preq);
53
 
  }
54
 
}
55
 
 
56
 
void
57
 
TerminationDetector::vote(bool _myvote) {
58
 
  myvote = (_myvote == false) ? 0 : myvote;
59
 
}
60
 
 
61
 
void
62
 
TerminationDetector::propogateUp() {
63
 
  int decision = myvote;
64
 
  if (child[0] >= 0 && cvote[0] == 0) {
65
 
    decision = 0;
66
 
  }
67
 
  if (child[1] >= 0 && cvote[1] == 0) {
68
 
    decision = 0;
69
 
  }
70
 
  if (me() == 0) {
71
 
    pdecision = decision;
72
 
  }
73
 
 
74
 
  if (parent >= 0) {
75
 
    MPI_Send(&decision, 1, MPI_INT, parent, me(), MPI_COMM_WORLD);
76
 
  }
77
 
  resetUpPhase();
78
 
}
79
 
 
80
 
void
81
 
TerminationDetector::propogateDown() {
82
 
  if (child[0] >= 0) {
83
 
    MPI_Send(&pdecision, 1, MPI_INT, child[0], me(), MPI_COMM_WORLD);
84
 
  }
85
 
  if (child[1] >= 0) {
86
 
    MPI_Send(&pdecision, 1, MPI_INT, child[1], me(), MPI_COMM_WORLD);
87
 
  }
88
 
  resetDownPhase();
89
 
}
90
 
 
91
 
void
92
 
TerminationDetector::progress(bool _myvote) {
93
 
  vote(_myvote);
94
 
  if (pdecision == 1 || (me() == 0 && nproc() == 0 && myvote == 1)) {
95
 
    return; //termination detected. nothing more to do
96
 
  }
97
 
  if (dirUp) {
98
 
    int flag[2] = {1, 1};
99
 
    MPI_Status status[2];
100
 
    if (child[0] >= 0) {
101
 
      MPI_Test(&creq[0], &flag[0], &status[0]);
102
 
    }
103
 
    if (child[1] >= 1) {
104
 
      MPI_Test(&creq[1], &flag[1], &status[1]);
105
 
    }
106
 
    if (flag[0] && flag[1]) {
107
 
      propogateUp();
108
 
    }
109
 
  }
110
 
  /*Tiny optimization: propogate inverts dirUp. So both dirUp and
111
 
    !dirUp could be executed consecutively, especially for me()==0*/
112
 
  if (!dirUp) {
113
 
    int flag = 1;
114
 
    MPI_Status status;
115
 
    if (parent >= 0) {
116
 
      MPI_Test(&preq, &flag, &status);
117
 
    }
118
 
    if (flag) {
119
 
      propogateDown();
120
 
    }
121
 
  }
122
 
}
123
 
 
124
 
bool
125
 
TerminationDetector::hasTerminated() {
126
 
//   progress(myvote);
127
 
  return pdecision == 1;
128
 
}
129