23
edits
Changes
→Assignment 1
'''Running the program'''
To profile compile the programon Linux you must download the OpenCV library and then create a makefile that will create the executable OilPaint.exe. To compile the program in visual studio you will need to set project properties for OpenCV through setting the C/C++ Additional Include Directories, run this commandLinker Additional Library Directories and Input Additional Dependencies (opencv_world320d.lib).
gprof Output: Flat profile: Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls s/call s/call name [[File 79.79 20.17 20.17 1 20.17 24.77 paint(cv::Mat&, cv::t2Mat&, int, int, int, int) 12.53 23.34 3.17 1742140400 0.jpg|600px]] [[File00 0.00 cv::Vec<unsigned char, 3>& cv::Mat::at<cv::OilVersion-t2Vec<unsigned char, 3> >(int, int) 5.62 24.76 1.42 1737354300 0.00 0.jpg|600px]00 cv::Vec<unsigned char, 3>::operator[] (int) 1.94 25.25 0.49 1 0.49 0.49 cv::Size_<int>::Size_(int, int) ... (there are a lot of other calls to the library that did not significantly affect the profiling)
The time required for the program depends largely on the file size being converted. Around 5 seconds for a 50KB image and 100 seconds for a 1MB image. It depends on the brush size and intensity levels as well.
'''Analysis'''
The profiling revealed that 80-99% of the processing time is spent in the paint function where the for-loop logic is located. Within that 99% the program spends roughly 2/3rds 3 of its time reading accessing data through the "at" function of the OpenCV Mat class (n-dimensional dense array class). The other 1/3 is spent on direct access through OpenCV’s Vec class (short numerical vectors). The for-loop is structured divides the picture up based on brush size. Then it finds the colour for each pixel in that section. Finally, it then averages the intensity to produce the final colour of that group of pixels. This is what makes this program ideal for parallelizing, because each iteration of this for-loop is calculating the final colours for each pixel. (SIMD type of process, the single instruction is to find the final colour and the multiple data is the pixels.)
//Simplified for-loop structure