1 | //
|
---|
2 | // distshpair.h
|
---|
3 | // based on mbpt/distsh.h
|
---|
4 | //
|
---|
5 | // Copyright (C) 1996 Limit Point Systems, Inc.
|
---|
6 | //
|
---|
7 | // Author: Ida Nielsen <ida@kemi.aau.dk>
|
---|
8 | // Updated: Edward Valeev <edward.valeev@chemistry.gatech.edu>
|
---|
9 | // Maintainer: LPS
|
---|
10 | //
|
---|
11 | // This file is part of the SC Toolkit.
|
---|
12 | //
|
---|
13 | // The SC Toolkit is free software; you can redistribute it and/or modify
|
---|
14 | // it under the terms of the GNU Library General Public License as published by
|
---|
15 | // the Free Software Foundation; either version 2, or (at your option)
|
---|
16 | // any later version.
|
---|
17 | //
|
---|
18 | // The SC Toolkit is distributed in the hope that it will be useful,
|
---|
19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
21 | // GNU Library General Public License for more details.
|
---|
22 | //
|
---|
23 | // You should have received a copy of the GNU Library General Public License
|
---|
24 | // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
|
---|
25 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
26 | //
|
---|
27 | // The U.S. Government is granted a limited license as per AL 91-7.
|
---|
28 | //
|
---|
29 |
|
---|
30 | #ifndef _chemistry_qc_basis_distshpair_h
|
---|
31 | #define _chemistry_qc_basis_distshpair_h
|
---|
32 |
|
---|
33 | #ifdef __GNUC__
|
---|
34 | #pragma interface
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | #include <util/misc/regtime.h>
|
---|
38 | #include <util/group/message.h>
|
---|
39 | #include <util/group/thread.h>
|
---|
40 | #include <chemistry/qc/basis/basis.h>
|
---|
41 |
|
---|
42 | using namespace sc;
|
---|
43 |
|
---|
44 | namespace sc {
|
---|
45 |
|
---|
46 | /// Distributes shell pairs either statically or dynamically.
|
---|
47 | class DistShellPair {
|
---|
48 | public:
|
---|
49 | /** This is used to store data that must be shared between all
|
---|
50 | * cooperating shell pairs.
|
---|
51 | */
|
---|
52 | class SharedData {
|
---|
53 | public:
|
---|
54 | volatile long int shellpair_;
|
---|
55 | /// Construct and initialize.
|
---|
56 | SharedData() { init(); }
|
---|
57 | /** If this will be used to iterate through the shells again,
|
---|
58 | * then init must be called.
|
---|
59 | */
|
---|
60 | void init() { shellpair_ = 0; }
|
---|
61 | };
|
---|
62 | private:
|
---|
63 | Ref<MessageGrp> msg_;
|
---|
64 | int nthread_;
|
---|
65 | Ref<ThreadLock> lock_;
|
---|
66 | Ref<GaussianBasisSet> bs1_;
|
---|
67 | Ref<GaussianBasisSet> bs2_;
|
---|
68 | bool bs1_eq_bs2_;
|
---|
69 | bool task_dynamic_;
|
---|
70 | bool thread_dynamic_;
|
---|
71 | int debug_;
|
---|
72 | // How often updates are printed (i.e. every 10% of total work)
|
---|
73 | double print_percent_;
|
---|
74 | SharedData *shared_;
|
---|
75 |
|
---|
76 | // Number of tasks handled by thread 0 in task 0:
|
---|
77 | // if dynamic == true : it will distribute all of them
|
---|
78 | // if dynamic == false : it will handle its share
|
---|
79 | long int ntask_;
|
---|
80 | // Print period
|
---|
81 | long int print_interval_;
|
---|
82 | // Index of the next task to be served
|
---|
83 | long int current_shellpair_;
|
---|
84 |
|
---|
85 | // for dynamic load balancing
|
---|
86 | int req_type_;
|
---|
87 | int ans_type_;
|
---|
88 | int ncpu_less_0_;
|
---|
89 | void serve_tasks();
|
---|
90 |
|
---|
91 | // for static load balancing
|
---|
92 | int S_, R_; // NOTE: S is in bs1, R is in bs2
|
---|
93 | int ncpu_;
|
---|
94 | int incS_, incR_;
|
---|
95 | int mythread_;
|
---|
96 |
|
---|
97 | // sorted work for dynamic load balancing
|
---|
98 | int *cost_;
|
---|
99 | int *Svec_;
|
---|
100 | int *Rvec_;
|
---|
101 | int *Ivec_;
|
---|
102 |
|
---|
103 | void init_dynamic_work();
|
---|
104 | public:
|
---|
105 | /** The DistShellPair class is used to distribute shell pair indices among tasks.
|
---|
106 |
|
---|
107 | Both static (round-robin) and dynamic methods are supported. */
|
---|
108 | DistShellPair(const Ref<MessageGrp> &, int nthread, int mythread,
|
---|
109 | const Ref<ThreadLock>& lock,
|
---|
110 | const Ref<GaussianBasisSet>& bs1, const Ref<GaussianBasisSet>& bs2,
|
---|
111 | bool dynamic, SharedData *shared = 0);
|
---|
112 | ~DistShellPair();
|
---|
113 | /// Resets to the first shell pair.
|
---|
114 | void init();
|
---|
115 | /// How much stuff to print out.
|
---|
116 | void set_debug(int d) { debug_ = d; }
|
---|
117 | /// How often to print status from node 0.
|
---|
118 | void set_print_percent(double p);
|
---|
119 | /** Puts the current PQ shell pair into P and Q and returns 1.
|
---|
120 | When there are no more shell pairs to be processed by this processor,
|
---|
121 | 0 is returned. Once we start doing get_tasks, we have to go to the
|
---|
122 | end if dynamic load balancing is used.
|
---|
123 |
|
---|
124 | P belongs to bs1, and Q belongs to bs2. If (bs1 == bs2) then
|
---|
125 | P is greater or equal to Q. */
|
---|
126 | int get_task(int &P, int &Q);
|
---|
127 | };
|
---|
128 |
|
---|
129 | }
|
---|
130 |
|
---|
131 | #endif
|
---|
132 |
|
---|
133 | // //////////////////////////////////////////////////////////////////////////
|
---|
134 |
|
---|
135 | // Local Variables:
|
---|
136 | // mode: c++
|
---|
137 | // c-file-style: "CLJ-CONDENSED"
|
---|
138 | // End:
|
---|