So since the last post I've been thinking about how to implement the forest fire simulation.
The first thing which was necessary would be a data structure to represent a grid. Easy enough we use a multidimensional array right? True but more is needed.
For individual processes to communicate with each other we should also include some form of message passing ability as if a grid is divided up into square regions they need to communicate with processors which are processing regions to the top, bottom, left, right and corners of them.
Also we need to ensure that when we update the grid we do not commit it right away as another process might still be using it. So thus updating the grid is a two step process, you need a temporary representation of the grid and then you need live data to which you commit when all processes are done communicate.
Getting the number of rows and columns of course would be helpful.
Thus I present you the grid data structure:
#ifndef GRID_H
#define GRID_H
struct Grid_;
typedef struct Grid_ Grid;
// Create, destroy Grid
Grid *grid_create(int n_cols, int n_rows);
void grid_destroy(Grid *grid);
// Data access
int grid_get_num_rows(Grid *grid);
int grid_get_num_cols(Grid *grid);
char grid_get(Grid *grid, int col, int row);
void grid_update(Grid *grid, int col, int row, char value);
void grid_commit_updates(Grid *grid);
// Communication
void grid_send_column(Grid *grid, int col, int dest);
void grid_send_row(Grid *grid, int row, int dest);
void grid_receive_column(Grid *grid, int col, int src);
void grid_receive_row(Grid *grid, int row, int src);
void grid_send_cell(Grid *grid, int col, int row, int dest);
void grid_receive_cell(Grid *grid, int col, int row, int src);
#endif // GRID_H
Note: This is just the header file, implementation details soon.