IsaacLehman / Game-of-Life

The Conway Game of Life in c, parallelized with openMP and creates .pbm images for visualization.
0 stars 0 forks source link

Survey Question on the For loop in source file /GameOfLife.c line 157 #1

Open LChenGit opened 2 years ago

LChenGit commented 2 years ago

Hello Sir/ Madam We are from a research group at Iowa State University, USA. We want to do a survey on Github developers on the methods they used for paralleling their code. To do the survey, We want to ask three questions about this for loop:

  1. Can you briefly explain the purpose of using pragma for this case? If the pragma contained reduction and private clauses, can you briefly mention the purposes of variables in those clauses?

  2. How much confidence do you have about the correctness of this implementation? You can choose from 1-5 with 1 as the lowest confidence score and 5 as the highest confidence score.

  3. (Optional) Do you actually run (interpret the code with compilation and pass input/get output) the code and see the optimization of parallelization? Yes/No

    • If yes, can you provide the information of what are the input and expected output of this program (the input that caused the program to run through this for-loop).

The for loop is from line 157 of file https:/github.com/IsaacLehman/Game-of-Life/blob/master//GameOfLife.c Here is a part of the code:

omp parallel for reduction(+:sum) private(c) for (r = 0; r < ROWS; r++) { for (c = 0; c < COLUMNS; c++) { sum += getVal(cells, r, c); }

}

int getVal(int ary, int row, int col) { return (ary + offset2D(row, col)); }

Sincerely thanks

IsaacLehman commented 2 years ago

Hello,

  1. The pragma denotes that an openmp parallel section is about to start. The double loop checks the 2D array to determine how many cells are still alive which it stores in the "sum" variable. We create threads based on rows, not columns because that is how memory is accessed (i.e. faster). The clause contains a reduction statement denoting that the sum variable will be combined at the end of the parallel section (i.e. reduction(+:sum)). Lastly, the private variable is c. Each thread will have its own c variable to loop over columns.

  2. I am confident this is the correct implementation. (5)

  3. I run the code in WSL which doesn't get the full benefit of the optimization in addition the file I/O of generating the .pbm images takes most of the computation time. So, unfortunately, there is not much benefit to parallelizing this code with the current setup. It was intended more as a proof of concept.

If you are interested in running it and creating a beautiful little mp4 video of the Game of Life, try these commands in your terminal: gcc -o GameOfLife.exe -fopenmp GameOfLife.c && chmod +x GameOfLife.exe ./GameOfLife.exe 500 500 20 2 ffmpeg -r 60 -f image2 -s 1920x1080 -i GameOfLifegen%d.pbm -vcodec libx264 -crf 25 -pix_fmt yuv420p GOL.mp4

I would be interested in learning more about your research project.

Isaac

On Wed, Jun 29, 2022 at 2:17 PM LC @.***> wrote:

Hello Sir/ Madam We are from a research group at Iowa State University, USA. We want to do a survey on Github developers on the methods they used for paralleling their code. To do the survey, We want to ask three questions about this for loop:

1.

Can you briefly explain the purpose of using pragma for this case? If the pragma contained reduction and private clauses, can you briefly mention the purposes of variables in those clauses? 2.

How much confidence do you have about the correctness of this implementation? You can choose from 1-5 with 1 as the lowest confidence score and 5 as the highest confidence score. 3.

(Optional) Do you actually run (interpret the code with compilation and pass input/get output) the code and see the optimization of parallelization? Yes/No

  • If yes, can you provide the information of what are the input and expected output of this program (the input that caused the program to run through this for-loop).

The for loop is from line 157 of file https:/ github.com/IsaacLehman/Game-of-Life/blob/master//GameOfLife.c Here is a part of the code:

omp parallel for reduction(+:sum) private(c) for (r = 0; r < ROWS; r++) { for (c = 0; c < COLUMNS; c++) { sum += getVal(cells, r, c); }

}

int getVal(int ary, int row, int col) { return (ary + offset2D(row, col)); }

Sincerely thanks

— Reply to this email directly, view it on GitHub https://github.com/IsaacLehman/Game-of-Life/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKWEHZTIJJYBE5RUE64OW4DVRSHJ5ANCNFSM52GVNDTQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>