1 /********************* */
2 /*! \file portfolio_util.h
4 ** Original author: Kshitij Bansal
5 ** Major contributors: none
6 ** Minor contributors (to current version): Morgan Deters
7 ** This file is part of the CVC4 project.
8 ** Copyright (c) 2009-2014 New York University and The University of Iowa
9 ** See the file COPYING in the top-level source directory for licensing
10 ** information.\endverbatim
12 ** \brief Code relevant only for portfolio builds
15 #ifndef __CVC4__PORTFOLIO_UTIL_H
16 #define __CVC4__PORTFOLIO_UTIL_H
20 #include "base/output.h"
21 #include "expr/pickler.h"
22 #include "options/main_options.h"
23 #include "smt/smt_engine.h"
24 #include "smt_util/lemma_input_channel.h"
25 #include "smt_util/lemma_output_channel.h"
26 #include "util/channel.h"
30 typedef expr::pickle::Pickle ChannelFormat
;
32 class PortfolioLemmaOutputChannel
: public LemmaOutputChannel
{
35 SharedChannel
<ChannelFormat
>* d_sharedChannel
;
36 expr::pickle::MapPickler d_pickler
;
40 PortfolioLemmaOutputChannel(std::string tag
,
41 SharedChannel
<ChannelFormat
> *c
,
47 d_pickler(em
, to
, from
),
51 ~PortfolioLemmaOutputChannel() throw() { }
53 void notifyNewLemma(Expr lemma
);
54 };/* class PortfolioLemmaOutputChannel */
56 class PortfolioLemmaInputChannel
: public LemmaInputChannel
{
59 SharedChannel
<ChannelFormat
>* d_sharedChannel
;
60 expr::pickle::MapPickler d_pickler
;
63 PortfolioLemmaInputChannel(std::string tag
,
64 SharedChannel
<ChannelFormat
>* c
,
69 ~PortfolioLemmaInputChannel() throw() { }
74 };/* class PortfolioLemmaInputChannel */
76 std::vector
<Options
> parseThreadSpecificOptions(Options opts
);
79 void sharingManager(unsigned numThreads
,
80 SharedChannel
<T
> *channelsOut
[], // out and in with respect
81 SharedChannel
<T
> *channelsIn
[],
82 SmtEngine
*smts
[]) // to smt engines
84 Trace("sharing") << "sharing: thread started " << std::endl
;
85 std::vector
<int> cnt(numThreads
); // Debug("sharing")
87 std::vector
< std::queue
<T
> > queues
;
88 for(unsigned i
= 0; i
< numThreads
; ++i
){
89 queues
.push_back(std::queue
<T
>());
92 const unsigned int sharingBroadcastInterval
= 1;
94 boost::mutex mutex_activity
;
96 /* Disable interruption, so that we can check manually */
97 boost::this_thread::disable_interruption di
;
99 while(not boost::this_thread::interruption_requested()) {
101 boost::this_thread::sleep
102 (boost::posix_time::milliseconds(sharingBroadcastInterval
));
104 for(unsigned t
= 0; t
< numThreads
; ++t
) {
106 /* No activity on this channel */
107 if(channelsOut
[t
]->empty()) continue;
109 /* Alert if channel full, so that we increase sharingChannelSize
110 or decrease sharingBroadcastInterval */
111 assert(not channelsOut
[t
]->full());
113 T data
= channelsOut
[t
]->pop();
115 if(Trace
.isOn("sharing")) {
117 Trace("sharing") << "sharing: Got data. Thread #" << t
118 << ". Chunk " << cnt
[t
] << std::endl
;
121 for(unsigned u
= 0; u
< numThreads
; ++u
) {
123 Trace("sharing") << "sharing: adding to queue " << u
<< std::endl
;
124 queues
[u
].push(data
);
126 }/* end of inner for: broadcast activity */
128 } /* end of outer for: look for activity */
130 for(unsigned t
= 0; t
< numThreads
; ++t
){
131 /* Alert if channel full, so that we increase sharingChannelSize
132 or decrease sharingBroadcastInterval */
133 assert(not channelsIn
[t
]->full());
135 while(!queues
[t
].empty() && !channelsIn
[t
]->full()){
136 Trace("sharing") << "sharing: pushing on channel " << t
<< std::endl
;
137 T data
= queues
[t
].front();
138 channelsIn
[t
]->push(data
);
142 } /* end of infinite while */
145 << "sharing thread interrupted, interrupting all smtEngines" << std::endl
;
147 for(unsigned t
= 0; t
< numThreads
; ++t
) {
148 Trace("interrupt") << "Interrupting thread #" << t
<< std::endl
;
150 smts
[t
]->interrupt();
151 }catch(ModalException
&e
){
152 // It's fine, the thread is probably not there.
153 Trace("interrupt") << "Could not interrupt thread #" << t
<< std::endl
;
157 Trace("sharing") << "sharing: Interrupted, exiting." << std::endl
;
158 }/* sharingManager() */
160 }/* CVC4 namespace */
162 #endif /* __CVC4__PORTFOLIO_UTIL_H */