|
Brainsimulation
Simulation of the human brain.
|
Common helper functions. More...


Go to the source code of this file.
Data Structures | |
| struct | executioncontext_t |
| Struct to pass a simulation's technical execution information to the ticks. More... | |
Functions | |
| nodeval_t ** | alloc_2d (const int m, const int n) |
| Allocates a new 2d array with m pointers, pointing to a list of n elements. More... | |
| nodeval_t **** | alloc_4d (const int m, const int n, const int o, const int p) |
| Allocates a new 4d array with m pointers, pointing to a list of n elements, pointing to a list of o elements, pointing to a list of p elements. More... | |
| void | init_zeros_2d (nodeval_t **nodes, int number_nodes_x, int number_nodes_y) |
| Sets all values of the given array to zero. More... | |
| const unsigned int | system_processor_online_count () |
| Returns the number of processor cores online in the system. More... | |
| threadhandle_t * | create_and_run_simulation_thread (unsigned int(*callback)(partialsimulationcontext_t *), partialsimulationcontext_t *context) |
| Creates a new platform-specific thread with the context and starts it. More... | |
| void | init_thread_barrier (threadbarrier_t *barrier, const unsigned int number_threads) |
| Initializes thread barrier. More... | |
| void | destroy_thread_barrier (threadbarrier_t *barrier) |
| Destroys the thread barrier. More... | |
| unsigned int | wait_at_barrier (threadbarrier_t *barrier) |
| Waits at the barrier. More... | |
| void | join_and_close_simulation_threads (threadhandle_t **handles, const int num_threads) |
| Joins all threads and then closes them. More... | |
| void | init_partial_simulation_context (partialsimulationcontext_t *context, int num_ticks, double tick_ms, int number_nodes_x, int number_nodes_y, int num_obervationnodes, nodetimeseries_t *observationnodes, nodeval_t **old_state, nodeval_t **new_state, nodeval_t **slopes, nodeval_t ****kernels, kernelfunc_t d_ptr, kernelfunc_t id_ptr, int number_global_inputs, nodeinputseries_t *global_inputs, int thread_start_x, int thread_end_x, threadbarrier_t *barrier) |
| Convenience function to initialize a partialsimulationcontext_t in a single line. More... | |
| void | init_executioncontext (executioncontext_t *context) |
| Initializes the simulation's technical execution context. More... | |
| void | output_to_csv (char *filename, int length, nodeval_t *values) |
| Writes the given array to a .csv with every entry in its own line. More... | |
| int | get_daytime (struct timeval *tp) |
| Get the time of day. More... | |
| void | parse_file (nodeinputseries_t timeseries, const char *filename) |
| Parses the .csv file, given by the specific filename and writes its contents into the given timeseries of the nodeinputseries_t. More... | |
| int | get_field (char *line, int num) |
| Gets the n-th integer value of a comma-separated (.csv) line. More... | |
Common helper functions.
| nodeval_t** alloc_2d | ( | const int | m, |
| const int | n | ||
| ) |
Allocates a new 2d array with m pointers, pointing to a list of n elements.
| m | The number of nodes in the first dimension (x-axis). |
| n | The number of nodes in the second dimension (y-axis). |
| nodeval_t**** alloc_4d | ( | const int | m, |
| const int | n, | ||
| const int | o, | ||
| const int | p | ||
| ) |
Allocates a new 4d array with m pointers, pointing to a list of n elements, pointing to a list of o elements, pointing to a list of p elements.
| m | The number of nodes in the first dimension. |
| n | The number of nodes in the second dimension. |
| o | The number of nodes in the third dimension. |
| p | The number of nodes in the fourth dimension. |
| threadhandle_t* create_and_run_simulation_thread | ( | unsigned int(*)(partialsimulationcontext_t *) | callback, |
| partialsimulationcontext_t * | context | ||
| ) |
Creates a new platform-specific thread with the context and starts it.
| callback | The callback function to run. The function must take a threadcontext struct and returns 0 or an error code. |
| context | The threadcontext struct to pass. |
| void destroy_thread_barrier | ( | threadbarrier_t * | barrier | ) |
Destroys the thread barrier.
| barrier | Barrier to destroy. |
| int get_daytime | ( | struct timeval * | tp | ) |
Get the time of day.
Platform-independent abstraction of gettimeofday in sys/time.h.
| tp | The timeval to write back to. |
| int get_field | ( | char * | line, |
| int | num | ||
| ) |
Gets the n-th integer value of a comma-separated (.csv) line.
| line | The line to parse. |
| num | The index of the column to get, i.e. n. |
| void init_executioncontext | ( | executioncontext_t * | context | ) |
Initializes the simulation's technical execution context.
Derives the number of threads for execution and writes the result to context->num_threads. Allocates memory for the arrays in the context.
| context | The context to initialize. |
| void init_partial_simulation_context | ( | partialsimulationcontext_t * | context, |
| int | num_ticks, | ||
| double | tick_ms, | ||
| int | number_nodes_x, | ||
| int | number_nodes_y, | ||
| int | num_obervationnodes, | ||
| nodetimeseries_t * | observationnodes, | ||
| nodeval_t ** | old_state, | ||
| nodeval_t ** | new_state, | ||
| nodeval_t ** | slopes, | ||
| nodeval_t **** | kernels, | ||
| kernelfunc_t | d_ptr, | ||
| kernelfunc_t | id_ptr, | ||
| int | number_global_inputs, | ||
| nodeinputseries_t * | global_inputs, | ||
| int | thread_start_x, | ||
| int | thread_end_x, | ||
| threadbarrier_t * | barrier | ||
| ) |
Convenience function to initialize a partialsimulationcontext_t in a single line.
Passes most members and automatically derives partialsimulationcontext_t::number_partial_inputs and partialsimulationcontext_t::partial_inputs from the global inputs.
| context | Pointer to the context. |
| num_ticks | The number of ticks in the simulation. |
| tick_ms | Milliseconds in between each simulation tick. |
| number_nodes_x | The number of total nodes in the first dimension of nodes. |
| number_nodes_y | The number of total nodes in the second dimension of nodes. |
| num_obervationnodes | The number of nodes to observe. |
| observationnodes | Pointers to the timeseries for the nodes to observe. Observations are to be written here. |
| old_state | 2D array of nodes with their current energy level.Size number_nodes_x * number_nodes_y. |
| new_state | 2D array of nodes with the new energy level.Values will be overwritten. Size number_nodes_x * number_nodes_y. |
| slopes | 2D array of nodes with their slope from the last tick iteration level. Size number_nodes_x * number_nodes_y. |
| kernels | 2D array containing the kernels of each node at each index.Each index node points to an array containing(currently) two kernels, each(currently) containing 4 neighbouring noides.Dimensions: number_nodes_x * number_nodes_y * 2 * 4. |
| d_ptr | Function pointer pointing to the kernel function for the direct neighborhood. |
| id_ptr | Function pointer pointing to the kernel function for the indirect neighborhood. |
| number_global_inputs | Number of all inputs on the entire node-grid inputs to be processed. |
| global_inputs | Inputs on the entire node-grid inputs to be processed. Length: number_partial_inputs. Partial inputs in the sub-grid (defined by thread_start_x and thread_end_x) are automatically derived from this global list. |
| thread_start_x | Node x index at which to start working in this thread (inclusive). |
| thread_end_x | Node x index at which to stop working in this thread (exclusive). |
| barrier | The barrier for threads to wait at. May be uninitialized in if MULTITHREADING is disabled. |
| void init_thread_barrier | ( | threadbarrier_t * | barrier, |
| const unsigned int | number_threads | ||
| ) |
Initializes thread barrier.
| barrier | Barrier to initialize. |
| number_threads | The number of threads that the barrier should be configured to block. |
| void init_zeros_2d | ( | nodeval_t ** | nodes, |
| int | number_nodes_x, | ||
| int | number_nodes_y | ||
| ) |
Sets all values of the given array to zero.
| nodes | 2D array to be modified. Dimension x * y. |
| number_nodes_x | Number of nodes in the first dimension. |
| number_nodes_y | Number of nodes in the second dimension. |
| void join_and_close_simulation_threads | ( | threadhandle_t ** | handles, |
| const int | num_threads | ||
| ) |
Joins all threads and then closes them.
Frees all thread handles.
| handles | Array of thread handle pointers. |
| num_threads | length of handles array. |
| void output_to_csv | ( | char * | filename, |
| int | length, | ||
| nodeval_t * | values | ||
| ) |
Writes the given array to a .csv with every entry in its own line.
| filename | Name of the file to write to. |
| length | Number of entries to write. |
| values | The values to write. Length length. |
| void parse_file | ( | nodeinputseries_t | timeseries, |
| const char * | filename | ||
| ) |
Parses the .csv file, given by the specific filename and writes its contents into the given timeseries of the nodeinputseries_t.
| timeseries | The nodeinputseries_t struct to write the parsed file into. |
| filename | The filename of the .csv file. |
| const unsigned int system_processor_online_count | ( | ) |
Returns the number of processor cores online in the system.
| unsigned int wait_at_barrier | ( | threadbarrier_t * | barrier | ) |
Waits at the barrier.
Returns 1 for the management thread and 0 for all other threads.
| barrier | Barrier to wait at. |
1.8.11