Assignment 2: Towards parallel

Part 1: Understanding hardware

A. 20 points Use your laptop or desktop and report the following information about your machine.  For each of the questions, list the command you used to find the info via the terminal (or command prompt/powershell in windows).  Do not use the windowed utilities (like about this mac or properties on a pc).  You should search online for how to do this.  

A. The CPU architecture (version number, vendor, # of cores, MHz max and min, etc)

B. The memory size and type

C. Any information you can find about the cache hierarchy of your system

Part 2: A simple poker simulator

Write a program in c that simulates a random hand of poker.  A hand in poker is represented by 5 cards.  A card is represented as a suit and a rank.

The rank is an integer between 1 and 13, inclusive. A 1 represents an Ace, an 11 represents a Jack, a
12 Queen, a 13 King.

A suit is one of Diamonds, Clubs, Hearts, or Spades.
Create an enumeration for suit and call the resulting type Suit:

typedef enum suit_s {DIAMONDS, CLUBS, HEARTS, SPADES} Suit;

Create a structure to represent a card.  It should look something like
this:

typedef struct card_s {
  int rank;
  Suit suit;
}  Card;

Then develop functions to: create a random card, print a card, and destroy (deallocate) a card.  Look up the rand() function for getting random numbers. Also create a function to determine whether two cards are equal.

A hand consists of five *distinct* cards.  Create a structure to represent a hand, and functions to create a random hand, print a hand, and destroy deallocate) a hand.  Re-use the functions for cards.

Write a function to determine whether a hand is a straight flush.  A hand is a straight flush if both of the following are satisfied: (1) all 5 cards of the hand have the same suit, and (2) the ranks of the cards form a sequence of consecutive integers.  However, for (2), the Ace (1) can count as EITHER 1 (the lowest rank), or as "14" (the highest rank), but NOT BOTH.  For example, 1,2,3,4,5 is fine, as is 10,11,12,13,1.  But not 11,12,13,1,2.

Create functions to test all of the above.

Finally, for your main function: take one command line input, the number of trials.  Then iterate #trials times.  At each iteration,
generate a random hand, determine if it is a straight flush, increment a counter if so, and destroy the hand.  At the end print out the number of trials, the total number of straight flushes encountered, and the fraction (a number between 0 and 1) of the hands that were straight flushes.

Towards parallelism

Create a script of this session to hand in. 

script session.txt

Now run your simulation program 10 times with 1000000 as the number of iterations

exit your session script by typing exit.

Add up the number of straight flushes found/10000000.  

Note:  If we knew how, we could have run our simulation on 10 CPU's and added up the results to do this in 1/10 the time.