parallel code examples for various methods

Several languages C, java, python, several methods

For multi core computers and multi node clusters

At UMBC we have had Bluegrit, Bluewave, Tara, Maya, Taki clusters

Contents

  • java threads for parallel matrix multiply
  • pthreads for parallel matrix multiply
  • OpenMP for parallel matrix multiply
  • python threads
  • MPI threads for parallel FFT
  • Other links
  • hello world thread_simple.c
    thread_simple.c  source file
    thread_simple_c.out  output file
    
    compile  gcc -o thread_simple thread_simple.c -lpthreads -lm
    
    

    java threads for parallel matrix multiply

    Links to source file and .out output file, click to read
    matmul_thread4.java  source file
    matmul_thread4_java.out  output file
    matmul_thread1.java  source code
    matmul_thread1_java.out  output file
    
    matmul_thread8.java  source file
    matmul_thread8_java.out  output file
    matmul_thread16.java  source file
    matmul_thread16_java.out  output file
    matmul_thread32.java  source file
    matmul_thread32_java.out  output file
    matmul_thread64.java  source file
    matmul_thread64_java.out  output file
    
    matmul_thread4_java.slurm  slurm file
    matmul_thread4_java.slurm  slurm file
    matmul_thread4_java.slurm  slurm file
    
    Compile  javac -cp . matmul_thread4.java
    Run      java  -cp . matmul_thread4 > matmul_thread4_java.out # without slurm
    
    

    pyhreads for parallel matrix multiply

    matmul_pthread4.c  source file
    matmul_pthread4.out  output file
    matmul_pthread8.c  source file
    matmul_pthread8.out  output file
    matmul_pthread16.c  source file
    matmul_pthread16.out  output file
    
    

    python2, python3, time_thread

    time_thread.py  source file
    time_thread_py.out  output file
    time_thread.py3  source file
    time_thread_py3.out  output file
    
    run  python time_thread.py
    run  python3 time_thread.py3
    
    

    OpenMP for parallel Matrix multiply

    Only one source file, because OMP_NUM_THREADS controls number of threads
    Links to source file and output, shown below
    omp_matmul.c  source file
    omp_matmul4.out  output file
    omp_matmul8.out  output file
    
    
    # Makefile for omp  OpenMP  just change THREADS=8, 16, 32, 64  
    all: omp_matmul4.out 
    
    omp_matmul4.out: omp_matmul.c
    	gcc -o omp_matmul omp_matmul.c -fopenmp -lm 
    	export OMP_NUM_THREADS=4
    	./omp_matmul > omp_matmul4.out
    
    
    

    MPI threads for parallel FFT

    Links to source file and output, shown below
    time_mpi_mp8.c  source file
    time_mpi_mp8.slurm  control file
    time_mpi_mp8.out  output file
    
    time_mpi_mp16.c  source file
    time_mpi_mp16.slurm  control file
    time_mpi_mp16.out  output file
    
    Or run with:
    mpicc -o time_mpi_mp8 time_mpi_mp8.c -lm
    mpirun -np 9 time_mpi_mp8 > time_mpi_mp8.out
    
    mpicc -o time_mpi_mp16 time_mpi_mp16.c -lm
    mpirun -np 17 time_mpi_mp16 > time_mpi_mp16.out
    
    roll_call.c  source file
    roll_call.out  output file
    scat.c  skatter gather source file
    scat.out  output file
    
    

    Go to Top

    Last updated 10/15/2019