Question: how to implement this in C using threads Conway's game of Life is a famous cellular automaton simulation devised by John Conway in 1970. It
how to implement this in C using threads
Conway's game of Life is a famous cellular automaton simulation devised by John Conway in 1970. It a a very simple zero-player game where the evolution of the game is strictly dictated by the initial board configuration and an update rule. It is particularly intriguing as, despite its simplicity, can give rise to truly curiously complex patterns over time. The game occurs on a rectangular board (m n) with m rows and n columns. The board is made toroidal with the row before O being m-1 and the column before column zero being column n-1 (hence the board appears to be infinite). Each cell of the board is a simple boolean telling whether the cell is alive or not. The game evolves through generations. In generation k, every cell on the board goes through a survival process to determine whether it will be alive in generation k + 1. The neighbors of cell (i,j) are the 8 cells surrounding (i,j), namely (i-1,j-1), (1-1,j), (1-1,j+1), (lj-1), (i,j +1), (i +1,j-1), (1+1,j), and (i + 1,j+1). Note that one should use modular arithmetic to wrap around in both directions and both axes. The status of cell (i,j) in generation k + 1 is based on the status of (i,j) and its neighbors in generation k, as follows When (i,j) is alive in generation k. If the number of living neighbors in generation k is 0 or 1 then (i,j) dies in generation k + 1 as there are too few live neighbors, 2 or 3 then (i,j) remains alive in generation k+1, 4 or more then (i,j) dies in generation k +1 as there are too many live neighbors. When (i,j) is dead in generation k and the number of live neighbors is 3, a new cell is born at (i, j) in generation To produce interesting behavior one can start with an initial board containing a specific pattern. A number of starting configurations are included in the git repository; for instance, the file start1.txt contains the so-called glider" pattern. You will also find in the git repository a sequential implementation that simulates the game of Life starting from an initial configuration given as its first command line argument. The sequential implementation is quite straightforward and animates the computation on the terminal. After 1000 iterations (the default can be changed by specifying a second argument to the executable) it saves the final board to a text file named final.txt Your task is to implement a multi-threaded version of the simulator, as follows: Your executable should be named lifeMT The Makefile should compile the multi-threaded executable You must use at least two worker threads to update the board . Setup the necessary synchronization to produce a correct final board Your multi-threaded implementation should still take the same input arguments . Your multi-threaded implementation should save the final board in a text file name finalMT.txt Conway's game of Life is a famous cellular automaton simulation devised by John Conway in 1970. It a a very simple zero-player game where the evolution of the game is strictly dictated by the initial board configuration and an update rule. It is particularly intriguing as, despite its simplicity, can give rise to truly curiously complex patterns over time. The game occurs on a rectangular board (m n) with m rows and n columns. The board is made toroidal with the row before O being m-1 and the column before column zero being column n-1 (hence the board appears to be infinite). Each cell of the board is a simple boolean telling whether the cell is alive or not. The game evolves through generations. In generation k, every cell on the board goes through a survival process to determine whether it will be alive in generation k + 1. The neighbors of cell (i,j) are the 8 cells surrounding (i,j), namely (i-1,j-1), (1-1,j), (1-1,j+1), (lj-1), (i,j +1), (i +1,j-1), (1+1,j), and (i + 1,j+1). Note that one should use modular arithmetic to wrap around in both directions and both axes. The status of cell (i,j) in generation k + 1 is based on the status of (i,j) and its neighbors in generation k, as follows When (i,j) is alive in generation k. If the number of living neighbors in generation k is 0 or 1 then (i,j) dies in generation k + 1 as there are too few live neighbors, 2 or 3 then (i,j) remains alive in generation k+1, 4 or more then (i,j) dies in generation k +1 as there are too many live neighbors. When (i,j) is dead in generation k and the number of live neighbors is 3, a new cell is born at (i, j) in generation To produce interesting behavior one can start with an initial board containing a specific pattern. A number of starting configurations are included in the git repository; for instance, the file start1.txt contains the so-called glider" pattern. You will also find in the git repository a sequential implementation that simulates the game of Life starting from an initial configuration given as its first command line argument. The sequential implementation is quite straightforward and animates the computation on the terminal. After 1000 iterations (the default can be changed by specifying a second argument to the executable) it saves the final board to a text file named final.txt Your task is to implement a multi-threaded version of the simulator, as follows: Your executable should be named lifeMT The Makefile should compile the multi-threaded executable You must use at least two worker threads to update the board . Setup the necessary synchronization to produce a correct final board Your multi-threaded implementation should still take the same input arguments . Your multi-threaded implementation should save the final board in a text file name finalMT.txt
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
