This exercise could be done at several levels of complexity. Most challenging and rewarding, but also most time consuming, would be for you to develop all code from scratch. But learning by example also has its virtues, so we provide complete serial and parallel implementations that you can examine and work with.
The following instructions assume that you are using a Mac or PC, with at least NEURON 7.1 under UNIX/Linux, or the latest alpha version of NEURON 7.2 under OS X or MSWin. Also be sure that MPICH 2 is installed if you have UNIX/Linux (OS X already has it, and it comes with NEURON's installer for MSWin). If you are using a workstation cluster or parallel supercomputer, some details will differ, so ask the system administrator how to get your NEURON source code (.hoc, .ses, .mod, .py files) to where the hosts can use them, how to compile .mod files, and what commands are used to manage simulations.
The next step is to create a program that performs serial execution of multiple simulations, i.e. executes them one after another. In addition to generating simulation results, it is useful for this program to report a measure of computational performance. For this example the measure will be the total time required to run all simulations and save results. The simulation results will be needed to verify that the parallel implementation is working properly. The performance measure will help us gauge the success of our efforts, and indicate whether we should look for additional ways to shorten run times.
The final step is to create a parallel implementation of the batch program. This should be tested by comparing its simulation results and performance against those of the serial batch program in order to detect errors or performance deficiencies that should be corrected.
In accordance with this development strategy, we provide the following three programs. For each program there is a brief description, plus one or more examples of usage. There are also links to each program's source code and code walkthroughs, which may be helpful in completing one of this exercise's assignments.
Finally, there is a fourth program for plotting results that have been saved to a file, but more about that later.
nrngui initonerun.hoc
onerun(x)
onerun(0.3)
nrngui initbatser.hoc
nrngui initbatpar.hoc
mpiexec -n N nrniv -mpi initbatpar.hoc
2. Compare results produced by serial and parallel simulations, to verify that parallelization hasn't broken anything. For example:
nrngui initbatser.hoc mv fi.dat fiser.dat nrngui initbatpar.hoc mv fi.dat finompi.dat mpd & mpiexec -n 4 nrniv -mpi initbatpar.hoc mv fi.dat fimpi4.dat cmp fiser.dat finompi.dat cmp fiser.dat fimpi4.datInstead of cmp, MSWin users will have to use fc in a "Command prompt" window.
3. Evaluate and compare performance of the serial and parallel programs.
Here are results of some tests I ran on a couple of PCs.
NEURON 7.2 (508:9756f32df7d0) 2011-03-16 under Linux on a quad core desktop. initbatser 10.4 s initbatpar without MPI 10.2 with MPI speedup n = 1 10.2 1 (performance baseline) 2 5.3 1.9 3 3.5 2.9 4 2.8 3.6 NEURON 7.2 (426:7b4f020b29e8) 2010-03-12 under Linux on a dual core laptop initbatser 7.7 s initbatpar without MPI 7.5 with MPI speedup n = 1 7.7 1 (performance baseline) 2 4.1 1.9
4. Make a copy of initbatpar.hoc and edit it, inserting printf statements that reveal the sequence of execution, i.e. which processor is doing what. These statements should report whatever you think would help you understand program flow. Here are some suggestions for things you might want to report:
fi
).
After inserting the printf statements, change NRUNS to 3 or 4, then run a serial simulation and see what happens.
Next run parallel simulations with -n 1, 2, 3 or 4 and see what happens. Do the monitor reports make sense?
5. Examine an f-i curve from data saved to one of the dat files.
nrngui initplotfi.hocthen use its file browser to select one of the dat files.
Examine initplotfi.hoc to see how it takes advantage of procs that are built into NEURON's standard run library (UNIX/Linux users see nrn/share/nrn/lib/hoc/stdlib.hoc, MSWin users see c:\nrnxx\lib\hoc\stdlib.hoc).