NEURON
bbssrvmpi.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #include "bbsconf.h"
3 #include <nrnmpi.h>
4 #ifdef NRNMPI // to end of file
5 #include <stdio.h>
6 #include <unistd.h>
7 #include "bbssrv2mpi.h"
8 #include "bbssrv.h"
9 
10 #define debug 0
11 
12 #define POLLCNT 300
13 extern int bbs_poll_;
14 void bbs_handle();
15 extern double hoc_cross_x_;
16 
17 static int bbs_poll_cnt_;
18 static int bbs_msg_cnt_;
19 
20 void bbs_handle() {
22  bbs_poll_ = POLLCNT;
23  }else{
24  bbs_poll_ = -1;
25  return;
26  }
27  ++bbs_poll_cnt_;
29 }
30 
32  if (nrnmpi_numprocs_bbs > 1) {
33  bbs_poll_ = POLLCNT;
34  }
35 }
36 void BBSDirectServer::done() {
37  return;
38  printf("bbs_msg_cnt_=%d bbs_poll_cnt_=%d bbs_poll_=%d\n",
39  bbs_msg_cnt_, bbs_poll_cnt_,
40  ((bbs_poll_ < 0) ? -bbs_poll_ : bbs_poll_));
41 }
42 
44  int size;
45  int tag;
46  int source;
47  nrnmpi_probe(&size, &tag, &source);
48  handle1(size, tag, source);
49 }
50 
52  int size;
53  int tag;
54  int source;
55  if (nrnmpi_iprobe(&size, &tag, &source) != 0) {
56  do {
57  handle1(size, tag, source);
58  } while (nrnmpi_iprobe(&size, &tag, &source) != 0);
59  }
60 }
61 
62 void BBSDirectServer::handle1(int size, int tag, int cid) {
63  bbsmpibuf* recv;
64  bbsmpibuf* send;
65  char* key;
66  int index;
67  send = nil;
68  recv = nrnmpi_newbuf(size);
69  nrnmpi_ref(recv);
70  tag = nrnmpi_bbsrecv(cid, recv);
71  ++bbs_msg_cnt_;
72  if (size > 0) {
73  nrnmpi_upkbegin(recv);
74  }
75  switch (tag) {
76  case POST_TODO:
77  index = nrnmpi_getid(recv); // the parent index
78 #if debug
79 printf("handle POST_TODO from %x when cross=%g\n", cid, hoc_cross_x_);
80 #endif
81  BBSDirectServer::server_->post_todo(index, cid, recv);
82  break;
83  case POST_RESULT:
84  index = nrnmpi_getid(recv);
85 #if debug
86 printf("handle POST_RESULT %d from %x when cross=%g\n", index, cid, hoc_cross_x_);
87 #endif
89  break;
90  case POST:
91  key = nrnmpi_getkey(recv);
92 #if debug
93 printf("handle POST %s from %x when cross=%g\n", key, cid, hoc_cross_x_);
94 #endif
95  BBSDirectServer::server_->post(key, recv);
96  break;
97  case LOOK:
98  key = nrnmpi_getkey(recv);
99 #if debug
100 printf("handle LOOK %s from %x when cross=%g\n", key, cid, hoc_cross_x_);
101 #endif
102  if (BBSDirectServer::server_->look(key, &send)) {
103  nrnmpi_bbssend(cid, LOOK_YES, send);
104  nrnmpi_unref(send);
105  }else{
106  nrnmpi_bbssend(cid, LOOK_NO, nil);
107  }
108  break;
109  case LOOK_TAKE:
110  key = nrnmpi_getkey(recv);
111 #if debug
112 printf("handle LOOK_TAKE %s from %x when cross=%g\n", key, cid, hoc_cross_x_);
113 #endif
114  if (BBSDirectServer::server_->look_take(key, &send)) {
115 #if debug
116 printf("handle sending back something\n");
117 #endif
118  nrnmpi_bbssend(cid, LOOK_TAKE_YES, send);
119  nrnmpi_unref(send);
120  }else{
121  nrnmpi_bbssend(cid, LOOK_TAKE_NO, nil);
122  }
123  break;
124  case TAKE:
125  key = nrnmpi_getkey(recv);
126 #if debug
127 printf("handle TAKE %s from %x when cross=%g\n", key, cid, hoc_cross_x_);
128 #endif
129  if (BBSDirectServer::server_->look_take(key, &send)) {
130 #if debug
131 printf("handle sending back something\n");
132 #endif
133  nrnmpi_bbssend(cid, TAKE, send);
134  nrnmpi_unref(send);
135  }else{
136 #if debug
137 printf("handle put_pending %s for %d\n", key, cid);
138 #endif
140  }
141  break;
142  case LOOK_TAKE_TODO:
143 #if debug
144 printf("handle LOOK_TAKE_TODO for cid=%x\n", cid);
145 #endif
147 #if debug
148 printf("handle sending back id=%d\n", index);
149 #endif
150  nrnmpi_bbssend(cid, index+1, send);
151  if (index) {
152  nrnmpi_unref(send);
153  }
154  break;
155  case LOOK_TAKE_RESULT:
156  index = nrnmpi_getid(recv);
157 #if debug
158 printf("handle LOOK_TAKE_RESULT for %x pid=%d\n", cid, index);
159 #endif
160  index = BBSDirectServer::server_->look_take_result(index, &send);
161 #if debug
162 printf("handle sending back id=%d\n", index);
163 #endif
164  nrnmpi_bbssend(cid, index+1, send);
165  if (index) {
166  nrnmpi_unref(send);
167  }
168  break;
169  case TAKE_TODO:
170 #if debug
171 printf("handle TAKE_TODO for %x\n", cid);
172 #endif
174  && server_->send_context(cid)) {
175 #if debug
176 printf("handle sent back a context\n");
177 #endif
178  break;
179  }
181  if (index) {
182 #if debug
183 printf("handle sending back id=%d\n", index);
184 #endif
185  nrnmpi_bbssend(cid, index+1, send);
186  nrnmpi_unref(send);
187  }else{
188 #if debug
189 printf("handle add_looking_todo\n");
190 #endif
192  }
193  break;
194  case HELLO:
195 #if debug
196 printf("handle HELLO from %x when cross=%g\n", cid, hoc_cross_x_);
197 #endif
198  nrnmpi_pkbegin(recv);
199  nrnmpi_enddata(recv);
200  nrnmpi_bbssend(cid, HELLO, recv);
201  break;
202  default:
203 printf("unknown message\n");
204  break;
205  }
206  nrnmpi_unref(recv);
207 }
208 #else
209 void bbs_handle(){}
210 #endif //NRNMPI
211 
int bbs_poll_
Definition: datapath.cpp:27
void post(const char *key)
static void handle()
bool look_take(const char *key)
#define TAKE
Definition: bbssrv.h:8
void bbs_handle()
Definition: bbssrvmpi.cpp:209
bool look(const char *key)
int nrnmpi_numprocs_bbs
#define LOOK_TAKE_RESULT
Definition: bbssrv.h:17
static BBSDirectServer * server_
Definition: bbslsrv2.h:18
static void handle_block()
bool send_context(int cid)
void put_pending(const char *key, int cid)
#define printf
Definition: mwprefix.h:26
static void handle1()
#define TAKE_TODO
Definition: bbssrv.h:18
#define key
Definition: spt2queue.cpp:20
#define POST_TODO
Definition: bbssrv.h:14
#define nil
Definition: enter-scope.h:36
#define LOOK_TAKE
Definition: bbssrv.h:7
void send(const char *url)
Definition: hel2mos.cpp:212
#define HELLO
Definition: bbssrv.h:13
#define POST
Definition: bbssrv.h:5
#define LOOK_TAKE_YES
Definition: bbssrv.h:11
void post_result(int id)
double hoc_cross_x_
Definition: hoc_init.cpp:265
#define LOOK_TAKE_TODO
Definition: bbssrv.h:16
int look_take_result(int parentid)
#define LOOK_NO
Definition: bbssrv.h:10
int remaining_context_cnt_
Definition: bbslsrv2.h:35
#define LOOK_TAKE_NO
Definition: bbssrv.h:12
#define LOOK_YES
Definition: bbssrv.h:9
#define POST_RESULT
Definition: bbssrv.h:15
void post_todo(int parentid, int cid)
short index
Definition: cabvars.h:11
void add_looking_todo(int cid)
#define LOOK
Definition: bbssrv.h:6