NCBI C++ ToolKit
blast_node.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: blast_node.hpp 100101 2023-06-15 14:10:29Z merezhuk $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Amelia Fong
27  *
28  */
29 
30 /** @file blast_node.hpp
31  * BLAST node api
32  */
33 
34 #ifndef ALGO_BLAST_API___BLAST_NODE__HPP
35 #define ALGO_BLAST_API___BLAST_NODE__HPP
36 
39 
41 BEGIN_SCOPE(blast)
42 
44 {
45 public:
46  enum EMsgType {
50  ePostLog
51  };
52  CBlastNodeMsg(EMsgType type, void * obj_ptr): m_MsgType(type), m_Obj(obj_ptr) {}
53  EMsgType GetMsgType() { return m_MsgType; }
54  void * GetMsgBody() { return m_Obj; }
55 private:
57  void * m_Obj;
58 };
59 
61 {
62 public:
63  CBlastNodeMailbox(int node_num, CConditionVariable & notify): m_NodeNum(node_num), m_Notify(notify){}
64  void SendMsg(CRef<CBlastNodeMsg> msg);
66  {
67  CFastMutexGuard guard(m_Mutex);
69  if (! m_MsgQueue.empty()){
70  rv.Reset(m_MsgQueue.front());
71  m_MsgQueue.pop_front();
72  }
73  return rv;
74  }
75  void UnreadMsg(CRef<CBlastNodeMsg> msg) { CFastMutexGuard guard(m_Mutex); m_MsgQueue.push_front(msg);}
76  int GetNumMsgs () { CFastMutexGuard guard(m_Mutex); return static_cast<int>(m_MsgQueue.size()); }
77  int GetNodeNum() { return m_NodeNum; }
78  ~CBlastNodeMailbox() { m_MsgQueue.resize(0); }
79 private:
80  int m_NodeNum;
82  list <CRef<CBlastNodeMsg> > m_MsgQueue;
84 };
85 
87 {
88 public :
89  enum EState {
94  };
95  CBlastNode (int node_num, const CNcbiArguments & ncbi_args, const CArgs& args,
96  CBlastAppDiagHandler & bah, int query_index, int num_queries, CBlastNodeMailbox * mailbox);
97 
98  virtual int GetBlastResults(CNcbiOstream & os) = 0;
99  int GetNodeNum() { return m_NodeNum;}
100  EState GetState() { return m_State; }
101  int GetStatus() { return m_Status; }
102  const CArgs & GetArgs() { return m_Args; }
103  CBlastAppDiagHandler & GetDiagHandler() { return m_Bah; }
104  const CNcbiArguments & GetArguments() { return m_NcbiArgs; }
105  void SendMsg(CBlastNodeMsg::EMsgType msg_type, void* ptr = NULL);
106  string & GetNodeIdStr() { return m_NodeIdStr;}
107  int GetNumOfQueries() {return m_NumOfQueries;}
108  int GetQueriesLength() {return m_QueriesLength;}
109 protected:
110  virtual ~CBlastNode(void);
111  virtual void* Main(void) = 0;
112  void SetState(EState state) { m_State = state; }
113  void SetStatus(int status) { m_Status = status; }
114  void SetQueriesLength(int l) { m_QueriesLength = l;}
115  void SetDataLoaderPrefix();
117 private:
119  const CArgs & m_Args;
123  string m_NodeIdStr;
126  int m_Status;
129 };
130 
131 
133 {
134 public:
135  CBlastMasterNode(CNcbiOstream & out_stream, int num_threads);
140  void RegisterNode(CBlastNode * node, CBlastNodeMailbox * mailbox);
141  int GetNumNodes() { return static_cast<int>(m_RegisteredNodes.size());}
142  int IsFull();
143  void Shutdown() { m_MaxNumNodes = -1; }
144  bool Processing();
145  int IsActive()
146  {
147  if ((m_MaxNumNodes < 0) && (m_RegisteredNodes.size() == 0)){
148  return false;
149  }
150  return true;
151  }
152  void FormatResults();
153  CConditionVariable & GetBuzzer() {return m_NewEvent;}
155  int GetNumOfQueries() { return m_NumQueries; }
156  Int8 GetQueriesLength() { return m_QueriesLength; }
157  int GetNumErrStatus() { return m_NumErrStatus; }
158 private:
159  void x_WaitForNewEvent();
160 
174 };
175 
176 
178 {
179 public:
180 
181  CBlastNodeInputReader(CNcbiIstream& is, int batch_size, int est_avg_len) :
182  CStreamLineReader(is), m_QueryBatchSize(batch_size), m_EstAvgQueryLength(est_avg_len), m_QueryCount(0) {}
183 
184  int GetQueryBatch(string & queries, int & query_no);
185 
186 private:
187  const int m_QueryBatchSize;
190 };
191 
192 END_SCOPE(blast)
194 
195 #endif /* ALGO_BLAST_API___BLAST_NODE__HPP */
Contains C++ wrapper classes to structures in algo/blast/core as well as some auxiliary functions to ...
Defines to provide correct exporting from BLAST DLL in Windows.
#define NCBI_XBLAST_EXPORT
NULL operations for other cases.
Definition: blast_export.h:65
CArgs –.
Definition: ncbiargs.hpp:379
Class to capture message from diag handler.
Definition: blast_aux.hpp:249
CFastMutex m_Mutex
Definition: blast_node.hpp:164
TActiveNodes m_ActiveNodes
Definition: blast_node.hpp:168
CConditionVariable m_NewEvent
Definition: blast_node.hpp:170
map< int, CRef< CBlastNode > > TRegisteredNodes
Definition: blast_node.hpp:137
Int8 GetQueriesLength()
Definition: blast_node.hpp:156
CStopWatch m_StopWatch
Definition: blast_node.hpp:165
CConditionVariable & GetBuzzer()
Definition: blast_node.hpp:153
map< int, CRef< CBlastNodeMailbox > > TPostOffice
Definition: blast_node.hpp:136
map< int, CRef< CBlastNodeMsg > > TFormatQueue
Definition: blast_node.hpp:139
TPostOffice m_PostOffice
Definition: blast_node.hpp:166
TRegisteredNodes m_RegisteredNodes
Definition: blast_node.hpp:167
map< int, double > TActiveNodes
Definition: blast_node.hpp:138
TFormatQueue m_FormatQueue
Definition: blast_node.hpp:169
CNcbiOstream & m_OutputStream
Definition: blast_node.hpp:161
const int m_QueryBatchSize
Definition: blast_node.hpp:187
const int m_EstAvgQueryLength
Definition: blast_node.hpp:188
CBlastNodeInputReader(CNcbiIstream &is, int batch_size, int est_avg_len)
Definition: blast_node.hpp:181
CFastMutex m_Mutex
Definition: blast_node.hpp:83
list< CRef< CBlastNodeMsg > > m_MsgQueue
Definition: blast_node.hpp:82
void UnreadMsg(CRef< CBlastNodeMsg > msg)
Definition: blast_node.hpp:75
CBlastNodeMailbox(int node_num, CConditionVariable &notify)
Definition: blast_node.hpp:63
CConditionVariable & m_Notify
Definition: blast_node.hpp:81
CRef< CBlastNodeMsg > ReadMsg()
Definition: blast_node.hpp:65
CBlastNodeMsg(EMsgType type, void *obj_ptr)
Definition: blast_node.hpp:52
EMsgType m_MsgType
Definition: blast_node.hpp:56
EMsgType GetMsgType()
Definition: blast_node.hpp:53
void * GetMsgBody()
Definition: blast_node.hpp:54
EState m_State
Definition: blast_node.hpp:125
EState GetState()
Definition: blast_node.hpp:100
const CArgs & m_Args
Definition: blast_node.hpp:119
string m_NodeIdStr
Definition: blast_node.hpp:123
virtual int GetBlastResults(CNcbiOstream &os)=0
string m_DataLoaderPrefix
Definition: blast_node.hpp:128
virtual void * Main(void)=0
Derived (user-created) class must provide a real thread function.
CBlastAppDiagHandler & m_Bah
Definition: blast_node.hpp:120
const CArgs & GetArgs()
Definition: blast_node.hpp:102
int m_QueriesLength
Definition: blast_node.hpp:127
CRef< CBlastNodeMailbox > m_Mailbox
Definition: blast_node.hpp:124
CBlastAppDiagHandler & GetDiagHandler()
Definition: blast_node.hpp:103
int m_QueryIndex
Definition: blast_node.hpp:121
int GetNodeNum()
Definition: blast_node.hpp:99
int GetNumOfQueries()
Definition: blast_node.hpp:107
int GetStatus()
Definition: blast_node.hpp:101
const CNcbiArguments & m_NcbiArgs
Definition: blast_node.hpp:118
int m_NumOfQueries
Definition: blast_node.hpp:122
const CNcbiArguments & GetArguments()
Definition: blast_node.hpp:104
void SetState(EState state)
Definition: blast_node.hpp:112
void SetQueriesLength(int l)
Definition: blast_node.hpp:114
void SetStatus(int status)
Definition: blast_node.hpp:113
int GetQueriesLength()
Definition: blast_node.hpp:108
string & GetNodeIdStr()
Definition: blast_node.hpp:106
CFastMutex –.
Definition: ncbimtx.hpp:667
CNcbiArguments –.
Definition: ncbienv.hpp:236
CObject –.
Definition: ncbiobj.hpp:180
CStopWatch –.
Definition: ncbitime.hpp:1937
Simple implementation of ILineReader for i(o)streams.
Definition: map.hpp:338
#define NULL
Definition: ncbistd.hpp:225
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
Definition: type.c:6
Modified on Tue May 07 08:13:12 2024 by modify_doxy.py rev. 669887