Strange behavior Updating HOC Vectors inside Python+mpi deff

When Python is the interpreter, what is a good
design for the interface to the basic NEURON

Moderator: hines

Post Reply

Strange behavior Updating HOC Vectors inside Python+mpi deff

Post by R_Jarvis » Thu Jan 22, 2015 8:31 pm

I have written an analysis to calculate transfer entropy on a large data set. The data set is so large I am using MPI such that I have access to more memory.

I am having trouble updating HOC Vectors inside Python definition, whenever I am using mpi4py as well, which is why I have made tautology statements like: '', the same is true for, Strangely a statement like that will make update the python variable j, k, and i and if I did not make such a statement the values of j k i would not be updated. Which is catastrophic when they required to act as iterators in loops.

Sometimes k does get updated and sometimes it doesn't, it seems to be influenced by how many statements come before it. Is it possible that this is caused by blocking behavior of synchronous MPI calls like broadcast? Maybe the HOC object in Python is not designed to work with mpi4py.

Code: Select all

def t_e(SIZE, NCELL, RANK, trentm):
    h('storval = new Vector()')
    h('objref vec')
    h('vec=new Vector()')

    for k in xrange(0, SIZE):
        for j in xrange(0, int(NCELL)):
            if RANK == k:
                histogram = []
                test = 0
                if test != 0:


                    histogram = h.source.recvec1.to_python()
                if test == 0:
                    histogram = None

                histogram = None
            histogram = COMM.bcast(histogram, root=k)  # ie root = rank
            gidn = int(gidn)
            test2 = h.vec.sum()

            if int(test2) != 0:
                print 'cell number ', gidn
                for i in xrange(0, int(NCELL - 1)):
                    test3 = 0
                    if test3 != 0:
                        trentm[i][gidn] =float(h.storval.x[2])
    return trentm           

trentm=t_e(SIZE, NCELL, RANK, trentm,np)

Thanks for any help or suggestions. I think there will definitely be ways of simplify the code, I am open to any suggestions about how to do this. I think the whole thing should be rewritten as a more general python definition that performs a broadcast inside an iterator and returns a matrix.

Posts: 35
Joined: Fri Apr 25, 2014 10:54 am

Re: Strange behavior Updating HOC Vectors inside Python+mpi

Post by aaronmil » Fri Jan 23, 2015 1:54 pm

Why are your storval and vec objects created through the "last resort" hoc interpreter? Just declare them as Python objects like:

Code: Select all

storval = h.Vector()
vec = h.Vector()
Then interact with the objects purely in Python, rather than hoc.

Site Admin
Posts: 1575
Joined: Wed May 18, 2005 3:32 pm

Re: Strange behavior Updating HOC Vectors inside Python+mpi

Post by hines » Sat Jan 24, 2015 7:49 am

To further emphasize aaronmil's point, I would also replace all the lines analogous to

Code: Select all


Code: Select all

ie. use pc directly in python with perhaps
pc = h.ParallelContext()
rank = int(
nhost = int(pc.nhost())

However, you mentioned the problem:
I am having trouble updating HOC Vectors is in a different namespace than your local i used in your def. Circumstances where you need h('...') are very rare.


Re: Strange behavior Updating HOC Vectors inside Python+mpi

Post by R_Jarvis » Mon Jan 26, 2015 7:27 pm

Okay great. Thanks for the advice, I will try to write everything in a more pythonic way. I also ran into trouble when I tried that once. I will post what happened here later.

Post Reply