Tuesday, May 24, 2011

Unmaintainable code

About to start up some Mac programming for the iPhone. Got my hands on a iMac mini, xCode and a developers license. Would rather do Android OS programming but sometimes you just deal with the cards that fall in your lap.

On another note I really wanted to post to share this:
http://www.thc.org/root/phun/unmaintain.html


Very long read but quite funny as well as enlightening:


Found on reddit.com

Wednesday, May 18, 2011

Cellular Automata Forest Fire Model Continued

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.

Monday, May 9, 2011

Cellular Automata Forest Fire Model

http://schuelaw.whitman.edu/JavaApplets/ForestFireApplet/

Just thought this forest fire simulation was interesting and wanted to share.

It is just Conway's Game of Life but with modified rules.

Would be interesting to parallelize this. You could split this up into either single rows and columns and let each processor deal with a specific row or column. Or you could split it up into various row * col block and let each processor deal with a specific block.

I might try looking into this later as as side project for something to parallelize.

Sunday, May 8, 2011

Intro to MPI


So here are some basic MPI functions that are needed for parallel computers in a cluster setup
MPI_Init
Used to initialize MPI. Without this none of the other commands will work.
MPI_Comm_rank
Gets the rank of a processor from 0 - p, where p is the total number of processors.
MPI_Comm_size
Get the total number of processes available for computing.
MPI_Send
Send a message. Messages are passed as array data, you can specify the size of an array.
MPI_Recv
Complement to MPI_Send.
MPI_Finalize
Called when program is done running. Cleans up memory to avoid leaks.
Sample intro program next post

Wednesday, May 4, 2011

Parallell Programming

So how do we take advantage of all these processors and cores that we keep getting more and more of? Parallell programming!

This can be hard. It can be difficult to properly utilize processors to divide work up and share it equally.

Most paralell programs go something like this:

Divide work up
Create memory locks
Have individual processors / threads perform the work
Consolidate the data from each processor / thread.

Gonna look into how to do this using MPI, pthreads and Java in the next few days.



Sunday, May 1, 2011

So I've been missing

So last post was about mid terms hell. Then I dropped off the face of the earth.

Truth be told school hit me and hit me hard. When I started this blog I wanted to work on learning how to program on a new micro controller I got. Turns out learning to program on a whole new board is hard work. Feels kinda like school work and I got enough of that as it is!

But alas school is nearly out for the summer! And I don't have too many finals, rather lots of projects due in the next few days. I'm gonna bang those out of the way and get back to programming recreationaly.

When I do start back up in the next few days though I'm not gonna focus all my energies on just the micro controller, rather I'm going to look at all the things I'm interested in : Parallel programming, Web Programming, Micro controllers etc. So this blog is going to have multiple focuses.

Stay tuned!