Skip to content

Commit

Permalink
Update Src Code Cmakefiles for Cuda
Browse files Browse the repository at this point in the history
  • Loading branch information
lemoinep committed Sep 25, 2023
1 parent 651f4da commit db4ab76
Show file tree
Hide file tree
Showing 18 changed files with 954 additions and 793 deletions.
302 changes: 302 additions & 0 deletions docs/modules/ROOT/assets/images/domain-decomposition.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/modules/ROOT/assets/images/eq1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/modules/ROOT/assets/images/eq2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/modules/ROOT/assets/images/eq3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/modules/ROOT/assets/images/eq4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions docs/modules/ROOT/pages/HEAT_Coding.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
= Heat Equation Parallel Programming Comparison



.Heat equation in 2D
[.examp]
****

* Theory
Heat (or diffusion) equation is a partial differential equation that describes the variation of temperature in a given region over time


\begin{align*}
\frac{\partial u}{\partial t} = \alpha \nabla^2 u
\end{align*}


image::eq1.png[Img901]

where *u*(*x*, *y*, *t*) is the temperature field that varies in space and
time, and α is the thermal diffusivity constant.

We limit ourselvels to two dimensions (a plane) where Laplacian can be
discretized in a grid with finite differences as


\begin{align*}
\nabla^2 u &= \frac{u(i-1,j)-2u(i,j)+u(i+1,j)}{(\Delta x)^2} \\
&+ \frac{u(i,j-1)-2u(i,j)+u(i,j+1)}{(\Delta y)^2}
\end{align*}

where ∆x and ∆y are the grid spacing of the temperature grid *u*.

Given an initial condition (*u*(t=0) = u0) one can follow the time dependence
of the temperature field with explicit time evolution method:

\begin{align*}
u^{m+1}(i,j) = u^m(i,j) + \Delta t \alpha \nabla^2 u^m(i,j)
\end{align*}


Note: The algorithm is stable only when

\begin{align*}
\Delta t < \frac{1}{2 \alpha} \frac{(\Delta x \Delta y)^2}{(\Delta x)^2 (\Delta y)^2}
\end{align*}

****
.Code
[.examp]
****
The solver carries out the time development of the 2D heat equation over the number of time steps provided by the user. The default geometry is a flat
rectangle (with grid size provided by the user), but other shapes may be used via input files. The program will produce an image (PNG) of the temperature field after every 100 iterations.

.Heat equation solver with MPI
[source,cpp]
----
include::ROOT:example$src/Heat_Equation_ParallelPrograming_Comparison/MPI/main.cpp[indent=0]
----

.Heat equation solver with hybrid MPI+OpenMP
[source,cpp]
----
include::ROOT:example$src/Heat_Equation_ParallelPrograming_Comparison/MPI_OpenMP/main.cpp[indent=0]
----


.Heat equation solver with Cuda
[source,cu]
----
include::ROOT:example$src/Heat_Equation_ParallelPrograming_Comparison/Cuda/core_cuda.cu[indent=0]
----
****
.*Performance*
****
ADD SOME RESULTS
****







...

5 changes: 5 additions & 0 deletions docs/modules/ROOT/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,9 @@ image::ParallelProgramming1.jpeg[Img3,400,400]
* xref:SPECX_Coding.adoc[SPECX Coding]
****

.Case Studies
[.examp]
****
* xref:HEAT_Coding.adoc[Case Study Heat Coding]
****

7 changes: 5 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ if(FALSE)
add_subdirectory(CUDA/Parallelism_Reduction)
add_subdirectory(CUDA/SimpleStreams)
add_subdirectory(CUDA/Start)
add_subdirectory(CUDA/Task_Paralllism)
add_subdirectory(CUDA/Vector)
add_subdirectory(CUDA/Task_Paralllism/Async1)
add_subdirectory(CUDA/Task_Paralllism/Async2)
add_subdirectory(CUDA/Vector/MatrixAdd)
add_subdirectory(CUDA/Vector/VectorAdd)
add_subdirectory(CUDA/Vector/VectorDotProduct)
endif()
#END:CUDA PART

Expand Down
103 changes: 103 additions & 0 deletions src/Cuda/DynamicSync/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@

#project(MPI_bcast)

######## A simple cmakelists.txt file for ... #############

cmake_minimum_required(VERSION 3.17)
#set(CMAKE_CXX_STANDARD 14)
#set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_BUILD_TYPE Release)
#set(CMAKE_CXX_COMPILER "/usr/local/bin/g++")
#set(CMAKE_CXX_STANDARD 14)
#set(CMAKE_CXX_COMPILER "/usr/local/bin/g++")
#set(CMAKE_C_COMPILER "/usr/bin/clang-14")
#set(CMAKE_CXX_COMPILER "/usr/bin/clang++-14")
#set(CMAKE_CXX_COMPILER "/usr/bin/gcc")
#set(CMAKE_CXX_COMPILER "/usr/bin/g++-11")



if(FALSE)
find_package(MPI REQUIRED)
if (MPI_FOUND)
MESSAGE("{MPI_CXX_LIBRARIES}")
else (MPI_FOUND)
MESSAGE (SEND_ERROR "This application cannot compile without MPI")
endif(MPI_FOUND)
endif()


if(FALSE)
find_package(OpenMP)
if (OpenMP_CXX_FOUND)
MESSAGE("{OpenMP_CXX_LIBRARIES}")
else (OpenMP_CXX_FOUND)
MESSAGE (SEND_ERROR "This application cannot compile without OpenMPI")
endif(OpenMP_CXX_FOUND)
endif()


find_package(CUDA REQUIRED)

if (CUDA_FOUND)
MESSAGE("{CUDA_CXX_LIBRARIES}")
else (CUDA_FOUND)
MESSAGE (SEND_ERROR "This application cannot compile without CUDA")
endif(CUDA_FOUND)

add_definitions(-D_FORCE_INLINES)

#set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --gpu-architecture sm_21 -std=c++11)

set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS}; -O3 )

file(GLOB WFOPenMP_SRC
"*.cu"
)

foreach (myfile ${WFOPenMP_SRC})
get_filename_component(myname ${myfile} NAME_WLE)
get_filename_component(dirname ${myfile} DIRECTORY)
message("${myname}.cu | ${dir_src}")
#add_executable(${myname} "${myname}.c")

cuda_add_executable(${myname} "${myname}.cu")

#target_link_libraries( ${myname} -lfoobar -ljoestuff )

#if(MPI_FOUND)
#include_directories(SYSTEM ${MPI_INCLUDES_PATH})
#target_include_directories(${myname} PUBLIC ${MPI_CXX_INCLUDE_DIRS})
#target_link_libraries(${myname} PUBLIC ${MPI_CXX_LIBRARIES} )
#endif()


endforeach (file ${WFOPenMP_SRC})


if(FALSE)
file(GLOB WFOPenMP_SRC
"*.cpp"
"*.h"
)

foreach (myfile ${WFOPenMP_SRC})
get_filename_component(myname ${myfile} NAME_WLE)
get_filename_component(dirname ${myfile} DIRECTORY)
message("${myname}.cpp | ${dir_src}")
#add_executable(${myname} "${myname}.c")

cuda_add_executable(${myname} "${myname}.cpp")

#target_link_libraries( ${myname} -lfoobar -ljoestuff )

#if(MPI_FOUND)
#include_directories(SYSTEM ${MPI_INCLUDES_PATH})
#target_include_directories(${myname} PUBLIC ${MPI_CXX_INCLUDE_DIRS})
#target_link_libraries(${myname} PUBLIC ${MPI_CXX_LIBRARIES} )
#endif()
endforeach (file ${WFOPenMP_SRC})
endif()


########### end ####################################
103 changes: 103 additions & 0 deletions src/Heat_Equation_ParallelPrograming_Comparison/Cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
project(HEATDemoCuda)

######## A simple cmakelists.txt file for Open... #############
#cmake_minimum_required(VERSION 3.26)
cmake_minimum_required(VERSION 3.17)
#set(CMAKE_CXX_STANDARD 14)
set(CMAKE_BUILD_TYPE Debug)
#set(CMAKE_BUILD_TYPE Release)
#set(CMAKE_CXX_COMPILER "/usr/local/bin/g++")
#set(CMAKE_CXX_STANDARD 14)
#set(CMAKE_CXX_COMPILER "/usr/local/bin/g++")
#set(CMAKE_C_COMPILER "/usr/bin/clang-14")
#set(CMAKE_CXX_COMPILER "/usr/bin/clang++-14")
#set(CMAKE_CXX_COMPILER "/usr/bin/gcc")
#set(CMAKE_CXX_COMPILER "/usr/bin/g++-11")


include_directories("../common")



if(TRUE)
find_package(MPI REQUIRED)
if (MPI_FOUND)
MESSAGE("{MPI_CXX_LIBRARIES}")
else (MPI_FOUND)
MESSAGE (SEND_ERROR "This application cannot compile without MPI")
endif(MPI_FOUND)
endif()

if(FALSE)
find_package(OpenMP)
if (OpenMP_CXX_FOUND)
MESSAGE("{OpenMP_CXX_LIBRARIES}")
else (OpenMP_CXX_FOUND)
MESSAGE (SEND_ERROR "This application cannot compile without OpenMP")
endif(OpenMP_CXX_FOUND)
endif()


find_package(CUDA REQUIRED)

if (CUDA_FOUND)
MESSAGE("{CUDA_CXX_LIBRARIES}")
MESSAGE(STATUS "Found headers CUDA : ${CUDA_INCLUDE_DIRS}")
MESSAGE(STATUS "Found lib CUDA : ${CUDA_LIBRARIES}")
MESSAGE(STATUS "Found CUDA nvcc : ${CUDA_NVCC_EXECUTABLE}")
else (CUDA_FOUND)
MESSAGE (SEND_ERROR "This application cannot compile without CUDA")
endif(CUDA_FOUND)

add_definitions(-D_FORCE_INLINES)

#set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --gpu-architecture sm_21 -std=c++11)

set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS}; -O3 )

find_package(PNG REQUIRED)
if (PNG_FOUND)
MESSAGE("{PNG_LIBRARIES}")
else (PNG_FOUND)
MESSAGE (SEND_ERROR "This application cannot compile without PNG")
endif(PNG_FOUND)


#file(GLOB my_cpp_list "${CMAKE_CURRENT_SOURCE_DIR}/common/*.c")
file(GLOB my_common_list
"${CMAKE_CURRENT_SOURCE_DIR}/../common/*.c"
"${CMAKE_CURRENT_SOURCE_DIR}/../common/*.h"
)

if (FALSE)
message(${CMAKE_CURRENT_SOURCE_DIR})
foreach(file_path ${my_cpp_list} ${my_common_list})
message(${file_path})
endforeach()
endif()


file(GLOB All_SRC
"*.h"
"*.cpp"
"*.cu"
)


#add_executable(HEATDemoCuda main.cpp ${All_SRC} ${my_common_list})

cuda_add_executable(HEATDemoCuda ${All_SRC} ${my_common_list})

include_directories(SYSTEM ${MPI_INCLUDES_PATH})
target_include_directories(HEATDemoCuda PUBLIC ${MPI_CXX_INCLUDE_DIRS} ${PNG_INCLUDE_DIR} ${CUDA_INCLUDE_DIRS})
#target_link_libraries(HEATDemoCuda PUBLIC ${MPI_CXX_LIBRARIES} ${PNG_LIBRARY} PUBLIC cuda)
#cuda_add_library(HEATDemoCuda PUBLIC ${MPI_CXX_LIBRARIES} ${PNG_LIBRARY} )
#add_library(HEATDemoCuda PUBLIC ${MPI_CXX_LIBRARIES} ${PNG_LIBRARY})

#target_link_libraries(HEATDemoCuda PUBLIC ${MPI_CXX_LIBRARIES} ${PNG_LIBRARY} ${CUDA_LIBRARIES})

target_link_libraries(HEATDemoCuda ${MPI_CXX_LIBRARIES})
target_link_libraries(HEATDemoCuda ${PNG_LIBRARY})
#target_link_libraries(HEATDemoCuda ${CUDA_LIBRARIES})


Loading

0 comments on commit db4ab76

Please sign in to comment.