MPQC  3.0.0-alpha
distsh.h
1 //
2 // distsh.h
3 // modeled after distshpair.h
4 //
5 // Copyright (C) 2009 Edward Valeev
6 //
7 // Author: Edward Valeev <evaleev@vt.edu>
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit 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 Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. 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 #ifndef _chemistry_qc_basis_distsh_h
29 #define _chemistry_qc_basis_distsh_h
30 
31 #include <util/misc/regtime.h>
32 #include <util/group/message.h>
33 #include <util/group/thread.h>
34 #include <chemistry/qc/basis/basis.h>
35 
36 namespace sc {
37 
39 class DistShell {
40  public:
44  class SharedData {
45  public:
46  volatile long int shell_;
48  SharedData() { init(); }
52  void init() { shell_ = 0; }
53  };
54 
58  DistShell(const Ref<MessageGrp> &, int nthread, int mythread,
59  const Ref<ThreadLock>& lock,
60  const Ref<GaussianBasisSet>& bs,
61  bool dynamic,
62  int max_nfunctions = -1,
63  int max_nshell = 1,
64  SharedData *shared = 0);
65  ~DistShell();
67  void init();
69  void set_debug(int d) { debug_ = d; }
72  void set_print_percent(double p);
77  int get_task(int& I, int& N);
78 
81  int shell_index(int i) const;
82 
83  private:
84  Ref<MessageGrp> msg_;
85  int nthread_;
86  Ref<ThreadLock> lock_;
88  int max_nfunction_;
89  int max_nshell_;
90  bool task_dynamic_;
91  bool thread_dynamic_; //< only true is 1 task, multiple threads, and shared data given
92  int debug_;
93  // How often updates are printed (i.e. every 10% of total work)
94  double print_percent_;
95  SharedData *shared_;
96 
97  typedef std::vector<int> ShellIndexMap;
98  ShellIndexMap shell_map_;
99 
100  typedef std::pair<int,int> Task;
101  typedef std::vector<Task> Tasks;
102  Tasks tasks_;
103 
104  // Number of tasks handled by thread 0 in task 0:
105  // if dynamic == true : it will distribute all of them
106  // if dynamic == false : it will handle its share
107  long int ntask_;
108  // Print period
109  long int print_interval_;
110  // Index of the next task to be served
111  int current_task_;
112 
113  // for dynamic load balancing
114  int req_type_;
115  int ans_type_;
116  void serve_tasks();
117 
118  // for static load balancing
119  int ncpu_;
120  int mythread_;
121 
122  // computes work units subject to max_nfunction and max_nshell constraints
123  void init_work();
124 
125  public:
126 };
127 
128 }
129 
130 #endif
131 
132 // //////////////////////////////////////////////////////////////////////////
133 
134 // Local Variables:
135 // mode: c++
136 // c-file-style: "CLJ-CONDENSED"
137 // End:
sc::DistShell::get_task
int get_task(int &I, int &N)
Copies "payload" (I is the first shell of the shell set, in the increasing-size order,...
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
sc::DistShell
Distributes sets of shells either statically or dynamically.
Definition: distsh.h:39
sc::DistShell::DistShell
DistShell(const Ref< MessageGrp > &, int nthread, int mythread, const Ref< ThreadLock > &lock, const Ref< GaussianBasisSet > &bs, bool dynamic, int max_nfunctions=-1, int max_nshell=1, SharedData *shared=0)
The DistShell class is used to distribute sets of shells to compute tasks.
sc::DistShell::SharedData::SharedData
SharedData()
Construct and initialize.
Definition: distsh.h:48
sc::DistShell::SharedData::init
void init()
If this will be used to iterate through the shells again, then init must be called.
Definition: distsh.h:52
sc::DistShell::set_print_percent
void set_print_percent(double p)
How often to print status from node 0.
sc::DistShell::init
void init()
Resets to the first shell.
sc::DistShell::shell_index
int shell_index(int i) const
maps shell index from the work ordering (as reported to get_task() ) to its index within the basis se...
sc::DistShell::SharedData
This is used to store data that must be shared between all cooperating shell sets.
Definition: distsh.h:44
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
sc::DistShell::set_debug
void set_debug(int d)
How much stuff to print out.
Definition: distsh.h:69

Generated at Sun Jan 26 2020 23:23:57 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.