File: compiledcode.txt

package info (click to toggle)
brian 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 23,436 kB
  • sloc: python: 68,707; cpp: 29,040; ansic: 5,182; sh: 111; makefile: 61
file content (52 lines) | stat: -rw-r--r-- 2,842 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
.. currentmodule:: brian

.. _compiled-code:

Compiled code
=============

Compiled C code can be used in several places in Brian to get speed improvements in cases where performance
is the most important factor.

Weave
-----

Weave is a SciPy module that allows the use of inlined C++ code. Brian by default doesn't use any C++
optimisations for maximum compatibility across platforms, but you can enable several optimised
versions of Brian objects and functions by enabling weave compilation. See :ref:`preferences`
for more information.

See also :ref:`efficiency-vectorisation` for some information on writing your own inlined C++ code
using Weave.

C++ objects
-----------

For maximum compatibility, Brian works with pure Python only. However, as well as the optional
weave optimisations, there are also objects can run with a pure C++ version for a considerable speedup.
For this to work, you need a copy of the ``gcc`` compiler installed (either on Linux, Mac or through cygwin on Windows)
to build them. During installation (via ``easy_install``, ``pip`` or with ``python setup.py install``), two objects
are compiled automatically: `brian.utils.fastexp.fastexp` (providing a fast, approximate exponential function) and
`brian.utils.ccircular.ccircular` (a circular array data structure). If the compilation fails, a warning message
will be displayed and the pure Python versions used instead.

In addition, it is possible to compile a C++ version of a more recent datastructure underlying the Synapses object, the `SpikeQueue`.
To compile this object, follow these instructions: 

In a command prompt or shell window, go to the directory where Brian is installed. On Windows this
will probably be ``C:\Python27\lib\site-packages\brian``. Now
go to the ``experimental/cspikequeue`` folder. If you're on Linux (and this may also work for Mac) run
the command ``python setup.py build_ext --inplace``. If you're on Windows you'll need to have cygwin with gcc
installed, and then you run ``setup.py build_ext --inplace -c mingw32`` instead. You should see some
compilation, possibly with some warnings but no errors.

If all works OK, you should see a UserWarning when importing Brian. You can uninstall (and effectively switch off) the use of the C++ SpikeQueue by removing the ``*.so`` file in the ``experimental/cspikequeue/`` directory. Repeating the steps above (i.e. recompiling the object) will re-enable the C SpikeQueue.

The same steps can also be used for compiling the `ccircular` or `fastexp` if they were not already compiled automatically during installation, just navigate
to the respective directory. 

Automatically generated C code
------------------------------

There is an experimental module for automatic generation of C code, see
:ref:`experimental-codegen`.