Profiling Neuron under Windows

Post Reply
Raj
Posts: 220
Joined: Thu Jun 09, 2005 1:09 pm
Location: Hanze University of Applied Sciences
Contact:

Profiling Neuron under Windows

Post by Raj »

Building Neuron under Windows:

Building under windows is easy, just follow the instructions given by T.N. Carnevale and M. Hines:
http://www.neuron.yale.edu/neuron/insta ... mswin.html
and have a good look at topic
https://www.neuron.yale.edu/phpBB2/viewtopic.php?p=433
before you install/update cygwin.

Profiling Neuron under Windows:

To see if you have the right software and settings available in Cygwin start with profiling the hello world application.
Step 0:
Create a file hello.cpp, containing:

Code: Select all

// Hello World Application
   #include <iostream>

   int main()
   {
       std::cout << "Hello, world!" << std::endl;
       return 0;
   } 

Compile with:

Code: Select all

g++ -g  -pg     hello.cpp   -o hello 

The -g flag adds debugging information to the code allowing the profiling software to produce human readable input, the -pg flag adds the profiling code itself.

Run the program:

Code: Select all

./hello
The directory in which you executed hello should now contain a file gmon.out. For neuron this has the strange implication that if you change working directory from within hoc gmon.out will not end up in the directory where you started the program but whereever you moved the working directory during hoc-execution.

Running gprof now shows you the profiling info:

Code: Select all

gprof -b hello.exe

The profiling provided with the -pg flag is incompatible with dynamical loading of libraries. This is why normal ways of working with mod files cannot be used. Therefore, to get access to the mechanism in your own modfiles, you need to include these files in the build and it is not enough to just specify the right compiler flags.

Step 1: Copy your mod files to src/nrnoc in the neuron source tree

Step 2:
In the src/nrnoc directory modify Makefile.am to refer to your mod-files. Copy the pattern found for hh.c and hh.mod.

Step 3: In the src/nrnoc directory in file cabvars.h modify the 'extern' and
'Pfri mechanism' sections to refer to your mechanism. Copy the pattern found for the hh mechanism.

Step 4: Run the script build.sh from the top level of the source tree

Step 5: Save and run the following script.

Code: Select all

#!/bin/sh
	export NRNS=$PWD
	export NPROF=$PWD
	
	# The -g flag adds debugging information to the code which is needed by the profiling program, the -pg flag adds the profiling code.
	export CFLAGS="-g -pg"
	export CXXFLAGS="-g -pg"
	
	export linux_nrnmech=no
		
	# Link statically (--disable-shared)
	$NRNS/configure --disable-shared --prefix=$NPROF --srcdir=$NRNS
	make
	make install 
	
	#Play sound to indicate end of script
	echo -e '\7'
Step 6: Now you have a complete build of neuron which you will find in the in i686/bin directory. The easiest way to work with these binaries is to copy an existing neuron installation and replace the bin directory with the newly created bin directory.

Step 7: Run nrniv.exe from a cygwin rxvt shell with your hoc-code, but you might want to try the demo first:
  • a) cd to nrn/bin and run nrniv
    b) load_file("nrngui.hoc") gives you the menu
    c) Change the working directory using the filemenu to where your model is. Lets assume you want to run demo.hoc from the demo directory.
    d) Load the hoc code (singhh.hoc this hoc-file is only using standard mechanisms, remember that the dynamic loading fails)
    e) Run the hoc-code (press Init and Run)
    f) quit (Select quit from file menu)
Step 8: Run gprof (-b supresses explanations it adds to the output),
gprof's syntax: gprof options [executable-file [profile-data-files...]] [> outfile]

Code: Select all

		gprof -b nrniv.exe ../demo/gmon.out > myprofile
Step 9: Interpret the output.


Acknowledgement: Thanks to Michael Hines for answering my questions about the build process.
Post Reply