/usr/share/nrn/lib/hoc/parcom.hoc is in neuron 7.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | {load_file("loadbal.hoc")}
{load_file("binfo.hoc")}
begintemplate ParallelComputeToolSplitInfo
public sec, psec, x, px, spsec, spx, sid, first
objref sec, psec, spsec
proc init() {
sec = new SectionRef()
sec.parent { psec = new SectionRef() }
x = section_orientation()
px = parent_connection()
// after splitting spsec connect sec(x), spx if spsec not nil
spx = -1
sid = -1
first = 0 // 1 if supposed to call multisplit on psec
}
endtemplate ParallelComputeToolSplitInfo
begintemplate ParallelComputeTool
public nthread, pthread, cache, busywait, multisplit, pinfo
public pct, box, map, np, save, nthread_, lb, printpart, move2part
public showshape
external cvode
objref this, pct, box, pc, lb, splitinfo_, shapeplot
strdef tstr, nprocstr, cxtotalstr, ldbalstr, npiecestr
proc init() {
pinfo = 0
np = 0
ispar_ = 1
multisplit_ = 0
ldbal_ = 1.0
cxtotal_ = 0
pc = new ParallelContext()
lb = new LoadBalance(pc)
nthread_ = pc.nthread()
pct = this
cacheeffic_ = cvode.cache_efficient()
busywait_ = 0
nprocstr = "?? useful processors"
totalcx()
ldbal()
build()
}
proc build() {
box = new VBox()
box.intercept(1)
box.ref(this)
box.save("save()")
xpanel("")
xvarlabel(nprocstr)
xvarlabel(cxtotalstr)
xvarlabel(npiecestr)
xvarlabel(ldbalstr)
xpvalue("# threads", &nthread_, 1, "change_nthread(nthread_, ispar_)")
xcheckbox("Thread Parallel", &ispar_, "change_nthread(nthread_, ispar_)")
xcheckbox("Cache Efficient", &cacheeffic_, "cacheeffic(cacheeffic_)")
xcheckbox("Use busy waiting", &busywait_, "busywait(busywait_)")
xcheckbox("Multisplit", &multisplit_, "multisplit(multisplit_)")
xbutton("Refresh", "howmany() totalcx() ldbal()")
xpanel()
box.intercept(0)
}
proc map() {
if (box.ismapped) return
sprint(tstr, "%s", this)
if (numarg() > 1) {
box.map(tstr, $2, $3, $4, $5)
}else{
box.map(tstr)
}
}
proc save() {
box.save("load_file(\"parcom.hoc\", \"ParallelComputeTool\")\n}")
box.save("{ocbox_ = ParallelComputeTool[0]}")
box.save("{object_push(ocbox_)}")
sprint(tstr, "{change_nthread(%d, %d)}", nthread_, ispar_)
box.save(tstr)
if (multisplit_) {box.save("{multisplit(1)}")}
if (multisplit_ == 0 && cacheeffic_) {box.save("{cacheeffic(1)}")}
if (busywait_) {box.save("{busywait(1)}")}
box.save("{object_pop()}")
box.save("{\n")
}
proc printpart() {local i
for i=0, pc.nthread - 1 {
forsec lb.slthread[i] print secname(), " ", pc.sec_in_thread
}
}
proc move2part() {local i
i = pc.sec_in_thread
lb.slthread[i].remove()
lb.slthread[$1].append()
for i=0, pc.nthread-1 {
pc.partition(i, lb.slthread[i])
}
}
proc howmany() {
np = pc.thread_how_many_proc()
if (np == 1) {
sprint(nprocstr, "%d useful processor", np)
}else{
sprint(nprocstr, "%d useful processors", np)
}
}
proc totalcx() {
cxtotal_ = lb.cpu_complexity()
sprint(cxtotalstr, "Total model complexity: %g", cxtotal_)
}
proc ldbal() {
lb.thread_partition(pinfo)
ldbal_ = lb.thread_cxbal_
sprint(npiecestr, "%d pieces", lb.npiece_)
sprint(ldbalstr, "Load imbalance: %.1f%%", (ldbal_ - 1)*100)
}
proc cacheeffic() {
if (!multisplit_) {
cvode.cache_efficient($1)
}
cacheeffic_ = cvode.cache_efficient()
}
proc busywait() {
if (!ispar_) {$1 = 0}
if ($1 == 1 && np == 0) { howmany() }
if (nthread_ > np) {
$1 = 0
}
pc.thread_busywait($1)
busywait_ = $1
}
func nthread() {
if (numarg()) {
change_nthread($1, ispar_)
}
return nthread_
}
func pthread() {
if (numarg()) {
change_nthread(nthread_, $1)
}
return ispar_
}
func cache() {
if (numarg()) {
cache_effic($1)
}
return cacheeffic_
}
proc change_nthread() {local ms
ms = multisplit_
if (ms) {
unsplit()
}
nthread_ = $1
ispar_ = $2
pc.nthread(nthread_, ispar_)
if (ms) {
multisplit(ms)
}
totalcx()
ldbal()
busywait(busywait_)
}
proc multisplit() {
multisplit_ = $1
if (multisplit_) {
use_thread()
}else{
unsplit()
lb = new LoadBalance(pc)
totalcx()
ldbal()
}
}
proc use_thread() {local cx, cellx localobj b, ms, vs, cb, nc, nil, roots
pc.partition()
lb = new LoadBalance(pc)
cxtotal_ = lb.cpu_complexity()
cx = cxtotal_*0.3/nthread_
ms = new Vector(100)
roots = new SectionList()
roots.allroots()
splitinfo_ = new List() // list of list of ParallelComputeToolSplitInfo
forsec roots {
cellx = lb.cell_complexity()
lb.multisplit(0, cx, ms)
vs = new VectorStream(ms)
splitinfo(vs, lb.srlist)
split()
}
cxtotal_ = lb.cpu_complexity()
ldbal()
pc.multisplit()
cacheeffic_ = cvode.cache_efficient()
multisplit_ = 1
}
proc splitinfo() {local gid, cx, nsid, isid, nsub, isub, n, i, id \
localobj si, si0, sil
sil = new List()
splitinfo_.append(sil)
gid = $o1.scanvar
cx = $o1.scanvar
nsid = $o1.scanvar
// printf("%d %g %d\n", gid, cx, nsid)
for isid = 0, nsid - 1 {
// printf(" %d\n", isid)
nsub = $o1.scanvar
for isub = 0, nsub - 1 {
cx = $o1.scanvar
n = $o1.scanvar
// printf(" %g %d\n ", cx, n)
for i=0, n - 1 {
id = $o1.scanvar
// printf(" %d", id)
$o2.object(id).sec { si = new ParallelComputeToolSplitInfo() }
si.sid = isid + 1
sil.append(si)
if (i == 0) {
si0 = si
if (isub == 0) {
si.first = 1
}
}else{
si.spsec = si0.sec
si.spx = si0.x
}
}
// printf("\n")
}
}
if (0) for i=0, sil.count-1 {
si = sil.object(i)
si.sec.sec printf("original: connect %s(%g),", secname(), si.x)
si.psec.sec printf(" %s(%g)\n", secname(), si.px)
if (si.spx < 0) {
printf(" new: disconnect()\n")
}else{
si.sec.sec printf("new: connect %s(%g),", secname(), si.x)
si.spsec.sec printf(" %s(%g)\n", secname(), si.spx)
}
}
}
proc split() {local i, j, sidoff, nhost, rank localobj si, sil
sidoff = 100*splitinfo_.count-1
nhost = pc.nhost
rank = pc.id
sil = splitinfo_.o(splitinfo_.count-1)
for i=0, sil.count-1 {
si = sil.o(i)
si.sec.sec {
disconnect()
// printf("%s disconnect()\n", secname())
}
if (si.spx >= 0) {
si.spsec.sec connect si.sec.sec(si.x), si.spx
// si.sec.sec printf("connect %s(%g),", secname(), si.x)
// si.spsec.sec printf(" %s(%g)\n", secname(), si.spx)
}
}
for i=0, sil.count-1 {
si = sil.o(i)
if (si.first) {
si.psec.sec {
pc.multisplit(si.px, (si.sid + sidoff)*nhost + rank)
// printf("%s pc.multisplit(%g, %d)\n", secname(), si.px, (si.sid + sidoff)*nhost + rank)
}
}
if (si.spx < 0) {
si.sec.sec {
pc.multisplit(si.x, (si.sid + sidoff)*nhost + rank)
// printf("%s pc.multisplit(%g, %d)\n", secname(), si.x, (si.sid + sidoff)*nhost + rank)
}
}
}
}
proc unsplit() {local i, j localobj si, sil
pc.partition()
pc.gid_clear(2)
for j=0, splitinfo_.count - 1 {
sil = splitinfo_.o(j)
for i=0, sil.count - 1 {
si = sil.o(i)
si.sec.sec disconnect()
si.psec.sec connect si.sec.sec(si.x), si.px
if (0) {
si.sec.sec printf("connect %s(%g),", secname(), si.x)
si.psec.sec printf(" %s(%g)\n", secname(), si.px)
}
}
}
cacheeffic_ = cvode.cache_efficient(0)
multisplit_ = 0
}
proc showshape() {local i localobj ar, piece
shapeplot = new Shape()
ar = new SectionList()
ar.allroots()
i = 0
forsec ar {
if ($1 == 0) {
i = pc.sec_in_thread + 1
}else{
i = (i%8) + 1
}
piece = new SectionList()
piece.wholetree
shapeplot.color_list(piece, i)
}
}
endtemplate ParallelComputeTool
objref tobj
tobj = new ParallelComputeTool()
objref tobj
|