Preview
In this research, we’ll talk about difference in performance when the threads are running in different CPU scenarios.
Introduction
This research aims to analyze how much parallelism can make our aplications better.
We'll be using 3 functions whithin 3 analysis methods.
For that, we created a float vector with 100*1000*1000 (100M) elements initialized with random values between -1 and 1.
Function 1: Sum all the vector;
Function 2: Sum all elements in the form Sin[i] (with i from 0 to n-1);
Function 3: Sum all the elements in the form log[i] (with i from 0 to n-1);
Analysis 1: Calculate the execution time of each function, running as a thread into a single core.
Analysis 2: For each function, calculate the execution of 2 threads with the same function, each one running in a different core.
Analysis 3: For each function, calculate the execution of 2 threads with the same function in the SAME core.
With the methods presented above, we could measure the executions. We'll calculate the time for the creation and execution of the threads and, to better visualize it, we'll plot graphics using GNU Plot tool.
We'll be using 3 functions whithin 3 analysis methods.
For that, we created a float vector with 100*1000*1000 (100M) elements initialized with random values between -1 and 1.
Function 1: Sum all the vector;
Function 2: Sum all elements in the form Sin[i] (with i from 0 to n-1);
Function 3: Sum all the elements in the form log[i] (with i from 0 to n-1);
Analysis 1: Calculate the execution time of each function, running as a thread into a single core.
Analysis 2: For each function, calculate the execution of 2 threads with the same function, each one running in a different core.
Analysis 3: For each function, calculate the execution of 2 threads with the same function in the SAME core.
With the methods presented above, we could measure the executions. We'll calculate the time for the creation and execution of the threads and, to better visualize it, we'll plot graphics using GNU Plot tool.
Installations
QT
To program the source code in C++ we're using the QT Creator. QT Creator is a very complete IDE for C++ and it has a lot of libraries and tools for GUI creation, data structures, threads creation and etc.
First of all, you can download QTCreator (offline version) from the links bellow, or download the online installation tool (https://www.qt.io/download). and it will install the IDE while downloads it.
- Linux 32bits: http://download.qt.io/official_releases/qt/5.5/5.5.1/qt-opensource-linux-x86-5.5.1.run
- Linux 64bits: http://download.qt.io/official_releases/qt/5.5/5.5.1/qt-opensource-linux-x64-5.5.1.run
We're assuming you're using one of the many linux distributions, so the links above are for Linux and not for windows. For windows users, you must download by using the online tool.
Navigate, in terminal, to the downloads folder and type the following commands:
- chmod +x file_name (where file names refers to the downloaded one).
- ./file_name.run
Follow the instructions on the screen and you're ready to go.
Navigate, in terminal, to the downloads folder and type the following commands:
- chmod +x file_name (where file names refers to the downloaded one).
- ./file_name.run
Follow the instructions on the screen and you're ready to go.
Gnuplot
To install Gnuplot, open the software center and search for GnuPlot. After found, select it and it will open it's own page. Scroll down a little bit and select the first two Optional Add-ons:- Pipe-oriented frontend to Gnuplot
- Command-line driven interactive plotting program.
After selecting both Add-ons, click on install and now you have everything you will need.
Repository
We decide to put the codes on a free online repository, GitHub.
GitHub link : https://github.com/Pekorishia/PerformanceAnalysis
Making it work
Open the GitHub link above and select the "download zip" button. Download it anywhere you want.
Now go to QT, open the file that you've just download, and select the AnaliseCPU.pro file. After that click on the red button that will appear ("Configure Project").
On the left panel, there is a icon called "Projects", click on it and uncheck, if it is checked, the "Shadow Build".
Now you only have to go to the down part of the left panel and click on the green triangle/arrow. The program will start to run.
It will show the time that was necessary to create the vector and will start to put the analysis results on a .txt file named output that is created on the same file that you've just donwload.
It will show the time that was necessary to create the vector and will start to put the analysis results on a .txt file named output that is created on the same file that you've just donwload.
All results are on this .txt file, but to make it more visible, we will plot a graphic.
Open the terminal, go to the file that has the output.txt, and copy the following commands:
$ gnuplot
$ set title "Performance Analysis"
$ f1 = "#99ffff"; f2 = "#4671d5"; f3 = "#ff0000";
$ set auto x
$ set ylabel 'Time(s)'
$ set yrange [0:11]
$ set style data histogram
$ set style histogram cluster gap 1
$ set style fill solid border -1
$ set boxwidth 0.9
$ set xtic scale 0
$ plot 'output.txt' using 2:xtic(1) ti col fc rgb f1, '' u 3 ti col fc rgb f2, '' u 4 ti col fc rgb f3
After copying the commands above a bar plot will show up and with this data the analysis will be easier.
Conclusion
For this research, we used the following systems:
Notebook with an AMD APU model A8-5550M Quad-Core processor clocked at 2.1GHz and 4GB DDR3 1600 MHz RAM.
Desktop PC equipped with an Intel Core i7 3770k Quad-Core(HT) processor clocked at 4.2GH'z with 8GB DDR3 1600 MHz Ram.
Notebook with an AMD APU model A8-5550M Quad-Core processor clocked at 2.1GHz and 4GB DDR3 1600 MHz RAM.
Desktop PC equipped with an Intel Core i7 3770k Quad-Core(HT) processor clocked at 4.2GH'z with 8GB DDR3 1600 MHz Ram.
AMD A8-5550M 2.1GHz
i7 3770k 4.2GHz
In the plots, we can clearly see that paralelism can improve a lot performance. With a big number of threads running at the same time, processors with multiple cores can manage better and being done quickly.
It's visible that with a major number of threads in a single core, the execution gets slower. When dividing the threads into other cores, we can push harder and the processor still works inside a good media with 2 cores dividing the threads.
We know too that sum itens is very much easier for a processor than calculating logs, in that case we can see that even in the worst case (analysis 3) we have a small execution time.
Besides the 3770k is a very much stronger processor, it gains some points based on the intel's HT technology, that shows to operational system a extra "core per core", that means that instead of 4 the OS "sees" 8 cores and can alocate more threads within the same core, this is a virtualization and the performance is not as quite good as two real cores, but the logical swap of threads and operations can make difference in some scenarios.


Nenhum comentário:
Postar um comentário