XJTLU Entrepreneur College (Taicang) Cover Sheet
Module code and Title
DTS202TC Foundation of Parallel Computing
School Title
School of AI and Advanced Computing
Assignment Title
Group Assessment 1
Submission Deadline
Oct 10th,2021 @ 23:59
Final Word Count
N/A
If you agree to let the university use your work anonymously for teaching and learning purposes, please type “yes” here.
I certify that I have read and understood the University’s Policy for dealing with Plagiarism, Collusion and the Fabrication of Data (available on Learning Mall Online). With reference to this policy I certify that:
· My work does not contain any instances of plagiarism and/or collusion.
My work does not contain any fabricated data.
By uploading my assignment onto Learning Mall Online, I formally declare that all of the above information is true to the best of my knowledge and belief.
Scoring – For Tutor Use
Student ID
1929640;1927732;1928493
Stage of Marking
Marker
Code
Learning Outcomes Achieved (F/P/M/D)
(please modify as appropriate)
Final
Score
A
B
C
1st Marker – red pen
Moderation
– green pen
IM
Initials
The original mark has been accepted by the moderator (please circle as appropriate):
Y / N
Data entry and score calculation have been checked by another tutor (please circle):
Y
2nd Marker if needed – green pen
For Academic Office Use
Possible Academic Infringement (please tick as appropriate)
Date
Received
Days late
Late Penalty
☐ Category A
Total Academic Infringement Penalty (A,B, C, D, E, Please modify where necessary) _____________________
☐ Category B
☐ Category C
☐ Category D
☐ Category E
Part 1 Serial Version
1.1 source code
——————————–Code begins—————————————————-
#include
#include
#include
struct PGM_str //define a structure for PGM file
{
int heig; //define height of the picture
int width; //define width of the picture
int Maximum_Value;//255
int Location[5000][5000];//set size
};
int new[5000][5000];
int main()
{
int m, n;
int pixel_value;//grey value
int row, column;//set row and column
clock_t Starting_point, Ending_point;//start time and end time of this program
FILE *im_input, *im_output;//input and output of images
float Duration;//time spent on this program
struct PGM_str *features = malloc(sizeof(struct PGM_str));//compute the size of PGM structure using malloc function
//input of image
char input_path[490], output_path[490];
printf(“Please enter the path of the PGM file you want to process:\t”);//indicate input of PGM file path
scanf(“%s”, input_path);//users enter the path of target image
im_input = fopen(input_path, “r”); //open the image of given path
while (im_input == NULL) //the situation of null file
{
printf(“Error occurs when opening the first file.\nPlease check and try again.”);//indicate failure to open image
exit(1);//exit
}
while (getc(im_input)!=’\n’);//the situation of leaving the first line blank
if (getc(im_input) != ‘#’)
{
fseek(im_input, -1, SEEK_CUR);//return to the previous byte
}
else
{
while (getc(im_input) != ‘\n’); //read till a change of line
}
fseek(im_input, -1, SEEK_CUR);
fscanf(im_input, “%d %d %d”, &features->width, &features->heig, &features->Maximum_Value);//grab features
printf(“width = %d\nheight = %d\nmax_Value = %d\n”, features->width, features->heig, features->Maximum_Value);//output of features
for (row = 0; row < features->heig; row++)
{
for (column = 0; column < features->width; column++)
{
fscanf(im_input, “%d”, &pixel_value);//grab the pixel value of the picture
features->Location[row][column] = pixel_value;
}
}
//————————————————————–
Starting_point = clock();//start time of execution
//Mid-value filtering—-start—-
int value=3;
int mid_value=value*0.5;
for(int times=0;times<20;times++)//20 times of filtering
{
for (int m = mid_value; m < features->heig – 1; m++)
{
for (int n = mid_value; n < features->width – 1; n++) {
new[m][n] = (features->Location[m – 1][n] + features->Location[m + 1][n] + features->Location[m][n – 1] + features->Location[m][n + 1] + features->Location[m – 1][n – 1] + features->Location[m – 1][n + 1] +
features->Location[m + 1][n – 1] + features->Location[m + 1][n + 1] ) *0.125; //compute the average value
}
} //to attain new pixel value after computation
for(int m = 1; m< features->heig-1; m++) {
for (int n= 1; n< features->width – 1; n++) {
features->Location[m][n] = new[m][n];//store new data
}
} //put new[][] into location[][]
printf(“Times of filtering currently:%d.\n”,times+1);//output of times executed
}
for(int m=0; m
{
new[m][0]=features->Location[m][0];
new[m][column-1]=features->Location[m][column-1];
}
for(int n=0; n
{
new[0][n]=features->Location[0][n];
new[row-1][n]=features->Location[row-1][n];
}
//Mean value filtering—-end—-
//output of time
Ending_point = clock();//time of execution
Duration = (double)(Ending_point – Starting_point) / CLOCKS_PER_SEC;
printf(“Total execution time is %f.\n”, Duration);//output execution time
fclose(im_input);
printf(“Please enter the path of the output file:”);//users enter the output file path
scanf(“%s”, output_path);
im_output = fopen(output_path, “w”);
fprintf(im_output, “%s “, “P2”);
fprintf(im_output, “%d %d “, features->heig, features->width);
fprintf(im_output, “%d “, features->Maximum_Value);
for (m = 0; m < features->heig; m++)//circulation of writing pixel value into the file
{
for (n = 0; n < features->width; n++)
{
int average = new[m][n];
fprintf(im_output, “%d “, average);
}
fprintf(im_output, “\n”);
}
fclose(im_output);//close the image
free(features);//release some space
printf(“Operation completed.\nThank you for using this programme.\n”);
return 0;
}
——————————–Code ends——————————————————
1.2 terminal run
1.3 result
The image on the left shows the version before processing and the image on the right shows the version after processing.
Part 2 Analysis and further improvement employing parallel computing
2.1 analysis
As illustrated in the image below, the execution time printed out was 3.532000.
Our group achieved an agreement that this was a decent pace and could be improved.
2.2 parallel version design
Foster’s methodology is employed when designing parallel series, dividing blurring process into four separate steps.
The first step is partitioning. Since this is a single section task, we choose domain decomposition rather than functional decomposition. It is decided the image be divided into several equal parts, depending on the number of threads available to the system for support. Since the calculation of the mean value of each pixel point relates only to the information of the picture before blurring, the executions are independent.
The second step is communication. Since the whole image is partitioned into sections, and each section encounters a situation where a circle of pixels at the edge requires data from an adjacent slice when computing pixel points. We establish links between the slices so that the slices can obtain the required data for the operation.
The third step is agglomeration. After the content has been filtered in each slice, the processed images from the slices are aggregated into one overall image.
The last step is mapping. Composite task is assigned to threads with equal workload. If threads are sufficient, the units of parallel computing can be reduced to each individual pixel point. However, in reality it is often not possible to support so many threads simultaneously, so we have to strike a balance between system capacity and computation rate. That is, we need to choose a moderate number of threads.
Logo With Chinese