Files
parallel-programming/final_assignment/results.ipynb
T
2023-12-05 23:47:11 -07:00

313 KiB

In [1]:
!pip install pandas matplotlib
Requirement already satisfied: pandas in /home/doge/parallel-programming/.venv/lib/python3.11/site-packages (2.1.3)
Requirement already satisfied: matplotlib in /home/doge/parallel-programming/.venv/lib/python3.11/site-packages (3.8.2)
Requirement already satisfied: numpy<2,>=1.23.2 in /home/doge/parallel-programming/.venv/lib/python3.11/site-packages (from pandas) (1.26.2)
Requirement already satisfied: python-dateutil>=2.8.2 in /home/doge/parallel-programming/.venv/lib/python3.11/site-packages (from pandas) (2.8.2)
Requirement already satisfied: pytz>=2020.1 in /home/doge/parallel-programming/.venv/lib/python3.11/site-packages (from pandas) (2023.3.post1)
Requirement already satisfied: tzdata>=2022.1 in /home/doge/parallel-programming/.venv/lib/python3.11/site-packages (from pandas) (2023.3)
Requirement already satisfied: contourpy>=1.0.1 in /home/doge/parallel-programming/.venv/lib/python3.11/site-packages (from matplotlib) (1.2.0)
Requirement already satisfied: cycler>=0.10 in /home/doge/parallel-programming/.venv/lib/python3.11/site-packages (from matplotlib) (0.12.1)
Requirement already satisfied: fonttools>=4.22.0 in /home/doge/parallel-programming/.venv/lib/python3.11/site-packages (from matplotlib) (4.46.0)
Requirement already satisfied: kiwisolver>=1.3.1 in /home/doge/parallel-programming/.venv/lib/python3.11/site-packages (from matplotlib) (1.4.5)
Requirement already satisfied: packaging>=20.0 in /home/doge/parallel-programming/.venv/lib/python3.11/site-packages (from matplotlib) (23.2)
Requirement already satisfied: pillow>=8 in /home/doge/parallel-programming/.venv/lib/python3.11/site-packages (from matplotlib) (10.1.0)
Requirement already satisfied: pyparsing>=2.3.1 in /home/doge/parallel-programming/.venv/lib/python3.11/site-packages (from matplotlib) (3.1.1)
Requirement already satisfied: six>=1.5 in /home/doge/parallel-programming/.venv/lib/python3.11/site-packages (from python-dateutil>=2.8.2->pandas) (1.16.0)
In [2]:
import pandas as pd
import matplotlib.pyplot as plt

Testing different platforms for parallel programming

This is a simple experiment to test out different platforms for a simple parallel programming task.

We will test .

  1. OpenMP
  2. CUDA
  3. MPI
  4. Linux Pthreads
  5. Java Threads

For each of these we will run with 4, 8, 16, 32 threads and on a varying scale of array sizes.

In [3]:
df = pd.read_csv('./performance_metrics.csv')

df.head()
Out [3]:
Program Array Size Thread Count Execution Time
0 OpenMP 10000 4.0 205283.984542
1 OpenMP 10000 4.0 179355.964065
2 OpenMP 10000 4.0 156984.024215
3 OpenMP 10000 4.0 172553.001903
4 OpenMP 10000 4.0 138308.969326

All thread counts for all programs

In [4]:
for program in df['Program'].unique():
    program_df = df[df['Program'] == program]
    plt.plot(program_df['Array Size'], program_df['Execution Time'], label=program)

plt.xlabel('Array Size')
plt.ylabel('Execution Time')
plt.title('Execution Time vs. Array Size for Different Programs (all thread counts averaged)')
plt.legend()
plt.show()

Execution times for non-CUDA on each thread counts.

  • Observations.
    • As thread count increases Java and MPI switch places.
    • MPI unsurprisingly works better when it has more threads to work with on the machine.
    • OpenMP performed the best closely behind the padded Linux Pthreads implementation.
In [5]:
# Graph all except cuda for 4 threads
df_no_cuda = df[df['Program'] != 'cuda']
df_no_cuda_4t = df_no_cuda[df_no_cuda['Thread Count'] == 4]

for program in df_no_cuda_4t['Program'].unique():
    program_df = df_no_cuda_4t[df_no_cuda_4t['Program'] == program]
    plt.plot(program_df['Array Size'], program_df['Execution Time'], label=program)

plt.xlabel('Array Size')
plt.ylabel('Execution Time')
plt.title('Execution Time vs. Array Size for Different Programs (4 threads)')
plt.legend()
        
Out [5]:
<matplotlib.legend.Legend at 0x7f9730ae2050>
In [6]:
# Graph all except cuda for 8 threads
df_no_cuda_8t = df_no_cuda[df_no_cuda['Thread Count'] == 8]

for program in df_no_cuda_8t['Program'].unique():
        program_df = df_no_cuda_8t[df_no_cuda_8t['Program'] == program]
        plt.plot(program_df['Array Size'], program_df['Execution Time'], label=program)

plt.xlabel('Array Size')
plt.ylabel('Execution Time')
plt.title('Execution Time vs. Array Size for Different Programs (8 threads)')
plt.legend()

plt.show()
In [7]:
# Graph all except cuda for 16 threads
df_no_cuda_16t = df_no_cuda[df_no_cuda['Thread Count'] == 16]

for program in df_no_cuda_16t['Program'].unique():
        program_df = df_no_cuda_16t[df_no_cuda_16t['Program'] == program]
        plt.plot(program_df['Array Size'], program_df['Execution Time'], label=program)

plt.xlabel('Array Size')
plt.ylabel('Execution Time')
plt.title('Execution Time vs. Array Size for Different Programs (16 threads)')
plt.legend()

plt.show()

In [8]:
# Graph all except cuda for 32 threads
df_no_cuda_16t = df_no_cuda[df_no_cuda['Thread Count'] == 32]

for program in df_no_cuda_16t['Program'].unique():
        program_df = df_no_cuda_16t[df_no_cuda_16t['Program'] == program]
        plt.plot(program_df['Array Size'], program_df['Execution Time'], label=program)

plt.xlabel('Array Size')
plt.ylabel('Execution Time')
plt.title('Execution Time vs. Array Size for Different Programs (32 threads)')
plt.legend()

plt.show()

In [9]:
# Graph cuda and openMP only
df_cuda_openmp = df[(df['Program'] == 'CUDA') | (df['Program'] == 'OpenMP')]

Comparing OpenMP with Cuda

  • Since openmp and cuda both performed really well we can look closely to see how they compared.
  • Observations
    • Even at much higher array sizes cuda maintains a low execution time while openMP seems to struggle.
In [10]:
for program in df_cuda_openmp['Program'].unique():
    program_df = df_cuda_openmp[df_cuda_openmp['Program'] == program]
    plt.plot(program_df['Array Size'], program_df['Execution Time'], label=program)

plt.xlabel('Array Size')
plt.ylabel('Execution Time')
plt.title('Execution Time vs. Array Size for CUDA and OpenMP')
plt.legend()
plt.show()

Comprehensive table of data

In [11]:
# Display a full table
# turn off table truncation
pd.set_option('display.max_rows', None)
display(df.pivot_table(index=['Program', 'Thread Count', 'Array Size'], values='Execution Time'))
Execution Time
Program Thread Count Array Size
Java 4.0 10000 9.530628e+05
100000 3.292380e+06
1000000 2.860490e+07
10000000 2.484076e+07
8.0 10000 1.444699e+06
100000 3.783955e+06
1000000 4.141488e+07
10000000 5.114960e+07
16.0 10000 2.312823e+06
100000 3.764023e+06
1000000 4.908494e+07
10000000 1.604579e+08
32.0 10000 3.589156e+06
100000 4.497204e+06
1000000 2.445472e+07
10000000 2.335915e+08
MPI 4.0 10000 3.334606e+05
100000 1.614696e+06
1000000 1.247393e+07
10000000 1.137531e+08
8.0 10000 3.131384e+05
100000 1.550956e+06
1000000 1.183061e+07
10000000 1.113281e+08
16.0 10000 3.420866e+05
100000 2.056698e+06
1000000 1.127848e+07
10000000 1.020751e+08
32.0 10000 6.231248e+05
100000 2.073539e+06
1000000 1.436290e+07
10000000 1.077001e+08
OpenMP 4.0 10000 1.704972e+05
100000 3.588238e+05
1000000 1.547572e+06
10000000 9.187440e+06
8.0 10000 2.573178e+05
100000 3.618154e+05
1000000 1.103501e+06
10000000 6.306812e+06
16.0 10000 4.675294e+05
100000 5.380256e+05
1000000 1.337741e+06
10000000 4.289085e+06
32.0 10000 8.865682e+05
100000 9.245034e+05
1000000 1.737905e+06
10000000 4.199411e+06
Padded 4.0 10000 3.991356e+05
100000 4.614564e+05
1000000 1.586557e+06
10000000 1.049616e+07
8.0 10000 4.829786e+05
100000 6.848344e+05
1000000 1.416199e+06
10000000 6.447894e+06
16.0 10000 9.357786e+05
100000 9.999386e+05
1000000 1.639122e+06
10000000 5.542047e+06
32.0 10000 1.434314e+06
100000 1.614646e+06
1000000 2.259404e+06
10000000 5.403496e+06

Statistics of execution time.

In [14]:
for program in df['Program'].unique():
        program_df = df[df['Program'] == program]
        print(f"\n{program}:\n")
        display(program_df["Execution Time"].describe())
count    8.000000e+01
mean     2.104659e+06
std      2.619990e+06
min      1.383090e+05
25%      4.410583e+05
50%      9.372750e+05
75%      1.991447e+06
max      9.671603e+06
Name: Execution Time, dtype: float64
count    8.000000e+01
mean     3.982728e+07
std      6.452756e+07
min      8.296540e+05
25%      3.380378e+06
50%      1.304605e+07
75%      4.257870e+07
max      2.793991e+08
Name: Execution Time, dtype: float64
count    8.000000e+01
mean     3.085687e+07
std      4.556039e+07
min      2.913650e+05
25%      1.232458e+06
50%      6.770169e+06
75%      3.751019e+07
max      1.148011e+08
Name: Execution Time, dtype: float64
count    8.000000e+01
mean     2.612748e+06
std      2.902114e+06
min      2.377350e+05
25%      8.365418e+05
50%      1.439095e+06
75%      2.531328e+06
max      1.071417e+07
Name: Execution Time, dtype: float64
count    20.000000
mean      3.560461
std       2.719199
min       1.390750
25%       1.530738
50%       2.385825
75%       4.447820
max       8.784860
Name: Execution Time, dtype: float64

Conclusion

  • From our tests it seems that for a simple application cuda and OpenMP are really performant while MPI struggles
  • The reason MPI is struggling is likely because there is a lot of latency between the machines.
    • This is likely not a good application for MPI. MPI would work better on much larger datasets that can be split more evenly.
  • OpenMP is very practical to parallelize simple applications and performs extremely well.
  • GPUs are really fast.
In [ ]: