Difference between revisions of "CSC352 Homework 3 2017"

From dftwiki3
Jump to: navigation, search
(Question)
(The dish array)
Line 36: Line 36:
 
  where the strings are repetitions of the pattern stored
 
  where the strings are repetitions of the pattern stored
 
  in the array pattern[].
 
  in the array pattern[].
 +
 +
To compile and run:
 +
 +
    gcc -o initDish initDish.c
 +
    ./initDish
 +
 
*/
 
*/
 
#include <stdio.h>
 
#include <stdio.h>

Revision as of 15:06, 5 April 2017

--D. Thiebaut (talk) 15:26, 5 April 2017 (EDT)



Game of Life on MPI


Question


How large an MPI cluster do you need on AWS to gain a speedup greater than 1.0 for a dish of 10,000 lines, where each line is 80 characters long?

Test your program(s) on AWS for various size clusters, and submit a zip file containing:

  • the C and MPI programs you will have written,
  • any shell file you will have written to help answer the question,
  • and a pdf showing the details of your analysis, including the timing of your code AWS.


Additional Information


You may find this 2-Node, Game of Life, MPI code useful to get started.

The dish array


You may want to use the function createDish() illustrated in the code below to create a dish of 10,000 lines.

/*
 initDish.c
 D. Thiebaut

 Demo program for generating a dish with N lines,
 where N is provided by the user, and where a pattern
 of cell is repeated many times until N lines have 
 been created in the dish array.
 The function createDish returns an array of N strings
 where the strings are repetitions of the pattern stored
 in the array pattern[].

 To compile and run:
 
     gcc -o initDish initDish.c
     ./initDish

*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char* pattern[] = { "                                                                                ",
		    "   #                                                                            ",
		    " # #                                            ###                             ",
		    "  ##                                                                            ",
		    "                                                                                ",
		    "                                                      #                         ",
		    "                                                    # #                         ",
		    "                                                     ##                         ",
		    "                                                                                ",
		    "                                                                                ",
		    "                                                                                ",
		    "                                                                                ",
		    "             #                                                                  ",
		    "           # #                                                                  ",
		    "            ##                                                                  ",
		    "                                                                                ",
		    "                                                                                ",
		    "                                                                                " };


// createDish()
// input:  N: the number of lines we want in dish.
// output: dish: an array of N lines, each line being taken
//         from the array pattern, in a rotating manner.
char** createDish( int N ) {
  int i;
  int patternLength = sizeof( pattern )/sizeof( char * );
  char **dish;

  //--- create an array of N strings ---
  dish = (char **) malloc( N * sizeof( char * ) );

  //--- create N strings and "attach" them to an entry in        ---
  //--- dish.  Copy one of the lines from pattern into the newly ---
  //--- created string.                                          ---
  for ( i=0; i<N; i++ ) {
    dish[i] = (char *) malloc( ( strlen( pattern[0] )+1 )*sizeof( char ) );
    strcpy( dish[i], pattern[i % patternLength ] );
  }

  //--- return the fully populated array of N strings ---
  return dish;
}


// =================================================================
// MAIN:
// Creates a dish array of 40 lines and displays it.
// =================================================================

int main( int argc, char** argv ) {
  int i, N, length;
  char** dish;

  //--- define the number of lines wanted ---
  N = 40;

  //--- create an array of N lines ---
  dish = createDish( N );

  //--- display it on the screen ---
  for (i=0; i < N; i++ ) 
    printf( "%s\n", dish[i] );

}