



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




1 Introduction 1 1.1 OpenMP barriers.......................................... 1 1.1.1 Centralized barrier..................................... 2 1.1.2 Tournament barrier..................................... 2 1.2 MPI Barrier............................................. 2
2 Code Base description 3 2.1 OpenMP implementation...................................... 3 2.1.1 Fudge factor........................................ 3 2.1.2 Compiling......................................... 3 2.2 MPI implementation........................................ 3
3 Results 3 3.1 Standalone OpenMP........................................ 3 3.1.1 Test procedure....................................... 3 3.1.2 Results........................................... 3 3.1.3 Interpretation........................................ 4 3.2 MPI results............................................. 6
4 MPI Compiling 7
5 Division of work 7
6 Conclusion 7
Barriers are used in multi-threaded programs to guarantee that all threads reach a certain program point. For example, iterative algorithms that operate on a grid need to make sure the entire grid has been updated before moving to the next iteration. If multiple threads are updating different parts of the grid, all threads need to wait for one another at the end of each iteration in order to not mix iterations. Barriers are thus essential in implementing multi-threaded algorithm where some form of synchronization is needed. Libraries that provide support for multi-threaded (or multi-machine) computing, such as OpenMP and MPI, already provide implementations of barrier synchronization. However, in this project, we re-implemented barriers in OpenMP and also provided an implementation of a MPI barrier.
1.1 OpenMP barriers
We implemented two barriers in OpenMP, the centralized barrier and the tournament barrier. Both algorithms were taken from the MCS paper presented in class. We explain both these algorithms in this section.
1.1.1 Centralized barrier
We implemented a centralized barrier with sense reversal. A centralized barrier utilizes a shared counter which is decremented every-time a thread reaches the barrier. When the counter reaches zero, it is reset, and all threads are freed from the barrier. The algorithm for the centralized barrier is given below: Data: Shared globalSense = false and shared counter = number of threads localSense = !localSense; lock(counter); counter–; if counter == 0 then counter = number of threads; unlock(counter); globalSense = localSense; else unlock(counter); spin until globalSense == localSense; end Algorithm 1: Centralized barrier algorithm
High-contention The shared counter produces high-contention. In the case of machines that maintain memory consistency, many invalidates will have to take place in order to maintain all copies of the shared counter up to date. The locking and unlocking of the counter can be replaced by an atomic operation such as fetch and decrement. However, in our algorithms, we used OpenMP constructs to achieve greater portability. The lock operations thus allow protection of the shared variable while we update it.
1.1.2 Tournament barrier
In the tournament barrier, the barrier is achieved in a series of rounds. In each round, processors are paired two by two and perform a simple barrier between each other. At the end of each round, a ‘winner’ (fixed) will move up to the next round and be paired up with another processor. When all rounds have completed (there are log 2 (n) rounds where n is the number of threads), a similar mechanism is used to inform all the ‘losers’ of each previous round. The algorithm for this barrier is given in the MCS paper.
Very little contention Although this algorithm is more complex and involves more steps, it also greatly reduces contention. Each thread spins on its own local copy of a ‘sense’ variable. Furthermore, actual barriers are very localized as only two threads participate in each of them. The complete barrier is built because of the aggregation of all the other smaller barriers.
1.2 MPI Barrier
The MPI Barrier that synchronizes processes across machines was supposed to be a tree-barrier. We chose the MCS Tree barrier for this purpose. It is an efficient barrier in terms of the number of network transactions in the critical path of the barrier and the advantage of spinning on locally accessible flags. The MCS Barrier can actually be divided into 2 processor-tree implementations: The first is the barrier-arrival tree where the processors notify their parent of their arrival at the barrier. This tree has a fan-out of 4 at every tree-node that the authors attribute to convenient access to a pack of 4 bytes as good as accessing just one data-element. Every child will update a flag reserved for it in the parent node to signal its arrival at the barrier and the parent meanwhile keeps spinning on its locally accessible flags to see if all its children have arrived at the barrier. The wake-up tree on the other hand has a fan-out of two at every tree node as this minimizes the critical path with the least number of network transactions. The algorithm referred was from the Mellor-Crummey and Scott paper.
Base 3.14/1.36 17.96/3.30 22.72/4.44 26.08/6. Centralized 2.67/1.31 4.58/2.15 8.95/3.86 144649.61/237307. Tournament 2.94/1.26 5.44/2.50 9.83/3.22 231307.10/365772.
Table 1. Average time and standard deviation for three different barriers synchronizing 2 to 5 processes
Average barrier time (no yield)
0
5
10
15
20
25
30
(^0 1 2) Number of Processes 3 4 5 6
Time (microseconds)
Baseline Centralized Tournament
Figure 1. Timing for different OpenMP barriers with a normal spin
Average barrier time (with yield)
0
10
20
30
40
50
60
(^0 1 2 3) Number of Processes 4 5 6 7 8 9
Time (in microseconds)
Baseline Centralized Tournament
Figure 2. Timing for different OpenMP barriers with a yielding spin
3.1.3 Interpretation
Centralized versus tournament barrier Our results show that the centralized barrier performs slightly better than the tournament barrier. This is a little surprising as the tournament barrier is a more complex algorithm that should reduce contention and thus improve overall performance. We can explain this apparent discrepency by the fact that the tournament barrier that we implemented does not take into account cache line sizes. The updates of variables shared only between some processes (for example, the ‘flag’ variable of one process is updated by only one other process) can actually cause invalidations in the caches of all processors due to the false sharing introduced by cache lines. Our algorithm does not implement a cache-line size aware approach. Therefore, the increased complexity of the algorithm, along with the false sharing, probably contribute to this slight worsening of performance as compared to the centralized barrier.
Spinning and scheduling A very obvious result is how bad the barriers perform when more than four processes are used. We ran tests with larger number of processes as well and the results hold: performance is absolutely dismal. This can be explained by the fact that the processes spin but now have to be contexted- switched because there are not enough processors to assign. Spinning is therefore a complete waste of cycles. An implementation where the process would yield or wait on a condition would be more appropriate. This is probably what the integrated OpenMP barrier does as its performance is very acceptable in the case of 5 processes.
To test this theory out, we implemented the same barriers but instead of just spinning, the processes yield. The results are presented in 2. Figure 2 presents these results in a graphical form. We also show all results in a global graph in Figure 3.
Integrated OpenMP barrier The integrated OpenMP barrier does not do as well as our barriers when we spin and yield. However, it will scale better with a higher number of processes. Some very preliminary tests show
Base 2.82/7.16 16.98/3.47 23.45/4.61 22.78/5.41 37.11/5.80 40.11/6.57 47.30/6. Centralized 2.66/1.53 5.52/2.97 8.47/3.65 13.32/4.53 17.50/5.37 20.33/5.89 23.89/6. Tournament 3.56/1.51 7.03/2.87 10.32/3.96 15.30/5.08 20.54/5.56 25.17/6.41 30.97/7.
Table 2. Average time and standard deviation for three different barriers synchronizing 2 to 8 processes with a yield
Average barrier time
0
5
10
15
20
25
30
0 1 2 3 4 5 6 Number of Processes
Time (in microseconds)
Baseline (no yield) Centralized (no yield) Tournament (no yield) Baseline (yield) Centralized (yield) Tournament (yield)
Figure 3. All OpenMP results
that the OpenMP barrier handles 32 processes very well. This is again because the OpenMP barrier is most likely implemented with conditions and signals. This has a higher cost when there are few processes but scales very well. An ideal barrier would utilize our approach for a small number of processes and use an OpenMP like approach for more processes (more or less is defined with regards to the number of available processors). A spin approach like ours is fast provided you do not have to spin much. When there are many processes on few
A make mpi barrier in the MPI directory will generate the executable. There is a script script.sh that configures the number of processors and the number of threads per processor that can be used to test the code with different combinations. The machinefile holds the hostnames of the machines on which the process will be spawned.
We both discussed the overall problem together and tried to identify the issues. We decided on the barriers we were going to implement together. We then both went off to implement a specific piece of the code. Priyanka took care of implementing the MPI barrier while Romain worked on the two OpenMP barriers. Romain had already worked in MPI and thus wanted some experience in OpenMP while Priyanka had not worked in either of the two infrastructures. Results were generated for both parts independently by the person working on that part. The report was then written by the both of us.
For OpenMP, it can be observed from the results that the tournament barrier performs better as compared to the Centralised one where a lot of contention is seen. The interfacing between MPI and OpenMP was done using the built-in OpenMP barrier. Further observations could be performed by interfacing the MPI barrier with the implemented centralized and tournament barriers. Performance results for MPI show that the MCS barrier does scale well.