1 #include <../../nrnconf.h>
18 #if defined(HAVE_SSTREAM)
31 #define MessageList MpiMessageList
32 #define WorkItem MpiWorkItem
33 #define WorkList MpiWorkList
34 #define ReadyList MpiReadyList
35 #define ResultList MpiResultList
36 #define PendingList MpiPendingList
37 #define LookingToDoList MpiLookingToDoList
41 WorkItem(
int id, bbsmpibuf*
buf,
int cid);
47 bool todo_less_than(
const WorkItem*)
const;
51 bool operator()(
const char* s1,
const char* s2)
const {
52 return strcmp(s1, s2) < 0;
57 bool operator()(
int i,
int j)
const {
63 bool operator()(
const WorkItem* w1,
const WorkItem* w2)
const {
64 return w1->todo_less_than(w2);
68 static char* newstr(
const char* s) {
69 char* s1 =
new char[strlen(s) + 1];
74 WorkItem::WorkItem(
int id, bbsmpibuf*
buf,
int cid) {
76 printf(
"WorkItem %d\n",
id);
84 WorkItem::~WorkItem() {
90 bool WorkItem::todo_less_than(
const WorkItem* w)
const {
91 WorkItem* w1 = (WorkItem*)
this;
92 WorkItem* w2 = (WorkItem*) w;
93 while (w1->parent_ != w2->parent_) {
94 if (w1->id_ < w2->id_) {
101 printf(
"todo_less_than %d < %d return %d\n", this->
id_, w->id_, w1->id_ < w2->id_);
103 return w1->id_ < w2->id_;
106 class MessageList:
public std::multimap<const char*, bbsmpibuf*, ltstr> {};
107 class PendingList:
public std::multimap<const char*, const int, ltstr> {};
109 class LookingToDoList:
public std::set<int, ltint> {};
110 class ReadyList:
public std::set<const WorkItem*, ltWorkItem> {};
111 class ResultList:
public std::multimap<int, const WorkItem*, ltint> {};
114 class PendingList {};
116 class LookingToDoList {};
122 #if defined(HAVE_STL)
137 #if defined(HAVE_STL)
141 printf(
"~BBSLocalServer not deleting everything\n");
152 printf(
"DirectServer::look_take |%s|\n",
key);
155 #if defined(HAVE_STL)
163 char* s = (
char*) ((*m).first);
168 printf(
"DirectServer::look_take |%s| recv=%p return %d\n",
key, (*recv), b);
176 printf(
"DirectServer::look |%s|\n",
key);
181 #if defined(HAVE_STL)
191 printf(
"DirectServer::look |%s| recv=%p return %d\n",
key, (*recv), b);
198 #if defined(HAVE_STL)
200 printf(
"put_pending |%s| %d\n",
key, cid);
202 char* s = newstr(
key);
203 pending_->insert(std::pair<const char* const, const int>(s, cid));
209 #if defined(HAVE_STL)
214 printf(
"take_pending |%s| %d\n",
key, *cid);
216 char* s = (
char*) ((*p).first);
226 #if defined(HAVE_STL)
234 MessageList::iterator m =
messages_->insert(
235 std::pair<const char* const, bbsmpibuf*>(newstr(
key),
send));
242 #if defined(HAVE_STL)
248 #if defined(HAVE_STL)
250 printf(
"BBSDirectServer::post_todo pid=%d cid=%d send=%p\n", pid, cid,
send);
254 WorkList::iterator
p =
work_->find(pid);
256 w->parent_ = (WorkItem*) ((*p).second);
258 work_->insert(std::pair<const int, const WorkItem*>(w->id_, w));
260 printf(
"work insert %d\n", w->id_);
267 nrnmpi_bbssend(cid, w->id_ + 1,
send);
278 #if defined(HAVE_STL)
284 for (
j = 0;
j < 1000; ++
j) {
291 Printf(
"some workers did not receive previous context\n");
305 printf(
"sending context to already waiting %d\n", cid);
336 #if defined(HAVE_STL)
341 printf(
"sending context to %d\n", cid);
355 #if defined(HAVE_STL)
357 printf(
"DirectServer::post_result id=%d send=%p\n",
id,
send);
359 WorkList::iterator
i =
work_->find(
id);
360 WorkItem* w = (WorkItem*) ((*i).second);
362 nrnmpi_unref(w->buf_);
364 results_->insert(std::pair<const int, const WorkItem*>(w->parent_ ? w->parent_->id_ : 0, w));
369 #if defined(HAVE_STL)
371 printf(
"DirectServer::look_take_todo\n");
375 ReadyList::iterator
i =
todo_->begin();
377 WorkItem* w = (WorkItem*) (*
i);
381 printf(
"DirectServer::look_take_todo recv %p with keypos=%d return %d\n",
398 printf(
"DirectServer::look_take_result pid=%d\n", pid);
400 #if defined(HAVE_STL)
403 ResultList::iterator
i =
results_->find(pid);
405 WorkItem* w = (WorkItem*) ((*i).second);
409 WorkList::iterator
j =
work_->find(
id);
413 printf(
"DirectServer::look_take_result recv=%p return %d\n", *recv,
id);
int look_take_result(int parentid)
void add_looking_todo(int cid)
bool look(const char *key)
void context(int ncid, int *cids)
bool look_take(const char *key)
MpiLookingToDoList * looking_todo_
void post_todo(int parentid, int cid)
void post(const char *key)
void put_pending(const char *key, int cid)
MpiLookingToDoList * send_context_
virtual ~BBSDirectServer()
static BBSDirectServer * server_
MpiMessageList * messages_
MpiPendingList * pending_
bool send_context(int cid)
bool take_pending(const char *key, int *cid)
int remaining_context_cnt_
void send(const char *url)
void nrnbbs_context_wait()
static double map(void *v)