NEURON
subworld.cpp
Go to the documentation of this file.
1
// included by ocbbs.cpp
2
3
void
BBSImpl::subworld_worker_execute
() {
4
// execute the same thing that execute_worker is executing. This
5
// is done for all the nrnmpi_myid_bbs == -1 workers associated with
6
// the specific nrnmpi_myid == 0 with nrnmpi_myid_bbs >= 0.
7
// All the nrnmpi/mpispike.cpp functions can be used since the
8
// proper communicators for a subworld are used by those functions.
9
// The broadcast functions are particularly useful and those are
10
// how execute_worker passes messages into here.
11
12
//printf("%d enter subworld_worker_execute\n", nrnmpi_myid_world);
13
int
info
[2];
14
// wait for something to do
15
nrnmpi_int_broadcast
(info, 2, 0);
16
// info[0] = -1 means it was from a pc.context. Also -2 means
17
// DONE.
18
//printf("%d subworld_worker_execute info %d %d\n", nrnmpi_myid_world, info[0], info[1]);
19
int
id
= info[0];
20
if
(
id
== -2) {
// DONE, so quit.
21
done
();
22
}
23
hoc_ac_
= double(
id
);
24
int
style = info[1];
25
if
(style == 0) {
// hoc statement form
26
int
size;
27
nrnmpi_int_broadcast
(&size, 1, 0);
// includes terminator
28
char
*
s
=
new
char
[size];
29
nrnmpi_char_broadcast
(s, size, 0);
30
hoc_obj_run
(s,
nil
);
31
delete
[]
s
;
32
//printf("%d leave subworld_worker_execute\n", nrnmpi_myid_world);
33
return
;
34
}
35
int
i
,
j
;
36
int
npickle;
37
char
*
s
;
38
Symbol
*
fname
= 0;
39
Object
* ob =
nil
;
40
char
*
sarg
[20];
// up to 20 arguments may be strings
41
int
ns = 0;
// number of args that are strings
42
int
narg
= 0;
// total number of args
43
44
if
(style == 3) {
// python callable
45
nrnmpi_int_broadcast
(&npickle, 1, 0);
46
s =
new
char
[npickle];
47
nrnmpi_char_broadcast
(s, npickle, 0);
48
}
else
if
(style == 1) {
// hoc function
49
int
size;
50
nrnmpi_int_broadcast
(&size, 1, 0);
// includes terminator
51
//printf("%d subworld hoc function string size = %d\n", nrnmpi_myid_world, size);
52
s =
new
char(size);
53
nrnmpi_char_broadcast
(s, size, 0);
54
fname =
hoc_lookup
(s);
55
if
(!fname) {
return
; }
// error raised by sender
56
}
else
{
57
return
;
// no others implemented, error raised by sender
58
}
59
60
// now get the args
61
int
argtypes;
62
nrnmpi_int_broadcast
(&argtypes, 1, 0);
63
//printf("%d subworld argtypes = %d\n", nrnmpi_myid_world, argtypes);
64
for
(j = argtypes; (i = j%5) != 0; j /= 5) {
65
++
narg
;
66
if
(i == 1) {
// double
67
double
x;
68
nrnmpi_dbl_broadcast
(&x, 1, 0);
69
//printf("%d subworld scalar = %g\n", nrnmpi_myid_world, x);
70
hoc_pushx
(x);
71
}
else
if
(i == 2) {
// string
72
int
size;
73
nrnmpi_int_broadcast
(&size, 1, 0);
74
sarg[ns] =
new
char(size);
75
nrnmpi_char_broadcast
(sarg[ns], size, 0);
76
hoc_pushstr
(sarg+ns);
77
ns++;
78
}
else
if
(i == 3) {
// Vector
79
int
n
;
80
nrnmpi_int_broadcast
(&n, 1, 0);
81
Vect
* vec =
new
Vect
(n);
82
nrnmpi_dbl_broadcast
(vec->data(),
n
, 0);
83
hoc_pushobj
(vec->temp_objvar());
84
}
else
{
// PythonObject
85
int
n
;
86
nrnmpi_int_broadcast
(&n, 1, 0);
87
char
*
s
;
88
s =
new
char
[
n
];
89
nrnmpi_char_broadcast
(s, n, 0);
90
Object
* po =
nrnpy_pickle2po
(s,
size_t
(n));
91
delete
[]
s
;
92
hoc_pushobj
(
hoc_temp_objptr
(po));
93
}
94
}
95
96
if
(style == 3) {
97
size_t
size;
98
char
* rs = (*nrnpy_callpicklef)(
s
, size_t(npickle),
narg
, &size);
99
assert
(rs);
100
delete
[] rs;
101
}
else
{
102
//printf("%d subworld hoc call %s narg=%d\n", nrnmpi_myid_world, fname->name, narg);
103
hoc_call_objfunc
(fname, narg, ob);
104
//printf("%d subworld return from hoc call %s\n", nrnmpi_myid_world, fname->name);
105
}
106
delete
[]
s
;
107
for
(i=0; i < ns; ++
i
) {
108
delete
[] sarg[
i
];
109
}
110
}
111
112
assert
#define assert(ex)
Definition:
hocassrt.h:26
hoc_pushobj
void hoc_pushobj(Object **d)
Definition:
code.cpp:647
sarg
static char * sarg
Definition:
nrnversion.cpp:17
Vect
#define Vect
Definition:
ivocvect.h:14
BBSImpl::done
virtual void done()
Definition:
bbs.cpp:484
nrnpy_pickle2po
Object *(* nrnpy_pickle2po)(char *, size_t size)
Definition:
ocbbs.cpp:36
hoc_lookup
Symbol * hoc_lookup(const char *)
nrnmpi_char_broadcast
static void nrnmpi_char_broadcast(char *, int, int)
Definition:
ocbbs.cpp:61
narg
static int narg()
Definition:
ivocvect.cpp:135
info
static List * info
Definition:
netrec_discon.cpp:64
n
int const size_t const size_t n
Definition:
nrngsl.h:12
s
_CONST char * s
Definition:
system.cpp:74
nrnmpi_int_broadcast
static void nrnmpi_int_broadcast(int *, int, int)
Definition:
ocbbs.cpp:60
fname
static const char * fname(const char *name)
Definition:
nrnbbs.cpp:108
BBSImpl::subworld_worker_execute
void subworld_worker_execute()
Definition:
subworld.cpp:3
j
size_t j
Definition:
nrngsl_real_radix2.cpp:56
Symbol
Definition:
model.h:57
nil
#define nil
Definition:
enter-scope.h:36
hoc_pushx
void hoc_pushx(double)
Object
Definition:
hocdec.h:226
hoc_obj_run
int hoc_obj_run(const char *, Object *)
Definition:
hoc_oop.cpp:323
i
#define i
Definition:
md1redef.h:12
nrnmpi_dbl_broadcast
static void nrnmpi_dbl_broadcast(double *, int, int)
Definition:
ocbbs.cpp:62
hoc_pushstr
void hoc_pushstr(char **d)
Definition:
code.cpp:665
hoc_ac_
double hoc_ac_
Definition:
hoc_init.cpp:261
hoc_call_objfunc
double hoc_call_objfunc(Symbol *s, int narg, Object *ob)
Definition:
hoc_oop.cpp:390
hoc_temp_objptr
Object ** hoc_temp_objptr(Object *)
Definition:
code.cpp:209
src
parallel
subworld.cpp