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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <stdlib.h>
#include "objects.h"
#include <csignal>
#include <ctime>
#include <time.h>
{{ openmp_pragma('include') }}
#include "run.h"
#include "brianlib/common_math.h"
{% for codeobj in code_objects | sort(attribute='name') %}
#include "code_objects/{{codeobj.name}}.h"
{% for block in codeobj.before_after_blocks %}
#include "code_objects/{{block}}_{{codeobj.name}}.h"
{% endfor %}
{% endfor %}
{% for name in user_headers | sort %}
#include {{name}}
{% endfor %}
#include <iostream>
#include <fstream>
#include <string>
{{report_func|autoindent}}
void set_from_command_line(const std::vector<std::string> args)
{
for (const auto& arg : args) {
// Split into two parts
size_t equal_sign = arg.find("=");
auto name = arg.substr(0, equal_sign);
auto value = arg.substr(equal_sign + 1, arg.length());
brian::set_variable_by_name(name, value);
}
}
void _int_handler(int signal_num) {
if (Network::_globally_running && !Network::_globally_stopped) {
Network::_globally_stopped = true;
} else {
std::signal(signal_num, SIG_DFL);
std::raise(signal_num);
}
}
int main(int argc, char **argv)
{
{% if prefs.core.stop_on_keyboard_interrupt %}
std::signal(SIGINT, _int_handler);
{% endif %}
std::random_device _rd;
std::vector<std::string> args(argv + 1, argv + argc);
if (args.size() >=2 && args[0] == "--results_dir")
{
brian::results_dir = args[1];
#ifdef DEBUG
std::cout << "Setting results dir to '" << brian::results_dir << "'" << std::endl;
#endif
args.erase(args.begin(), args.begin()+2);
}
{{'\n'.join(code_lines['before_start'])|autoindent}}
brian_start();
{{'\n'.join(code_lines['after_start'])|autoindent}}
{
using namespace brian;
{{ openmp_pragma('set_num_threads') }}
{{main_lines|autoindent}}
}
{{'\n'.join(code_lines['before_end'])|autoindent}}
brian_end();
{{'\n'.join(code_lines['after_end'])|autoindent}}
return 0;
}
|