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_,
40  bbs_poll_cnt_,
41  ((bbs_poll_ < 0) ? -bbs_poll_ : bbs_poll_));
42 }
43 
45  int size;
46  int tag;
47  int source;
48  nrnmpi_probe(&size, &tag, &source);
49  handle1(size, tag, source);
50 }
51 
53  int size;
54  int tag;
55  int source;
56  if (nrnmpi_iprobe(&size, &tag, &source) != 0) {
57  do {
58  handle1(size, tag, source);
59  } while (nrnmpi_iprobe(&size, &tag, &source) != 0);
60  }
61 }
62 
63 void BBSDirectServer::handle1(int size, int tag, int cid) {
64  bbsmpibuf* recv;
65  bbsmpibuf* send;
66  char* key;
67  int index;
68  send = nil;
69  recv = nrnmpi_newbuf(size);
70  nrnmpi_ref(recv);
71  tag = nrnmpi_bbsrecv(cid, recv);
72  ++bbs_msg_cnt_;
73  if (size > 0) {
74  nrnmpi_upkbegin(recv);
75  }
76  switch (tag) {
77  case POST_TODO:
78  index = nrnmpi_getid(recv); // the parent index
79 #if debug
80  printf("handle POST_TODO from %x when cross=%g\n", cid, hoc_cross_x_);
81 #endif
83  break;
84  case POST_RESULT:
85  index = nrnmpi_getid(recv);
86 #if debug
87  printf("handle POST_RESULT %d from %x when cross=%g\n", index, cid, hoc_cross_x_);
88 #endif
90  break;
91  case POST:
92  key = nrnmpi_getkey(recv);
93 #if debug
94  printf("handle POST %s from %x when cross=%g\n", key, cid, hoc_cross_x_);
95 #endif
97  break;
98  case LOOK:
99  key = nrnmpi_getkey(recv);
100 #if debug
101  printf("handle LOOK %s from %x when cross=%g\n", key, cid, hoc_cross_x_);
102 #endif
104  nrnmpi_bbssend(cid, LOOK_YES, send);
105  nrnmpi_unref(send);
106  } else {
107  nrnmpi_bbssend(cid, LOOK_NO, nil);
108  }
109  break;
110  case LOOK_TAKE:
111  key = nrnmpi_getkey(recv);
112 #if debug
113  printf("handle LOOK_TAKE %s from %x when cross=%g\n", key, cid, hoc_cross_x_);
114 #endif
116 #if debug
117  printf("handle sending back something\n");
118 #endif
119  nrnmpi_bbssend(cid, LOOK_TAKE_YES, send);
120  nrnmpi_unref(send);
121  } else {
122  nrnmpi_bbssend(cid, LOOK_TAKE_NO, nil);
123  }
124  break;
125  case TAKE:
126  key = nrnmpi_getkey(recv);
127 #if debug
128  printf("handle TAKE %s from %x when cross=%g\n", key, cid, hoc_cross_x_);
129 #endif
131 #if debug
132  printf("handle sending back something\n");
133 #endif
134  nrnmpi_bbssend(cid, TAKE, send);
135  nrnmpi_unref(send);
136  } else {
137 #if debug
138  printf("handle put_pending %s for %d\n", key, cid);
139 #endif
141  }
142  break;
143  case LOOK_TAKE_TODO:
144 #if debug
145  printf("handle LOOK_TAKE_TODO for cid=%x\n", cid);
146 #endif
148 #if debug
149  printf("handle sending back id=%d\n", index);
150 #endif
151  nrnmpi_bbssend(cid, index + 1, send);
152  if (index) {
153  nrnmpi_unref(send);
154  }
155  break;
156  case LOOK_TAKE_RESULT:
157  index = nrnmpi_getid(recv);
158 #if debug
159  printf("handle LOOK_TAKE_RESULT for %x pid=%d\n", cid, index);
160 #endif
162 #if debug
163  printf("handle sending back id=%d\n", index);
164 #endif
165  nrnmpi_bbssend(cid, index + 1, send);
166  if (index) {
167  nrnmpi_unref(send);
168  }
169  break;
170  case TAKE_TODO:
171 #if debug
172  printf("handle TAKE_TODO for %x\n", cid);
173 #endif
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
#define nil
Definition: enter-scope.h:36
#define POST_TODO
Definition: bbssrv.h:14
#define LOOK_TAKE_RESULT
Definition: bbssrv.h:17
#define LOOK_TAKE_NO
Definition: bbssrv.h:12
#define TAKE
Definition: bbssrv.h:8
#define TAKE_TODO
Definition: bbssrv.h:18
#define LOOK_TAKE
Definition: bbssrv.h:7
#define LOOK
Definition: bbssrv.h:6
#define LOOK_NO
Definition: bbssrv.h:10
#define POST_RESULT
Definition: bbssrv.h:15
#define POST
Definition: bbssrv.h:5
#define HELLO
Definition: bbssrv.h:13
#define LOOK_YES
Definition: bbssrv.h:9
#define LOOK_TAKE_TODO
Definition: bbssrv.h:16
#define LOOK_TAKE_YES
Definition: bbssrv.h:11
void bbs_handle()
Definition: bbssrvmpi.cpp:209
short index
Definition: cabvars.h:10
int look_take_result(int parentid)
void add_looking_todo(int cid)
bool look(const char *key)
bool look_take(const char *key)
static void handle()
void post_todo(int parentid, int cid)
void post(const char *key)
void put_pending(const char *key, int cid)
static void handle1()
static BBSDirectServer * server_
Definition: bbslsrv2.h:18
bool send_context(int cid)
int remaining_context_cnt_
Definition: bbslsrv2.h:37
void post_result(int id)
static void handle_block()
void send(const char *url)
Definition: hel2mos.cpp:214
double hoc_cross_x_
Definition: hoc_init.cpp:401
int bbs_poll_
Definition: datapath.cpp:31
#define printf
Definition: mwprefix.h:26
int nrnmpi_numprocs_bbs
#define key
Definition: spt2queue.cpp:20