3
// based on mbpt/distsh.h
5
// Copyright (C) 1996 Limit Point Systems, Inc.
7
// Author: Ida Nielsen <ida@kemi.aau.dk>
8
// Updated: Edward Valeev <edward.valeev@chemistry.gatech.edu>
11
// This file is part of the SC Toolkit.
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)
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.
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.
27
// The U.S. Government is granted a limited license as per AL 91-7.
30
#ifndef _chemistry_qc_basis_distshpair_h
31
#define _chemistry_qc_basis_distshpair_h
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>
46
/// Distributes shell pairs either statically or dynamically.
49
/** This is used to store data that must be shared between all
50
* cooperating shell pairs.
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.
60
void init() { shellpair_ = 0; }
65
Ref<ThreadLock> lock_;
66
Ref<GaussianBasisSet> bs1_;
67
Ref<GaussianBasisSet> bs2_;
72
// How often updates are printed (i.e. every 10% of total work)
73
double print_percent_;
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
81
long int print_interval_;
82
// Index of the next task to be served
83
long int current_shellpair_;
85
// for dynamic load balancing
91
// for static load balancing
92
int S_, R_; // NOTE: S is in bs1, R is in bs2
97
// sorted work for dynamic load balancing
103
void init_dynamic_work();
105
/** The DistShellPair class is used to distribute shell pair indices among tasks.
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);
113
/// Resets to the first shell pair.
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.
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);
133
// //////////////////////////////////////////////////////////////////////////
137
// c-file-style: "CLJ-CONDENSED"