File: test_direct.hoc

package info (click to toggle)
neuron 8.2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,760 kB
  • sloc: cpp: 149,571; python: 58,465; ansic: 50,329; sh: 3,510; xml: 213; pascal: 51; makefile: 35; sed: 5
file content (79 lines) | stat: -rw-r--r-- 1,957 bytes parent folder | download | duplicates (2)
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
// Launch:
// nrnivmodl mod
// nrnivmodl-core mod
// nrniv tst_direct.hoc
//   success if prints 3 lines of 1 at the end

{load_file("stdrun.hoc")}

create soma

proc test_direct_memory_transfer() { localobj po, pc, ic, tv, vvec, i_mem, tvstd, vstd, i_memstd
    soma {
        L=5.6419
        diam=5.6419
        insert hh
        ic = new IClamp(.5)
    }
    ic.del = .5
    ic.dur = 0.1
    ic.amp = 0.3

    // for testing external mod file
    soma { insert Sample }

    cvode.use_fast_imem(1)
    cvode.cache_efficient(1)

    // record results of a run
    vvec = new Vector()
    soma {vvec.record(&v(.5))}
    i_mem = new Vector()
    soma {i_mem.record(&i_membrane_(.5))}
    tv = new Vector()
    soma {tv.record(&t)}

    // normal NEURON run
    run()

    // store results for later comparison
    vstd = vvec.cl()
    tvstd = tv.cl()
    i_memstd = i_mem.cl()

    // resize so no chance of comparing equal if psolve does nothing
    vvec.resize(0)
    tv.resize(0)
    i_mem.resize(0)

    if (!nrnpython("from neuron import coreneuron")) {
        printf("Python not available\n")
        return
    }

    po = new PythonObject()
    po.coreneuron.enable = 1
    nrnpython("from neuron.tests.utils.strtobool import strtobool; import os; coreneuron.gpu=bool(strtobool(os.environ.get('CORENRN_ENABLE_GPU', 'false')))")
    printf("nrncore_arg: |%s|\n", po.coreneuron.nrncore_arg(tstop))

    pc = new ParallelContext()
    pc.set_maxstep(10)
    stdinit()
    pc.psolve(tstop)

    // compare results
    result1 = tv.eq(tvstd)
    result2 = vvec.cl().sub(vstd).abs().max() < 1e-10
    result3 = i_mem.cl().sub(i_memstd).abs().max() < 1e-10
    result  = result1 && result2 && result3
    print(result1)
    print(result2)
    print(result3)
    print(result)
    // make the test (nrniv) return an error code if the comparison failed
    if (!result) {
        nrnpython("import sys; sys.exit(1)")
    }
}

test_direct_memory_transfer()