Accessing a variable on a particular host

General issues of interest both for network and
individual cell parallelization.

Moderator: hines

Post Reply
shyam_u2
Posts: 77
Joined: Sun Feb 20, 2011 7:15 pm

Accessing a variable on a particular host

Post by shyam_u2 »

Hi Ted,

When i run NEURON through(nrniv) by double clicking the hoc file, I can enter any variable name in the nrniv window and get its value. How can i do this when i run NEURON in a parallel environment using the terminal ?

Thanks,
shyam
ted
Site Admin
Posts: 6300
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Accessing a variable on a particular host

Post by ted »

Suppose there is some variable x and there are N hosts. If you just execute
a_statement_that_involves_x
you'll be accessing x on host 0. If you want to access x on a particular host, you could iterate over all host ids until you get to the right one. In pseudocode you'd do this by

Code: Select all

for i = 0,number_of_hosts-1 {
  if (host id == i) {
    a_statement_that_involves_x
  }
}
To make this something that could be done conveniently from the command line, it would be useful to wrap the for loop inside a proc like so (more pseudocode follows):

Code: Select all

// $s2 is a string that is to be executed
// $1 is the id of the host on which it is to be executed
proc onhost() {
  if ($1 >= number of hosts) {
    print "host ", $1, " doesn't exist"
  } else {
    for i = 0,number_of_hosts-1 {
      if (host id == i) {
        execute($s2)
      }
    }
  }
}
Then you could type
onhost(2, "print xyz")
onhost(1, "a = 2")
or whatever.
To imitate a phrase from my favorite old calculus textbook,
"Implementation of the pseudocode in hoc is left as an exercise to the reader."
shyam_u2
Posts: 77
Joined: Sun Feb 20, 2011 7:15 pm

Re: Accessing a variable on a particular host

Post by shyam_u2 »

Thanks Ted. It works fine.
ted
Site Admin
Posts: 6300
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Accessing a variable on a particular host

Post by ted »

Good work. Thanks for asking the question, and for using NEURON in your research.
Post Reply