API

Sparse Matrix

Structs

struct coo

structure of sparse matrix format: COO

Structure representing a sparse matrix in COO format.

This structure is desgined for a adjacency matrix, thus the values of all non-zero entries are of type Integer.

Public Members

int *Row

a pointer storing the row indices of non-zeros elements

int *Column

a pointer storing the column indices of non-zeros elements

int *Value

a pointer storing the non-zeros elements

long dim_l

number of row of a sparse matrix

long dim_c

number of column of a sparse matrix

long nnz

number of non-zero elements in the sparse matrix

struct csr

structure of sparse matrix format: CSR

Structure representing a sparse matrix in CSR format.

This structure is desgined for a adjacency matrix, thus the values of all non-zero entries are of type Integer.

Public Members

int *Row

a pointer storing the offsets of pointer of each row

int *Column

a pointer storing the column indices of non-zeros elements

int *Value

a pointer storing the non-zeros elements

long dim_l

number of row of a sparse matrix

long dim_c

number of column of a sparse matrix

long nnz

number of non-zero elements in the sparse matrix

struct MatrixDist

Info of each local matrix within a distributed sparse matrix.

For a distributed sparse matrix in 1D/2D MPI proc grid, this structure is created to store some basic distribution of a sparse matrix on each MPI proc.

Contains : Basic info : Block row index, Block column index, number of lines in the block, number of columns in the block, row start index (included), column start index (included), row end index (included), column end index (included)

Public Members

int indl

index of row of MPI proc within 2D MPI grid which this matrix is located on

int indc

index of column of MPI proc within 2D MPI grid which this matrix is located on.

long dim_l

number of row of a sparse matrix located on current MPI proc

long dim_c

number of column of a sparse matrix located on current MPI proc

long startRow

global index of the starting row of a local matrix within the global matrix

long startColumn

global index of the starting column of a local matrix within the global matrix

long endRow

global index of the ending row of a local matrix within the global matrix

long endColumn

global index of the ending column of a local matrix within the global matrix

Functions

int csrGetValue(long indl, long indc, csr *M_CSR)

Returns the value of indices [indl,indc] of a local sparse matrix in CSR format.

Return

Matrix value at the index [indl,indc]

Parameters
  • [in] M_CSR: a sparse matrix in CSR format to be displayed to be queried

  • [in] indl: row index of the value we want (must be < (*M_CSR).dim_l)

  • [in] indc: column index of the value we want (must be < (*M_CSR).dim_c)

void csrDisplay(csr *M, int max_dim)

Display a local sparse matrix in CSR format.

Display the local sparse matrix in CSR format as a classic matrix (also prints the 0s), if the dimension of the matrix is not too large

Parameters
  • [in] M: : a sparse matrix in CSR format to be displayed

  • [in] max_dim: : max matrix dimension (if the dimension of the matrix is above this value, it is not printed)

MatrixDist initMatrixDist(int rank, int nb_blocks_row, int nb_blocks_column, long n)

Function that initialize the basic information of each local sparse matrix based on the setup.

Returns a MatrixDist structure according to the parameters received. The information filled in is only the basic information

Return

MBlock: structure containing basic information of the local matrix on each proc

Parameters
  • [in] rank: : mpi process rank

  • [in] nb_blocks_row: : number of processes (blocks) on rows (in the process grid)

  • [in] nb_blocks_column: : number of processes (blocks) on columns (in the process grid)

  • [in] n: : global matrix dimension

Brain Structure

Structs

struct BrainPart

Structure containing the information of a part of the brain.

It contains :

  1. The number of neuron types that can be encountered in the part

  2. the cumulative distribution of neurons in the neuron types

  3. the probability of connection (for each type) to other parts of the brain.

This structure depends on the brain to which it belongs.

Public Members

int nbTypeNeuron

the number of neuron types that can be encountered in the part

double *repartitionNeuronCumulee

the cumulative distribution of neurons in the neuron types

double *probaConnection

the probability of connection (for each type) to other parts of the brain

struct Brain

Structure containing the information of a brain.

It contains :

  1. the total number of neurons

  2. the number of parts in the brain

  3. the indices (neurons) at which parts start

  4. the brain parts (see BrainPart).

Public Members

long long dimension

the total number of neurons

int nb_part

the number of parts in the brain

long long *parties_cerveau

the indices (neurons) at which parts start

BrainPart *brainPart

the brain parts (see BrainPart).

Functions

int choose_neuron_type(Brain *brain, int part)

Choose and returns the neuron type for a neuron in a specitic brain part.

Choose and returns a neuron type for a neuron in the brain part of index “part”, in the brain “brain”

Return

neuron type

Parameters
  • [in] brain: pointer to a brain

  • [in] part: brain part index

void free_brain(Brain *brain)

Brain destructor.

Function that frees a brain

Parameters
  • [in] brain: pointer to a brain

void generate_neuron_types(Brain *brain, int ind_start_neuron, int nb_neuron, int *types)

Function that generates (chooses) the types of multiple neurons and writes them in “types”.

Generates the types of neurons from index “ind_start_neuron” to “ind_start_neuron + nb_neuron” in the brain “brain”, and writes them in “types”

Condition**: The memory allocation (malloc of size nb_neuron * sizeof(int)) for “types” must be done beforehand.

Return

neuron type

Parameters
  • [in] brain: pointer to a brain

  • [in] part: brain part index

int get_brain_part_ind(long long ind, Brain *brain)

Function that returns the index of the part of the brain in which a neuron is located.

Function that returns the index of the part of the Brain in which the neuron of index ind is located

Condition**:

Brain is a well formed and ind is assumed to be between 0 and brain.dimension
Return

i index of the brain part

Parameters
  • [in] ind: index of the neuron

  • [in] brain: pointer to a brain

double get_mean_connect_percentage_for_part(Brain *brain, int part, int type)

Function that returns the average percentage of connection chances for a specific neuron to the other parts.

Function that returns the average percentage (between 0 and 100) of connection chances for a neuron of a given type in a given part, to the other parts

Return

average percentage of connection chance

Parameters
  • [in] brain: pointer to a brain

  • [in] part: brain part index

  • [in] type: neuron index

int get_nb_neuron_brain_part(Brain *brain, int part)

Function that returns the number of neurons in a specific brain part.

Function that returns the number of neurons in the brain part if index part, in the Brain brain

Return

number of neurons in the brain part

Parameters
  • [in] ind: index of the neuron

  • [in] brain: pointer to a brain

void printf_recap_brain(Brain *brain)

Brain print.

Function that displays a summary of the brain passed as a parameter (useful for debugging a brain)

Parameters
  • [in] brain: pointer to a brain

Hard-coded Brain

Brain generate_hard_brain(long long n)

generate the hard-code brain structure

generate a brain with n neurons using a hard-code structure

Parameters
  • [in] n: : number of neuros of the brain to be generated, thus the row/column size of generated sparse matrix

Brain Matrix Generation

Structs

struct BrainMatrixInfo

Structure containing debug info for a generated matrix.

It contains :

  1. the number of row of the local matrix

  2. the number of column of the local matrix

  3. the types chosen for the neurons

  4. the number of connections (number of non-zero values) per row or column (depending on the version of the generator used)

  5. number of memory cells allocated

  6. the total number of non-zero values contained in the matrix (all processes)

Public Members

long dim_c

the number of column of the local matrix

long dim_l

the number of row of the local matrix

int *types

the types chosen for the neurons

long *nb_connections

the number of connections (number of non-zero values) per row or column (depending on the version of the generator used)

long total_memory_allocated

number of memory cells allocated

long cpt_values

the total number of non-zero values contained in the matrix (all processes)

Functions

void brainAdjMatrixCSR(csr *M_CSR, MatrixDist BlockInfo, Brain *brain, int *neuron_types, BrainMatrixInfo *debugInfo)

Generates a CSR square adjacency matrix of dimension (*brain).dimension, corresponding to the brain passed as a parameter, in a two-dimensional process grid. A row/column of the matrix corresponding to a neuron, adjacency matrix means that it is the row-neuron that connect to the column-neuron

Condition : BlockInfo must have been filled with information suitable for the brain (Otherwise, the generation will not necessarily fail, but the generated matrix will not necessarily correspond to the brain)

Parameters
  • [in] BlockInfo: structure containing information about the local mpi process (“block”)

  • [in] brain: Pointer to the brain, basis for the generation of the matrix

  • [in] neuron_types: vector containing the types chosen for the neurons of the brain passed as a parameter

  • [out] M_CSR: Pointer to a structure corresponding to a CSR matrix. At the end of the generation, contains the generated matrix.

  • [out] debugInfo: OPTIONAL - Pointer to a debug structure or NULL. If not NULL, at the end of the generation, contains debug information such as the number of connections made per neuron (<=> number of 1 on each row), the total number of connections, etc.

void brainTransAdjMatrixCSR(csr *M_CSR, MatrixDist BlockInfo, Brain *brain, int *neuron_types, BrainMatrixInfo *debugInfo)

Generates a CSR square transposed adjacency matrix of dimension (*brain).dimension, corresponding to the brain passed as a parameter, in a two-dimensional process grid. A row/column of the matrix corresponding to a neuron, transposed adjacency matrix means that it is the column-neuron that connect to the row-neuron

Condition: BlockInfo must have been filled with information suitable for the brain (Otherwise, the generation will not necessarily fail, but the generated matrix will not necessarily correspond to the brain)

Parameters
  • [in] BlockInfo: structure containing information about the local mpi process (“block”)

  • [in] brain: Pointer to the brain, basis for the generation of the matrix

  • [in] neuron_types: vector containing the types chosen for the neurons of the brain passed as a parameter

  • [out] M_CSR: Pointer to a structure corresponding to a CSR matrix. At the end of the generation, contains the generated matrix.

  • [out] debugInfo: OPTIONAL - Pointer to a debug structure or NULL. If not NULL, at the end of the generation, contains debug information such as the number of connections made per neuron (<=> number of 1 on each column), the total number of connections, etc.

void brainTransAdjMatrixCSR1D(csr *M_CSR, long ind_start_row, Brain *brain, int *neuron_types, long l, long c, BrainMatrixInfo *debugInfo)

Generates a CSR square transposed adjacency matrix of dimension (*brain).dimension, corresponding to the brain passed as a parameter, in a one-two-dimensional process grid (row block parallelization) A row/column of the matrix corresponding to a neuron, transposed adjacency matrix means that it is the column-neuron that connect to the row-neuron

Condition : BlockInfo must have been filled with information suitable for the brain (Otherwise, the generation will not necessarily fail, but the generated matrix will not necessarily correspond to the brain)

Parameters
  • [in] ind_start_row: Row offset (in the 1D process grid), to be taken into account for the creation of connection between neurons

  • [in] brain: Pointer to the brain, basis for the generation of the matrix

  • [in] neuron_types: vector containing the types chosen for the neurons of the brain passed as a parameter

  • [in] l: number of rows in the local (process) matrix

  • [in] c: number of column in the local (process) matrix (= global matrix dimension, because the matrix is parallelized in row blocks only)

  • [out] M_CSR: Pointer to a structure corresponding to a CSR matrix. At the end of the generation, contains the generated matrix.

  • [out] debugInfo: OPTIONAL - Pointer to a debug structure or NULL. If not NULL, at the end of the generation, contains debug information such as the number of connections made per neuron (<=> number of 1 on each column), the total number of connections, etc.

void brainTransAdjMatrixCOO1D(coo *M_COO, long ind_start_row, Brain *brain, int *neuron_types, long l, long c, BrainMatrixInfo *debugInfo)

Generates a COO square transposed adjacency matrix of dimension (*brain).dimension, corresponding to the brain passed as a parameter, in a one-two-dimensional process grid (row block parallelization) A row/column of the matrix corresponding to a neuron, transposed adjacency matrix means that it is the column-neuron that connect to the row-neuron

Condition : BlockInfo must have been filled with information suitable for the brain (Otherwise, the generation will not necessarily fail, but the generated matrix will not necessarily correspond to the brain)

Parameters
  • [in] ind_start_row: Row offset (in the 1D process grid), to be taken into account for the creation of connection between neurons

  • [in] brain: Pointer to the brain, basis for the generation of the matrix

  • [in] neuron_types: vector containing the types chosen for the neurons of the brain passed as a parameter

  • [in] l: number of rows in the local (process) matrix

  • [in] c: number of column in the local (process) matrix (= global matrix dimension, because the matrix is ​​parallelized in row blocks only)

  • [out] M_CSR: Pointer to a structure corresponding to a CSR matrix. At the end of the generation, contains the generated matrix.

  • [out] debugInfo: OPTIONAL - Pointer to a debug structure or NULL. If not NULL, at the end of the generation, contains debug information such as the number of connections made per neuron (<=> number of 1 on each column), the total number of connections, etc.