~ubuntu-branches/ubuntu/saucy/nwchem/saucy

« back to all changes in this revision

Viewing changes to src/tools/ga-5-1/tascel/src/SplitQueueOpt.h

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Michael Banck, Daniel Leidert
  • Date: 2012-02-09 20:02:41 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120209200241-jgk03qfsphal4ug2
Tags: 6.1-1
* New upstream release.

[ Michael Banck ]
* debian/patches/02_makefile_flags.patch: Updated.
* debian/patches/02_makefile_flags.patch: Use internal blas and lapack code.
* debian/patches/02_makefile_flags.patch: Define GCC4 for LINUX and LINUX64
  (Closes: #632611 and LP: #791308).
* debian/control (Build-Depends): Added openssh-client.
* debian/rules (USE_SCALAPACK, SCALAPACK): Removed variables (Closes:
  #654658).
* debian/rules (LIBDIR, USE_MPIF4, ARMCI_NETWORK): New variables.
* debian/TODO: New file.
* debian/control (Build-Depends): Removed libblas-dev, liblapack-dev and
  libscalapack-mpi-dev.
* debian/patches/04_show_testsuite_diff_output.patch: New patch, shows the
  diff output for failed tests.
* debian/patches/series: Adjusted.
* debian/testsuite: Optionally run all tests if "all" is passed as option.
* debian/rules: Run debian/testsuite with "all" if DEB_BUILD_OPTIONS
  contains "checkall".

[ Daniel Leidert ]
* debian/control: Used wrap-and-sort. Added Vcs-Svn and Vcs-Browser fields.
  (Priority): Moved to extra according to policy section 2.5.
  (Standards-Version): Bumped to 3.9.2.
  (Description): Fixed a typo.
* debian/watch: Added.
* debian/patches/03_hurd-i386_define_path_max.patch: Added.
  - Define MAX_PATH if not defines to fix FTBFS on hurd.
* debian/patches/series: Adjusted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef __tascel_SplitQueueOpt_h__
 
2
#define __tascel_SplitQueueOpt_h__
 
3
 
 
4
#include "TerminationDetector.h"
 
5
 
 
6
namespace tascel {
 
7
 
 
8
  /**
 
9
   * A set of task queues shared among processes.
 
10
   *
 
11
   * Each process has a local queue with a maximum number of possible tasks.
 
12
   * A process can steal tasks from any other process's queue and have
 
13
   * tasks stolen from its own queue.
 
14
   *
 
15
   * This implementation splits the queue into a local and shared portion.
 
16
   * This allows the local process to modify its queue without locking.
 
17
   *
 
18
   * Compared to the original SplitQueue, this SplitQueueOpt is further
 
19
   * optimized by allowing a stealing process to steal without locking all of
 
20
   * the queue state, as described in "Scalable Work Stealing", SC'09.
 
21
   */
 
22
  class SplitQueueOpt {
 
23
    private:
 
24
      /**
 
25
       * The local queue state which other procs can modify.
 
26
       *
 
27
       * Queue state is further split into two pieces. The vtail2 is separated
 
28
       * so that it can be updated independent of the rest of the queue state.
 
29
       */
 
30
      struct sq_state_t {
 
31
        /**
 
32
         * The local queue state which other procs can modify.
 
33
         */
 
34
        struct {
 
35
          int dirty;      /**< whether a steal has occurred */
 
36
          int split;      /**< the split between head and tail */
 
37
          int tail;       /**< the tail of the queue */
 
38
          int size_shared;/**< the number of shared tasks in the queue */
 
39
        } ps;
 
40
        int vtail2;       /**< incremented after a steal completes */
 
41
      };
 
42
 
 
43
      const int max_ntsks;    /**< max number of tasks allowed in queue */
 
44
      const int tsk_size;     /**< size of a single task */
 
45
      char **q;               /**< addresses of queue data on all procs */
 
46
      sq_state_t **sq_state;  /**< addresses of queue state on all procs */
 
47
      int *head;              /**< pointer to this procs head_val */
 
48
      int *size_local;        /**< pointer to this procs size_local_val */
 
49
      int *vtail1;            /**< pointer to this procs vtail1_val */
 
50
      int *tail;              /**< pointer to this procs tail state */
 
51
      int *vtail2;            /**< pointer to this procs vtail2 state */
 
52
      int *size_shared;       /**< pointer to this procs size_shared state */
 
53
      int *split;             /**< pointer to this procs split state */
 
54
      int *dirty;             /**< pointer to this procs dirty state */
 
55
      int size_local_val;     /**< size of local portion of local queue */
 
56
      int head_val;           /**< index of the local queue's head */
 
57
      int vtail1_val;         /**< the true end index of the queue */
 
58
      TerminationDetector td; /**< the termination detector */
 
59
      int **locks;            /**< Locks for mutual exclusion */
 
60
 
 
61
      /**
 
62
       * Moves tasks from the shared portion to the local portion.
 
63
       *
 
64
       * @param[in] _nacquire number of tasks to move
 
65
       */
 
66
      int acquireFromShared(int _nacquire);
 
67
 
 
68
      /**
 
69
       * Moves tasks from the local portion to the shared portion.
 
70
       *
 
71
       * @param[in] ndonate number of tasks to move
 
72
       */
 
73
      void releaseToShared(int ndonate);
 
74
 
 
75
      /**
 
76
       * If all steal operations have completed, update vtail1.
 
77
       */
 
78
      void updateVtail1();
 
79
 
 
80
      /**
 
81
       * Returns true if the local queue is empty.
 
82
       */
 
83
      bool empty() const;
 
84
 
 
85
      /**
 
86
       * Returns true if the local queue is full.
 
87
       */
 
88
      bool full() const;
 
89
 
 
90
      /**
 
91
       * Returns true if this proc can add tasks to its local private portion.
 
92
       */
 
93
      bool spaceAvailable() const;
 
94
 
 
95
      /**
 
96
       * Obtain the lock (locks[proc])
 
97
       * @param[in] proc Process whose lock needs to be obainted
 
98
       * @param[in] num_tries If non-blocking lock, number of
 
99
       * attempts. Negative number results in a blocking call.  
 
100
       * @return true if locking succeeded
 
101
       */
 
102
      bool lock(int proc, int num_tries=-1);
 
103
 
 
104
      /**
 
105
       * Release the lock (locks[proc])
 
106
       * @param[in] proc Process whose lock needs to be released
 
107
       */
 
108
      void unlock(int proc);
 
109
      
 
110
    public:
 
111
 
 
112
      /**
 
113
       * Constructs the SplitQueueOpt instance.
 
114
       *
 
115
       * @param[in] tsk_size size of a single task
 
116
       * @param[in] max_ntsks max number of tasks allowed in a queue
 
117
       *
 
118
       * @pre tsk_size must be the same value on all procs
 
119
       * @pre max_ntsks must be the same value on all procs
 
120
       */
 
121
      SplitQueueOpt(int tsk_size, int max_ntsks);
 
122
 
 
123
      /**
 
124
       * Destroys the SplitQueue instance.
 
125
       */
 
126
      ~SplitQueueOpt();
 
127
 
 
128
      /**
 
129
       * Retrieves a task from the private portion of the local queue.
 
130
       *
 
131
       * @param[out] dscr the retrieved task
 
132
       * @param[in] dlen size of the retrieved task
 
133
       *
 
134
       * @pre dscr is not NULL
 
135
       * @pre dlen == tsk_size
 
136
       */
 
137
      bool getTask(void *dscr, int dlen);
 
138
 
 
139
      /**
 
140
       * Adds a task to the private portion of the local queue.
 
141
       *
 
142
       * @param[in] dscr the task to add
 
143
       * @param[in] dlen size of the added task
 
144
       *
 
145
       * @pre dscr is not NULL
 
146
       * @pre dlen == tsk_size
 
147
       */
 
148
      void addTask(void *dscr, int dlen);
 
149
 
 
150
      /**
 
151
       * Steals one or more tasks from the given proc's shared portion.
 
152
       *
 
153
       * @param[in] proc to steal from
 
154
       */
 
155
      bool steal(int proc);
 
156
 
 
157
      /**
 
158
       * Returns true if all of the tasks have been processed.
 
159
       */
 
160
      bool hasTerminated();
 
161
 
 
162
      /**
 
163
       * Returns the number of tasks in the entire local queue.
 
164
       */
 
165
      int numTasks() const {
 
166
        return *size_local + *size_shared;
 
167
      }
 
168
 
 
169
      /**
 
170
       * Runs the termination detector.
 
171
       */
 
172
      void td_progress();
 
173
 
 
174
  }; /* SplitQueueOpt */
 
175
}; /* tascel */
 
176
 
 
177
#endif /*__tascel_SplitQueueOpt_h__*/
 
178