Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/vis15/src/lib/include/diderot/parallel.hxx
ViewVC logotype

Annotation of /branches/vis15/src/lib/include/diderot/parallel.hxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4797 - (view) (download) (as text)

1 : jhr 4180 /*! \file parallel.hxx
2 :     *
3 :     * \author John Reppy
4 :     */
5 :    
6 :     /*
7 :     * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
8 :     *
9 :     * COPYRIGHT (c) 2016 The University of Chicago
10 :     * All rights reserved.
11 :     */
12 :    
13 :     #ifndef _DIDEROT_PARALLEL_HXX_
14 :     #define _DIDEROT_PARALLEL_HXX_
15 :    
16 :     #ifndef DIDEROT_TARGET_PARALLEL
17 :     # error "parallel.hxx included but target is not parallel"
18 :     #endif
19 :    
20 :     #ifndef _DIDEROT_BASE_HXX_
21 :     #include "base.hxx"
22 :     #endif
23 :     #ifndef _DIDEROT_WORLD_HXX_
24 :     #include "world.hxx"
25 :     #endif
26 :    
27 : jhr 4770 #include <atomic>
28 :    
29 :     typedef std::atomic<uint32_t> atomic_uint32_t;
30 :    
31 : jhr 4180 #include <pthread.h>
32 : jhr 4637 #include "barrier.hxx"
33 : jhr 4797 #include "worker-gate.hxx"
34 : jhr 4180
35 :     namespace diderot {
36 :    
37 :     struct scheduler {
38 : jhr 4637 using task = void (*)(void *);
39 : jhr 4797
40 :     struct worker_info {
41 :     uint32_t _id; //!< index into thread _info[] array
42 :     world_base *_wrld; //!< world pointer
43 :     scheduler *_sched; //!< scheduler data pointer
44 :     void *_data; //!< per-worker data pointer for current task
45 :     };
46 :    
47 : jhr 4637 // information about the available CPUs
48 : jhr 4351 int _numHWNodes; //!< \brief number of (possibly multicore) processors
49 :     int _numHWCores; //!< \brief total number of (possibly
50 :     //! mulithreaded) cores
51 :     int _numHWThreads; //!< \brief total number of hardware threads
52 :     int _numCoresPerNode; //!< \brief number of cores per thread
53 :     int _numThdsPerCore; //!< \brief number of threads per core
54 : jhr 4637
55 : jhr 4797 uint32_t _numWorkers; //!< number of worker threads in the pool; this is
56 :     //! decremented as workers terminate
57 : jhr 4637 pthread_t *_workers; //!< thread IDs of workers
58 : jhr 4797 worker_info *_info; //!< per-thread info structure
59 : jhr 4637 task _task; //!< holds current task for workers
60 : jhr 4351 uint32_t _workSize; //!< size of a block of work
61 : jhr 4637 bool _done; //!< flag to signal that the program is done.
62 :    
63 : jhr 4797 pthread_mutex_t _lock; //!< lock to protect _runWait
64 :     pthread_cond_t _runWait; //!< used by workers to signal termination
65 :     worker_gate _gate; //!< gate for coordinator/worker synchronization
66 :     barrier _coordBar; //!< barrier for coordinating between workers and
67 :     //!< coordinator thread
68 :     barrier _bspBar; //!< barrier to implement BSP semantics
69 : jhr 4637
70 : jhr 4351 scheduler ();
71 :     ~scheduler ();
72 : jhr 4180
73 :     //! \brief get information about the host CPU configuration
74 :     //! \return true if there is an error
75 : jhr 4351 bool get_cpu_info (world_base *wrld);
76 : jhr 4180
77 : jhr 4797 //! \brief create the pool of workers
78 :     //! \param wrld thw world
79 :     //! \param nw the requested number of workers.
80 :     //! \return true if there is an error
81 :     bool create_workers (world_base *wrld, uint32_t nw);
82 : jhr 4180
83 : jhr 4797 //! \brief shut down the workers
84 :     void shutdown ();
85 :    
86 : jhr 4637 };
87 :    
88 : jhr 4180 } // namespace diderot
89 :    
90 :     #endif //! _DIDEROT_PARALLEL_HXX_

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0