Changes

Jump to: navigation, search

Top Solo

2,054 bytes removed, 21:04, 7 February 2013
Assignment 1
Compilation with profiling on Mac OSX:
 
'''g++ -o CImg_demo CImg_demo.cpp -O2 -g -pg -I.. -Wall -W -ansi -pedantic -Dcimg_use_vt100 -I/usr/X11R6/include -lm -L/usr/X11R6/lib -lpthread -lX11'''
 
 
 
=== Summary of Findings ===
 
The execution of the program takes roughly 80-90 seconds. it should be noted that this application initially was an application that relied upon user input for execution and for termination. I have modified this initial behavior by ensuring the while loop (which generates the triangles) executes only for a maximum of 1000 iterations. The time measured in this assignment is for every 1000 iterations of this loop.
 
Profiling Results
The results if the initial profile shows that the execution time is most greatly consumed when drawing the triangles out to the screen one at a time. It seems like this can be optimized by offloading this drawing to n threads based on n triangles to be drawn. But this is subject to change because of any additional complexity that may be introduced that may include interoperability with both the GPU and CPU.
 
There is another for loop which sets the dimensions for each triangle one by one in linear time O(n ). This process can also be out-sourced to the GPU in n threads for n triangles. I would need to determine if this process also involves interoperability between the CPU and GPU.
 
The complexity of the entire program is O(n^3). There is a for loop for setup, a while loop for accepting user input and another for loop for drawing the triangles.
 
Also the times recorded can be increase if the maximum loop iterations increase ie: 10000,100000,1000000. This will identify the same relationship but with higher task time.
 
 
=== Amdahls Law Calculations ===
 
Since there are 100 Triangles generated then we can theoretically create 100 threads for each triangle. The draw_line, draw_triangle, and draw_image functions take up 16 percent(0.38 + 0.08 + 0.06 / 3.10) of the execution time of the application in seconds. Plugging that into the equation using 100 cores we get:
 
S100 = 1/ 1 - 0.16 + 0.16 / 100
 
= 1.18 seconds or 1.2 seconds speedup rounded up PER 1000 iterations of the while loop to draw these triangles.
 
Will I work on this Project?
If I can optimize this function or any other function within the CImg library I will continue with this project. If it is not possible to optimize this project within the given time of the course then it will be difficult to continue on with this project and I will have to work with someone else's project. But my initial plan is to continue with this project unless I am told otherwise.
 
 
=== Makefile changes ===
 
 
I have made changes to the original Makefile that was provided with this library. I have customized it to compile for profiling by default. A new build can be generate by cleaning the old build (eg: make clean). The source can be compiled by running make <platform> eg: macosx, linux. You will need to download a third party program to allow you to run the 'make' command on Windows but the execution is the same. it can also be run on windows using visual Studio or on the command line("cl.exe must be in the environnent PATH variable").
 
 
=== Build Instructions ===
'''g++ -o CImg_demo CImg_demomake <platform> eg: macosx, linux etc.cpp -O2 -g -pg -I.. -Wall -W -ansi -pedantic -Dcimg_use_vt100 -I/usr/X11R6/include -lm -L/usr/X11R6/lib -lpthread -lX11'''
<big><pre>
// Item : Filled Triangles
// Init images and create display window.
 
CImg<unsigned char> img0(background), img;
CImgDisplay disp(img0,"[#6] - Filled Triangles (Click to shrink)");
 
 
// Define random properties (pos, size, colors, ..) for all triangles that will be displayed.
 
float posx[SIZE], posy[SIZE], rayon[SIZE], angle[SIZE], veloc[SIZE], opacity[SIZE];
std::srand((unsigned int)time(0));
// I'm thinking of offloading these operations to the GPU
 
for (int k = 0; k<SIZE; ++k) {
opacity[k] = (float)(0.3 + 1.5*cimg::rand());
 
}
 
 
// Start animation loop.
while (!disp.is_closed() && !disp.is_keyQ() && !disp.is_keyESC()) {
 
img = img0;
 
 
/* Maybe offload this for loop to GPU? */
}
 
 
// Display current animation framerate, and refresh display window.
if (++num>SIZE) num = SIZE;
 
 
// Allow the user to toggle fullscreen mode, by pressing CTRL+F.
}
 </pre></big> 
=== Initial Profile (on OpenSUSE Linux at Seneca) ===
<big><pre>
Flat profile:
 
 
 
Each sample counts as 0.01 seconds.
0.00 3.10 0.00 1 0.00 136.13 cimg_library::CImgList<float>::get_crop_font() const
</pre></big>
=== Modified Makefile for Profiling ===
<big><pre> 
CIMG_FILES = CImg_demo
all
 
 
dlinux:
 
@$(MAKE) \
 
"CONF_CFLAGS = \
 
$(CIMG_ANSI_CFLAGS) \
 
$(CIMG_DEBUG_CFLAGS) \
 
$(CIMG_VT100_CFLAGS) \
 
$(CIMG_X11_CFLAGS) \
 
$(CIMG_XSHM_CFLAGS)" \
 
"CONF_LDFLAGS = \
 
$(CIMG_X11_LDFLAGS) \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LAGS) \
 
$(CIMG_FFTW3_LDFLAGS)" \
 
"STRIP_EXE=true" \
 
all $(CIMG_EXTRA_FILES)
 
 
# Sun Solaris targets, with X11 display.
 
solaris:
 
@$(MAKE) \
 
"CONF_CFLAGS = \
 
$(CIMG_ANSI_CFLAGS) \
 
$(CIMG_VT100_CFLAGS) \
 
$(CIMG_X11_CFLAGS) \
 
$(CIMG_XSHM_CFLAGS)" \
 
"CONF_LDFLAGS = \
 
$(CIMG_SOLARIS_LDFLAGS) \
 
$(CIMG_X11_LDFLAGS) \
 
$(CIMG_XSHM_LDFLAGS)" \
 
all
 
 
dsolaris:
 
@$(MAKE) \
 
"CONF_CFLAGS = \
 
$(CIMG_ANSI_CFLAGS) \
 
$(CIMG_DEBUG_CFLAGS) \
 
$(CIMG_VT100_CFLAGS) \
 
$(CIMG_X11_CFLAGS) \
 
$(CIMG_XSHM_CFLAGS)" \
 
"CONF_LDFLAGS = \
 
$(CIMG_SOLARIS_LDFLAGS) \
 
$(CIMG_X11_LDFLAGS) \
 
$(CIMG_XSHM_LDFLAGS)" \
 
all
 
 
osolaris:
 
@$(MAKE) \
 
"CONF_CFLAGS = \
 
$(CIMG_ANSI_CFLAGS) \
 
$(CIMG_OPT_CFLAGS) \
 
$(CIMG_VT100_CFLAGS) \
 
$(CIMG_X11_CFLAGS) \
 
$(CIMG_XSHM_CFLAGS)" \
 
"CONF_LDFLAGS = \
 
$(CIMG_SOLARIS_LDFLAGS) \
 
$(CIMG_X11_LDFLAGS) \
 
$(CIMG_XSHM_LDFLAGS)" \
 
"STRIP_EXE=true" \
 
all
 
 
msolaris:
 
@$(MAKE) \
 
"CONF_CFLAGS = \
 
$(CIMG_ANSI_CFLAGS) \
 
$(CIMG_NODISPLAY_CFLAGS) \
 
$(CIMG_OPT_CFLAGS)" \
 
"STRIP_EXE=true" \
 
all
 
 
 
 
Msolaris:
 
@$(MAKE) \
 
"CONF_CFLAGS = \
 
$(CIMG_OPT_CFLAGS) \
 
$(CIMG_VT100_CFLAGS) \
 
$(CIMG_X11_CFLAGS) \
 
$(CIMG_XSHM_CFLAGS) \
 
$(CIMG_XRANDR_CFLAGS) \
 
$(CIMG_TIFF_CFLAGS) \
 
$(CIMG_MINC2_CFLAGS) \
 
$(CIMG_EXR_CFLAGS) \
 
$(CIMG_PNG_CFLAGS) \
 
$(CIMG_JPEG_CFLAGS) \
 
$(CIMG_ZLIB_CFLAGS) \
 
$(CIMG_OPENCV_CFLAGS) \
 
$(CIMG_MAGICK_CFLAGS) \
 
$(CIMG_FFTW3_CFLAGS)" \
 
"CONF_LDFLAGS = \
 
$(CIMG_SOLARIS_LDFLAGS) \
 
$(CIMG_X11_LDFLAGS) \
 
$(CIMG_XSHM_LDFLAGS) \
 
$(CIMG_XRANDR_LDFLAGS) \
 
$(CIMG_TIFF_LDFLAGS) \
 
$(CIMG_MINC2_LDFLAGS) \
 
$(CIMG_EXR_LDFLAGS) \
 
$(CIMG_PNG_LDFLAGS) \
 
$(CIMG_JPEG_LDFLAGS) \
 
$(CIMG_ZLIB_LDFLAGS) \
 
$(CIMG_OPENCV_LDFLAGS) \
 
$(CIMG_MAGICK_LDFLAGS) \
 
$(CIMG_FFTW3_LDFLAGS)" \
 
"STRIP_EXE=true" \
 
all $(CIMG_EXTRA_FILES)
 
 
 
# MacOsX targets, with X11 display.
all
 
 
dmacosx:
 
@$(MAKE) \
 
"CONF_CFLAGS = \
 
$(CIMG_ANSI_CFLAGS) \
 
$(CIMG_DEBUG_CFLAGS) \
 
$(CIMG_VT100_CFLAGS) \
 
$(CIMG_X11_CFLAGS)" \
 
"CONF_LDFLAGS = \
 
$(CIMG_X11_LDFLAGS)" \
 
all
 
 
 
 
omacosx:
 
@$(MAKE) \
 
"CONF_CFLAGS = \
 
$(CIMG_ANSI_CFLAGS) \
 
$(CIMG_OPT_CFLAGS) \
 
$(CIMG_VT100_CFLAGS) \
 
$(CIMG_X11_CFLAGS)" \
 
"CONF_LDFLAGS = \
 
$(CIMG_X11_LDFLAGS)" \
 
all
 
 
mmacosx:
 
@$(MAKE) \
 
"CONF_CFLAGS = \
 
$(CIMG_ANSI_CFLAGS) \
 
$(CIMG_NODISPLAY_CFLAGS) \
 
$(CIMG_OPT_CFLAGS)" \
 
all
 
 
 
 
Mmacosx:
 
@$(MAKE) \
 
"CONF_CFLAGS = \
 
$(CIMG_OPT_CFLAGS) \
 
$(CIMG_VT100_CFLAGS) \
 
$(CIMG_X11_CFLAGS) \
 
$(CIMG_TIFF_CFLAGS) \
 
$(CIMG_MINC2_CFLAGS) \
 
$(CIMG_EXR_CFLAGS) \
 
$(CIMG_PNG_CFLAGS) \
 
$(CIMG_JPEG_CFLAGS) \
 
$(CIMG_ZLIB_CFLAGS) \
 
$(CIMG_OPENCV_CFLAGS) \
 
$(CIMG_MAGICK_CFLAGS) \
 
$(CIMG_FFTW3_CFLAGS)" \
 
"CONF_LDFLAGS = \
 
$(CIMG_X11_LDFLAGS) \
 
$(CIMG_TIFF_LDFLAGS) \
 
$(CIMG_MINC2_LDFLAGS) \
 
$(CIMG_EXR_LDFLAGS) \
 
$(CIMG_PNG_LDFLAGS) \
 
$(CIMG_JPEG_LDFLAGS) \
 
$(CIMG_ZLIB_LDFLAGS) \
 
$(CIMG_OPENCV_LDFLAGS) \
 
$(CIMG_MAGICK_LDFLAGS) \
 
$(CIMG_FFTW3_LDFLAGS)" \
 
all $(CIMG_EXTRA_FILES)
 
 
 
# Windows targets, with GDI32 display.
  dwindows:  @$(MAKE) \ "CONF_CFLAGS = \ $(CIMG_DEBUG_CFLAGS)" \ "CONF_LDFLAGS = \ $(CIMG_GDI32_LDFLAGS)" \ all    owindows:  @$(MAKE) \ "CONF_CFLAGS = \ $(CIMG_OPT_CFLAGS)" \ "CONF_LDFLAGS = \ $(CIMG_GDI32_LDFLAGS)" \ "STRIP_EXE=true" \ all    mwindows:  @$(MAKE) \ "CONF_CFLAGS = \ $(CIMG_NODISPLAY_CFLAGS) \ $(CIMG_OPT_CFLAGS)" \ "STRIP_EXE=true" \ all    Mwindows:  @$(MAKE) \ "CONF_CFLAGS = \ $(CIMG_OPT_CFLAGS) \ $(CIMG_TIFF_CFLAGS) \ $(CIMG_PNG_CFLAGS) \ $(CIMG_JPEG_CFLAGS) \ $(CIMG_ZLIB_CFLAGS) \ $(CIMG_OPENCV_CFLAGS) \ $(CIMG_FFTW3_CFLAGS)" \ "CONF_LDFLAGS = \ $(CIMG_GDI32_LDFLAGS) \ $(CIMG_TIFF_LDFLAGS) \ $(CIMG_PNG_LDFLAGS) \ $(CIMG_JPEG_LDFLAGS) \ $(CIMG_ZLIB_LDFLAGS) \ $(CIMG_OPENCV_LDFLAGS) \ $(CIMG_FFTW3_LDFLAGS)" \ "STRIP_EXE=true" \ all $(CIMG_EXTRA_FILES) </pre></big> === Build Instructions === make <platform> eg: macosx, linux etc.
== Assignment 2 ==
== Assignment 3 ==
1
edit

Navigation menu