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!

Thursday, April 14, 2011

Privacy Policy

Privacy Policy for Launch Pad

If you require any more information or have any questions about our privacy policy, please feel free to contact us.

At Launch Pad, the privacy of our visitors is of extreme importance to us. This privacy policy document outlines the types of personal information is received and collected by Launch Pad and how it is used.

Log Files
Like many other Web sites Launch Pad makes use of log files. The information inside the log files includes internet protocol (IP) addresses, type of browser, Internet Service Provider (ISP), date/time stamp, referring/exit pages, and number of clicks to analyze trends, administer the site, track user’s movement around the site, and gather demographic information. IP addresses, and other such information are not linked to any information that is personally identifiable.

Cookies and Web Beacons
Launch Pad does use cookies to store information about visitors preferences, record user-specific information on which pages the user access or visit, customize Web page content based on visitors browser type or other information that the visitor sends via their browser.

DoubleClick DART Cookie
» Google, as a third party vendor, uses cookies to serve ads on Launch Pad
» Google's use of the DART cookie enables it to serve ads to users based on their visit to  Launch Pad and other sites on the Internet.
» Users may opt out of the use of the DART cookie by visiting the Google ad and content network privacy policy at the following URL - http://www.google.com/privacy_ads.html

Some of our advertising partners may use cookies and web beacons on our site. Our advertising partners include ....
» Google AdSense
» Adbrite
» Azoogle
» Amazon


These third-party ad servers or ad networks use technology to the advertisements and links that appear on  Launch Pad send directly to your browsers. They automatically receive your IP address when this occurs. Other technologies (such as cookies, JavaScript, or Web Beacons) may also be used by the third-party ad networks to measure the effectiveness of their advertisements and / or to personalize the advertising content that you see.

Launch Pad has no access to or control over these cookies that are used by third-party advertisers.

You should consult the respective privacy policies of these third-party ad servers for more detailed information on their practices as well as for instructions about how to opt-out of certain practices. Launch Pad's privacy policy does not apply to, and we cannot control the activities of, such other advertisers or web sites.

If you wish to disable cookies, you may do so through your individual browser options. More detailed information about cookie management with specific web browsers can be found at the browsers' respective websites.Privacy P

Wednesday, March 16, 2011

Mid Term Hell

So I've been working on projects leading into mid terms as well as studying for mid terms. As such I haven't gotten a thing done with this board in a while. Working on getting some stuff up but things might be moving slowing for a bit. Keep checking back for updates.

Saturday, March 5, 2011

Temperature application code

So lets look back on what made the temperature application tick from the last post.

A series of define statements. All of the BIT# definitions come from the included msp430x20x2.h file included.
I couldn't fit the next bit of code into a screen shot so I'll have to copy paste it :
 while(1)
  {   
    ADC10CTL0 |= ENC + ADC10SC;             // Sampling and conversion start
    __bis_SR_register(CPUOFF + GIE);        // LPM0 with interrupts enabled
   
   
    /* Moving average filter out of 8 values to somewhat stabilize sampled ADC */
    tempMeasured[tempMeasuredPosition++] = ADC10MEM;
    if (tempMeasuredPosition == 8)
      tempMeasuredPosition = 0;
    tempAverage = 0;
    for (i = 0; i < 8; i++)
      tempAverage += tempMeasured[i];
    tempAverage >>= 3;                      // Divide by 8 to get average
   
    if ((--uartUpdateTimer == 0) || calibrateUpdate )
    {
      ConfigureTimerUart();
      if (calibrateUpdate)
      {
        TXByte = 248;                       // A character with high value, outside of temp range
        Transmit();
        calibrateUpdate = 0;
      }  
      TXByte = (unsigned char)( ((tempAverage - 630) * 761) / 1024 );     
      Transmit();
      uartUpdateTimer = UART_UPDATE_INTERVAL;
      ConfigureTimerPwm();
    }
   
   
    tempDifference = tempAverage - tempCalibrated;
    if (tempDifference < -TEMP_THRESHOLD)
    {
      tempDifference = -tempDifference;
      tempPolarity = TEMP_COLD;
      LED_OUT &= ~ LED1;
    }
    else
    if (tempDifference > TEMP_THRESHOLD)
    {
      tempPolarity = TEMP_HOT;
      LED_OUT &= ~ LED0;
    }
    else
    {
      tempPolarity = TEMP_SAME;
      TACCTL0 &= ~CCIE;
      TACCTL1 &= ~CCIE;
      LED_OUT &= ~(LED0 + LED1);       
    }
   
    if (tempPolarity != TEMP_SAME)   
    {     
      tempDifference <<= 3;
      tempDifference += TIMER_PWM_OFFSET;     
      TACCR1 = ( (tempDifference) < (TIMER_PWM_PERIOD-1) ? (tempDifference) : (TIMER_PWM_PERIOD-1) );
      TACCTL0 |= CCIE;
      TACCTL1 |= CCIE;     
    }  
  } 
}
What is above is the main while loop. (Hopefully the color selection doesn't make your eyes bleed).
What it does roughly is create and array :   tempMeasured[tempMeasuredPosition++] = ADC10MEM; the purpose of which is to hold previous temperatures that it measured it seems. From there it is just a matter of looping through and getting an average of the temperature change. I'm not too sure what lots of the gritty details do, but overall it simply checks to see if the temperature is more than the TEMP_THRESHOLD or less than it. If it is increasing it lights up the LED.

Its really straight forward but lots of the bit operations hold me up.That and not knowing what every variable and function is, and what they do. Going to have to go over some bit wise operations again pretty soon.

Tuesday, March 1, 2011

Temperature Application pt. II

A few days ago I posted the temperature appliction which comes pre-programmed on the board. Temperature app basically consists of a Hello World application (flashing LEDs) as well as showing off the temperature sensor.

What I didn't know at the time was that there was a GUI app for windows as well. Watch as the numbers rise and fall. Excitement!