# ParallelComputing **Repository Path**: wangqiyuejava63/parallel-computing ## Basic Information - **Project Name**: ParallelComputing - **Description**: Improve gray-scaling program with MPI and OpenMP Analyze the performance of two methods of implementation. - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-12-20 - **Last Updated**: 2025-12-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # How to build `make` # How to run `mpirun -np 16 grayscale_mpi im.ppm out.ppm` `./grayscale_openmp im.ppm out.ppm` `./grayscale_serial im.ppm out.ppm` -np is to indicate the number of processor # what is ppm https://netpbm.sourceforge.net/doc/ppm.html # MPI ## Install MPI ```sh sudo apt-get install openmpi-bin libopenmpi-dev ``` if have install network problem can change apt source according to this https://mirrors.ustc.edu.cn/help/ubuntu.html#__tabbed_1_2 ## How to use MPI MPI 全名叫 Message Passing Interface,即信息传递接口,其作用是在不同进程间传递消息,从而可以并行地处理任务,即进行并行计算 https://xflops.sjtu.edu.cn/hpc-start-guide/parallel-computing/mpi/#mpi_2 https://mpitutorial.com/tutorials/mpi-scatter-gather-and-allgather/zh_cn/ ### mpicc mpicc 是一个 编译器包装器(compiler wrapper); 它本身不编译代码,而是调用真正的编译器(这里是 /usr/bin/gcc); 同时自动添加必要的参数,比如: -I/usr/include/openmpi(包含 MPI 头文件) -L/usr/lib/openmpi/lib(链接库路径) -lmpi(链接 MPI 库) # OpenMP OpenMp提供了对并行算法的高层的抽象描述,程序员通过在源代码中加入专用的pragma来指明自己的意图,由此编译器可以自动将程序进行并行化,并在必要之处加入同步互斥以及通信。 普通执行顺序是串行执行,执行完一条指令才能执行下一条指令。 改成并行架构后,可以同时并行执行多条指令,在指令总数不变的情况下所需的总执行时间就会减小。 OpenMP采用fork-join的执行模式。开始的时候只存在一个主线程,当需要进行并行计算的时候,派生出若干个分支线程来执行并行任务。当并行代码执行完成之后,分支线程会合,并把控制流程交给单独的主线程。 ## How to use OpenMP https://www.oryoy.com/news/ubuntu-xi-tong-qing-song-an-zhuang-openmp-yi-bu-dao-wei-de-bian-yi-you-hua-zhi-nan.html https://www.cnblogs.com/buptmuye/p/3711097.html https://www.cnblogs.com/yangyangcv/archive/2012/03/23/2413335.html https://www.cnblogs.com/carsonzhu/p/17131175.html ### some intersting things I searched on Intel technical library https://www.intel.com/content/www/us/en/developer/technical-library/overview.html?q=openmp&s=Relevancy and found this https://www.intel.com/content/www/us/en/developer/videos/openmp-the-once-and-future-api.html and this https://www.intel.com/content/www/us/en/developer/videos/three-quick-practical-examples-openmp-offload-gpus.html # Benchmark ## test - get a serial runtime as a base ./test_serial.sh ./benchmark.sh -t -mpi ./benchmark.sh -s -mpi ./benchmark.sh -e -mpi ./benchmark.sh -t -omp ./benchmark.sh -s -omp ./benchmark.sh -e -omp ## store the output into txt mpi_runtime.txt mpi_speedup.txt mpi_efficiency.txt omp_runtime.txt omp_speedup.txt omp_efficiency.txt ## plot python3 plot_mpi_omp.py -mpi -runtime python3 plot_mpi_omp.py -mpi -speedup python3 plot_mpi_omp.py -mpi -efficiency python3 plot_mpi_omp.py -omp -runtime python3 plot_mpi_omp.py -omp -speedup python3 plot_mpi_omp.py -omp -efficiency python3 plot_comparison.py python3 plot_comparison_speedup_efficiency.py > Traceback (most recent call last): > File "/home/wqy/ParallelComputing/./plot_mpi.py", line 1, in > import matplotlib.pyplot as plt > ModuleNotFoundError: No module named 'matplotlib' - how to fix sudo apt install python3-pip sudo apt install python3-matplotlib