mpi basics course

This commit is contained in:
Victor Eijkhout
2025-10-08 09:08:47 -05:00
parent 857bab6b59
commit 29d941b517
42 changed files with 184 additions and 72 deletions

View File

@@ -55,6 +55,7 @@
\newif\ifVolumeOne
\VolumeOnefalse
\newif\ifFormatAsBook \FormatAsBooktrue
\newcommand\codesnippetsdir{snippets}
\newcommand\latexengine{,xetex}
\input commonmacs

View File

@@ -84,22 +84,16 @@ CFLAGS += ${OPTFLAGS}
CXXFLAGS += ${OPTFLAGS}
FFLAGS += ${OPTFLAGS}
## there are bugs in the qopenmp backend of Intel23
# ifdef INTEL_OMP_FLAG
# OMPFLAGS_intel = ${INTEL_OMP_FLAG}
# else ifeq "${INTEL23}" "23"
# else
# OMPFLAGS_intel = -qopenmp
# endif
OMPFLAGS_intel = -fopenmp
OMPFLAGS_oneapi = -qopenmp
OMPFLAGS_gcc = -ggdb -fopenmp
OMPFLAGS_clang = -fopenmp
OMPFLAGS_cuda = -mp=gpu
OMPFLAGS_nvidia = -fopenmp
OMPFLAGS_nvhpc = -fopenmp
OMPFLAGS_xl = -qsmp=omp -qoffload
ifeq "${MODE}" "ompg"
OMPFLAGS := -fiopenmp -fopenmp-targets=spir64
ifeq "${MODE}" "ompgpu"
OMPFLAGS := ${OMPFLAGS_${TACC_FAMILY_COMPILER}} -mp=gpu
else
OMPFLAGS := ${OMPFLAGS_${TACC_FAMILY_COMPILER}}
endif
@@ -113,10 +107,11 @@ else ifeq "${MODE}" "omp"
CFLAGS += ${OMPFLAGS}
CXXFLAGS += ${OMPFLAGS}
FFLAGS += ${OMPFLAGS}
else ifeq "${MODE}" "ompg"
else ifeq "${MODE}" "ompgpu"
CFLAGS += ${OMPFLAGS}
CXXFLAGS += ${OMPFLAGS}
FFLAGS += ${OMPFLAGS}
LINK_FLAGS += ${OMPFLAGS}
else ifeq "${MODE}" "tbb"
CFLAGS += ${OMPFLAGS}
CXXFLAGS += ${OMPFLAGS}
@@ -428,7 +423,7 @@ else ifeq "${MODE}" "hybrid"
LINK_FLAGS += ${OMPFLAGS}
else ifeq "${MODE}" "omp"
LINK_FLAGS += ${OMPFLAGS}
else ifeq "${MODE}" "ompg"
else ifeq "${MODE}" "ompgpu"
LINK_FLAGS += ${OMPFLAGS}
else ifeq "${MODE}" "tbb"
LINK_FLAGS += ${OMPFLAGS}

View File

@@ -1,5 +1,6 @@
// histogramwrong.c
for ( long int experiment=0; experiment<nexperiments; ++experiment ) {
int bin = rand_r(&seed)%nbins;
int bin;
for ( int r=0; r<1000; r++ ) bin = rand_r(&seed)%nbins;
bins[bin]++;
}

View File

@@ -1,5 +1,5 @@
// bigint.cxx
size_t s = static_cast<size_t>(1)<<(s0-1);
size_t s;
vector<char> buffer(s);
mpl::contiguous_layout<char> buffersize(s);
comm_world.send( buffer.data(),buffersize,processB );
comm_world.send( buffer.data(),buffersize,processB );

View File

@@ -1,11 +1,11 @@
!! vecarray.F90
PetscScalar,dimension(:),Pointer :: &
in_array,out_array
call VecGetArrayReadF90( x,in_array,ierr )
call VecGetArrayF90( y,out_array,ierr )
call VecGetArrayRead( x,in_array,ierr )
call VecGetArray( y,out_array,ierr )
call VecGetLocalSize( x,localsize,ierr )
do index=1,localsize
out_array(index) = 2*in_array(index)
end do
call VecRestoreArrayReadF90( x,in_array,ierr )
call VecRestoreArrayF90( y,out_array,ierr )
call VecRestoreArrayRead( x,in_array,ierr )
call VecRestoreArray( y,out_array,ierr )

View File

@@ -1,9 +1,9 @@
!! vecset.F90
Vec :: vector
PetscScalar,dimension(:),pointer :: elements
call VecGetArrayF90(vector,elements,ierr)
call VecGetArray(vector,elements,ierr)
write (msg,10) myrank,elements(1)
10 format("First element on process",i3,":",f7.4,"\n")
call PetscSynchronizedPrintf(comm,msg,ierr)
call PetscSynchronizedFlush(comm,PETSC_STDOUT,ierr)
call VecRestoreArrayF90(vector,elements,ierr)
call VecRestoreArray(vector,elements,ierr)

View File

@@ -1,3 +1,3 @@
auto [success,index] = recv_requests.waitany();
if ( success==mpl::test_result::completed ) {
auto [success,index] = recv_requests.waitany();
if ( success==mpl::test_result::completed ) {
auto recv_status = recv_requests.get_status(index);

View File

@@ -1,9 +1,9 @@
// commdupall.c
ierr = MPI_Isend(&sdata,1,MPI_INT,right,1,comm,&(request[0])); CHK(ierr);
function_start(comm,&ctx);
ierr = MPI_Irecv(&rdata,1,MPI_INT,left,MPI_ANY_TAG,comm,&(request[1])); CHK(ierr);
ierr = MPI_Waitall(2,request,status); CHK(ierr);
function_end(comm,ctx);
ierr = MPI_Isend(&sdata,1,MPI_INT,right,1,comm,&(request[0])); CHK(ierr);
function_start(comm,&ctx);
ierr = MPI_Irecv(&rdata,1,MPI_INT,left,MPI_ANY_TAG,comm,&(request[1])); CHK(ierr);
ierr = MPI_Waitall(2,request,status); CHK(ierr);
function_end(comm,ctx);
int function_start(MPI_Comm comm,void **ctx) {
int procno,nprocs,left,right, sdata=6,rdata, ierr;
MPI_Request *request;

View File

@@ -84,22 +84,16 @@ CFLAGS += ${OPTFLAGS}
CXXFLAGS += ${OPTFLAGS}
FFLAGS += ${OPTFLAGS}
## there are bugs in the qopenmp backend of Intel23
# ifdef INTEL_OMP_FLAG
# OMPFLAGS_intel = ${INTEL_OMP_FLAG}
# else ifeq "${INTEL23}" "23"
# else
# OMPFLAGS_intel = -qopenmp
# endif
OMPFLAGS_intel = -fopenmp
OMPFLAGS_oneapi = -qopenmp
OMPFLAGS_gcc = -ggdb -fopenmp
OMPFLAGS_clang = -fopenmp
OMPFLAGS_cuda = -mp=gpu
OMPFLAGS_nvidia = -fopenmp
OMPFLAGS_nvhpc = -fopenmp
OMPFLAGS_xl = -qsmp=omp -qoffload
ifeq "${MODE}" "ompg"
OMPFLAGS := -fiopenmp -fopenmp-targets=spir64
ifeq "${MODE}" "ompgpu"
OMPFLAGS := ${OMPFLAGS_${TACC_FAMILY_COMPILER}} -mp=gpu
else
OMPFLAGS := ${OMPFLAGS_${TACC_FAMILY_COMPILER}}
endif
@@ -113,10 +107,11 @@ else ifeq "${MODE}" "omp"
CFLAGS += ${OMPFLAGS}
CXXFLAGS += ${OMPFLAGS}
FFLAGS += ${OMPFLAGS}
else ifeq "${MODE}" "ompg"
else ifeq "${MODE}" "ompgpu"
CFLAGS += ${OMPFLAGS}
CXXFLAGS += ${OMPFLAGS}
FFLAGS += ${OMPFLAGS}
LINK_FLAGS += ${OMPFLAGS}
else ifeq "${MODE}" "tbb"
CFLAGS += ${OMPFLAGS}
CXXFLAGS += ${OMPFLAGS}
@@ -428,7 +423,7 @@ else ifeq "${MODE}" "hybrid"
LINK_FLAGS += ${OMPFLAGS}
else ifeq "${MODE}" "omp"
LINK_FLAGS += ${OMPFLAGS}
else ifeq "${MODE}" "ompg"
else ifeq "${MODE}" "ompgpu"
LINK_FLAGS += ${OMPFLAGS}
else ifeq "${MODE}" "tbb"
LINK_FLAGS += ${OMPFLAGS}

View File

@@ -3,11 +3,11 @@
####
#### This makefile is part of the source of
#### "Parallel Programming in MPI and OpenMP"
#### by Victor Eijkhout, copyright 2013-8
#### by Victor Eijkhout, copyright 2013-2025
####
#### Makefile for course support
####
################################################################
################################################################
include Make.clean
include ../../makefiles/Make.clean

View File

@@ -2,18 +2,19 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%% This text file is part of the source of
%%%% This text file is part of the source of
%%%% `Parallel Computing'
%%%% by Victor Eijkhout, copyright 2012-2025
%%%%
%%%% lang_all.tex : include file for all language selection
%%%% lang_x.tex : include file for C++/MPL language selection
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\includecomment{c}
\includecomment{cxx}
\includecomment{fortran}
\includecomment{python}
\includecomment{mpl}
\excludecomment{nompl}
\excludecomment{python}
\includecomment{nonpython}
\excludecomment{fortran}

View File

@@ -15,5 +15,6 @@
\includecomment{cxx}
\includecomment{fortran}
\includecomment{python}
\excludecomment{nonpython}
\includecomment{mpl}
\excludecomment{nompl}

View File

@@ -15,5 +15,6 @@
\excludecomment{cxx}
\excludecomment{fortran}
\excludecomment{python}
\includecomment{nonpython}
\excludecomment{mpl}
\includecomment{nompl}

View File

@@ -15,5 +15,6 @@
\excludecomment{c}
\includecomment{cxx}
\excludecomment{python}
\includecomment{nonpython}
\excludecomment{mpl}
\excludecomment{nompl}

View File

@@ -12,6 +12,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\includecomment{python}
\excludecomment{nonpython}
\excludecomment{fortran}
\excludecomment{c}
\includecomment{cxx}

View File

@@ -16,4 +16,5 @@
\includecomment{mpl}
\excludecomment{nompl}
\excludecomment{python}
\includecomment{nonpython}
\excludecomment{fortran}

View File

@@ -84,22 +84,16 @@ CFLAGS += ${OPTFLAGS}
CXXFLAGS += ${OPTFLAGS}
FFLAGS += ${OPTFLAGS}
## there are bugs in the qopenmp backend of Intel23
# ifdef INTEL_OMP_FLAG
# OMPFLAGS_intel = ${INTEL_OMP_FLAG}
# else ifeq "${INTEL23}" "23"
# else
# OMPFLAGS_intel = -qopenmp
# endif
OMPFLAGS_intel = -fopenmp
OMPFLAGS_oneapi = -qopenmp
OMPFLAGS_gcc = -ggdb -fopenmp
OMPFLAGS_clang = -fopenmp
OMPFLAGS_cuda = -mp=gpu
OMPFLAGS_nvidia = -fopenmp
OMPFLAGS_nvhpc = -fopenmp
OMPFLAGS_xl = -qsmp=omp -qoffload
ifeq "${MODE}" "ompg"
OMPFLAGS := -fiopenmp -fopenmp-targets=spir64
ifeq "${MODE}" "ompgpu"
OMPFLAGS := ${OMPFLAGS_${TACC_FAMILY_COMPILER}} -mp=gpu
else
OMPFLAGS := ${OMPFLAGS_${TACC_FAMILY_COMPILER}}
endif
@@ -113,10 +107,11 @@ else ifeq "${MODE}" "omp"
CFLAGS += ${OMPFLAGS}
CXXFLAGS += ${OMPFLAGS}
FFLAGS += ${OMPFLAGS}
else ifeq "${MODE}" "ompg"
else ifeq "${MODE}" "ompgpu"
CFLAGS += ${OMPFLAGS}
CXXFLAGS += ${OMPFLAGS}
FFLAGS += ${OMPFLAGS}
LINK_FLAGS += ${OMPFLAGS}
else ifeq "${MODE}" "tbb"
CFLAGS += ${OMPFLAGS}
CXXFLAGS += ${OMPFLAGS}
@@ -428,7 +423,7 @@ else ifeq "${MODE}" "hybrid"
LINK_FLAGS += ${OMPFLAGS}
else ifeq "${MODE}" "omp"
LINK_FLAGS += ${OMPFLAGS}
else ifeq "${MODE}" "ompg"
else ifeq "${MODE}" "ompgpu"
LINK_FLAGS += ${OMPFLAGS}
else ifeq "${MODE}" "tbb"
LINK_FLAGS += ${OMPFLAGS}

52
makefiles/Make.cuda Normal file
View File

@@ -0,0 +1,52 @@
# -*- makefile -*-
################################################################
################################################################
####
#### This make file is part of the source of
#### `Parallel Programing in Science and Engineering'
#### by Victor Eijkhout, copyright 2013-2025
####
#### This is a makefile for the programming exercises using CUDA
####
################################################################
################################################################
info ::
@echo "make srun srunout APP=... RUN_OPTIONS=... : build and run on GPU"
@echo " [ PROFILE= (nonzero for profiling) ]"
ifeq "${TACC_SYSTEM}" "frontera"
QUEUE = rtx-dev
else ifeq "${TACC_SYSTEM}" "ls6"
QUEUE = gpu-a100
else ifeq "${TACC_SYSTEM}" "vista"
QUEUE = gh-dev
endif
.PHONY: srun srunout
srunout : srun
@appout="${APP}.out" && runout="${APP}.runout" \
&& echo " .. copying to $${runout}" \
&& cat "$${appout}" \
| awk '/srun/ {s=1} s==1 && !/srun:/ {p=1} p==1 {print}' \
> "$${runout}" \
&& echo "----------------" \
&& cat "$${runout}" \
&& echo "----------------" \
&& if [ "${GITADD}" = "1" ] ; then \
git add "$${runout}" \
; fi
srun :
@if [ ! -z "${APP}" ] ; then \
make --no-print-directory ${APP} ECHO=${ECHO} \
&& appout="${APP}.out" \
&& cmdline="${APP} ${RUN_OPTIONS}" \
&& if [ ! -z "${PROFILE}" ] ; then \
cmdline="ncu $$cmdline" && appout="${APP}.prof_out" \
; fi \
&& if [ ! -z "${ECHO}" ] ; then \
echo "cmdline=$$cmdline" ; fi \
&& srun -A A-ccsc -N 1 -n 1 -t 0:5:0 -p ${QUEUE} $${cmdline} \
2>&1 | tee $${appout} \
&& echo && echo "See <<$$appout>> for output" && echo \
; else echo "Set variable APP [ RUN_OPTIONS=... ]" && exit 1 ; fi
clean ::
@rm -f *.ncu-rep

Binary file not shown.

BIN
pdfs/mpi_c_course.pdf Normal file

Binary file not shown.

Binary file not shown.

BIN
pdfs/mpi_f_course.pdf Normal file

Binary file not shown.

BIN
pdfs/mpi_p_course.pdf Normal file

Binary file not shown.

BIN
pdfs/mpi_x_course.pdf Normal file

Binary file not shown.

BIN
pdfs/mpibasics_c_course.pdf Normal file

Binary file not shown.

BIN
pdfs/mpibasics_course.pdf Normal file

Binary file not shown.

BIN
pdfs/mpibasics_f_course.pdf Normal file

Binary file not shown.

BIN
pdfs/mpibasics_p_course.pdf Normal file

Binary file not shown.

BIN
pdfs/mpibasics_x_course.pdf Normal file

Binary file not shown.

BIN
pdfs/omp_c_course.pdf Normal file

Binary file not shown.

BIN
pdfs/omp_x_course.pdf Normal file

Binary file not shown.

BIN
pdfs/ompcpp_course.pdf Normal file

Binary file not shown.

View File

@@ -84,22 +84,16 @@ CFLAGS += ${OPTFLAGS}
CXXFLAGS += ${OPTFLAGS}
FFLAGS += ${OPTFLAGS}
## there are bugs in the qopenmp backend of Intel23
# ifdef INTEL_OMP_FLAG
# OMPFLAGS_intel = ${INTEL_OMP_FLAG}
# else ifeq "${INTEL23}" "23"
# else
# OMPFLAGS_intel = -qopenmp
# endif
OMPFLAGS_intel = -fopenmp
OMPFLAGS_oneapi = -qopenmp
OMPFLAGS_gcc = -ggdb -fopenmp
OMPFLAGS_clang = -fopenmp
OMPFLAGS_cuda = -mp=gpu
OMPFLAGS_nvidia = -fopenmp
OMPFLAGS_nvhpc = -fopenmp
OMPFLAGS_xl = -qsmp=omp -qoffload
ifeq "${MODE}" "ompg"
OMPFLAGS := -fiopenmp -fopenmp-targets=spir64
ifeq "${MODE}" "ompgpu"
OMPFLAGS := ${OMPFLAGS_${TACC_FAMILY_COMPILER}} -mp=gpu
else
OMPFLAGS := ${OMPFLAGS_${TACC_FAMILY_COMPILER}}
endif
@@ -113,10 +107,11 @@ else ifeq "${MODE}" "omp"
CFLAGS += ${OMPFLAGS}
CXXFLAGS += ${OMPFLAGS}
FFLAGS += ${OMPFLAGS}
else ifeq "${MODE}" "ompg"
else ifeq "${MODE}" "ompgpu"
CFLAGS += ${OMPFLAGS}
CXXFLAGS += ${OMPFLAGS}
FFLAGS += ${OMPFLAGS}
LINK_FLAGS += ${OMPFLAGS}
else ifeq "${MODE}" "tbb"
CFLAGS += ${OMPFLAGS}
CXXFLAGS += ${OMPFLAGS}
@@ -428,7 +423,7 @@ else ifeq "${MODE}" "hybrid"
LINK_FLAGS += ${OMPFLAGS}
else ifeq "${MODE}" "omp"
LINK_FLAGS += ${OMPFLAGS}
else ifeq "${MODE}" "ompg"
else ifeq "${MODE}" "ompgpu"
LINK_FLAGS += ${OMPFLAGS}
else ifeq "${MODE}" "tbb"
LINK_FLAGS += ${OMPFLAGS}

View File

@@ -3,11 +3,11 @@
####
#### This makefile is part of the source of
#### "Parallel Programming in MPI and OpenMP"
#### by Victor Eijkhout, copyright 2013-8
#### by Victor Eijkhout, copyright 2013-2025
####
#### Makefile for course support
####
################################################################
################################################################
include Make.clean
include ../../makefiles/Make.clean

View File

@@ -0,0 +1,66 @@
% -*- latex -*-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%% This text file is part of the source of
%%%% `Parallel Computing'
%%%% by Victor Eijkhout, copyright 2012-2025
%%%%
%%%% courseformat.tex : common preable for courses
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% beamer setup
%%
%\usepackage{beamerthemeHPC}
\usepackage{beamerthemeTACC}
\usepackage{morewrites,multicol}
\usepackage{comment}
\input slides.inex
\input pcsecommonmacs
\input acromacs
\input commonmacs
\input listingmacs
\input slidemacs
\input pcseslidemacs
\input coursemacs
\input snippetmacs
\input standardmacs
\usepackage{morewrites}
\usepackage[original,nonewpage]{imakeidx}
\makeindex % default index
\input idxmacs
\input alsoidxmacs
\input pcseidxmacs
\input doxymacs
\includecomment{full}
\excludecomment{condensed}
\excludecomment{online}
\includecomment{utonly}
\includecomment{onesided}
\includecomment{advanced}
\excludecomment{solutions}
%%
%% slide parameters
%%
\renewcommand\snippetstyle{slidesnippetcode}
\newcommand\codesnippetsdir{../../snippets}
%%
%% LaTeX customizations
%%
\setcounter{tocdepth}{2}
\parskip=10pt plus 5pt minus 3pt

View File

@@ -2,18 +2,19 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%% This text file is part of the source of
%%%% This text file is part of the source of
%%%% `Parallel Computing'
%%%% by Victor Eijkhout, copyright 2012-2025
%%%%
%%%% lang_all.tex : include file for all language selection
%%%% lang_x.tex : include file for C++/MPL language selection
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\includecomment{c}
\includecomment{cxx}
\includecomment{fortran}
\includecomment{python}
\includecomment{mpl}
\excludecomment{nompl}
\excludecomment{python}
\includecomment{nonpython}
\excludecomment{fortran}

View File

@@ -15,5 +15,6 @@
\includecomment{cxx}
\includecomment{fortran}
\includecomment{python}
\excludecomment{nonpython}
\includecomment{mpl}
\excludecomment{nompl}

View File

@@ -15,5 +15,6 @@
\excludecomment{cxx}
\excludecomment{fortran}
\excludecomment{python}
\includecomment{nonpython}
\excludecomment{mpl}
\includecomment{nompl}

View File

@@ -15,5 +15,6 @@
\excludecomment{c}
\includecomment{cxx}
\excludecomment{python}
\includecomment{nonpython}
\excludecomment{mpl}
\excludecomment{nompl}

View File

@@ -12,6 +12,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\includecomment{python}
\excludecomment{nonpython}
\excludecomment{fortran}
\excludecomment{c}
\includecomment{cxx}

View File

@@ -16,4 +16,5 @@
\includecomment{mpl}
\excludecomment{nompl}
\excludecomment{python}
\includecomment{nonpython}
\excludecomment{fortran}