diff --git a/cuda-omp/omp/miscellaneous/globals/Makefile b/cuda-omp/omp/miscellaneous/globals/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..6c7346495430f207e785e71f00d2cc426c2192ba --- /dev/null +++ b/cuda-omp/omp/miscellaneous/globals/Makefile @@ -0,0 +1,32 @@ +COMPILER_CXX ?= clang++-18 +DEBUG ?= YES +FLAGS ?= -fopenmp --offload-arch=native -fopenmp-targets=nvptx64-nvidia-cuda + +# executable name +EXEC ?= globals + +SYSTYPE ?= $(strip $(shell uname -n)) + + +############ DEBUG configuration ################################### +ifeq ($(DEBUG), YES) +OPT = -O0 -g +else +OPT = -O3 +endif +#################################################################### + +.PHONY: clean + +HEADERS = $(shell find . -name "*.hpp" -type f) +SOURCES = $(shell find . -name "*.cpp" -type f) +DEPENDENCIES = $(SOURCES) $(HEADERS) Makefile +CFLAGS = -Wall -Wextra -v -march=native -mtune=native + +$(EXEC): $(DEPENDENCIES) + $(COMPILER_CXX) $(CFLAGS) $(FLAGS) $(OPT) $(SOURCES) -o $@ + ldd $(EXEC) + @echo -e '\n\t Program' $@ 'compiled for' $(SYSTYPE) 'machine \n' + +clean: + rm -rf $(EXEC) *~ diff --git a/cuda-omp/omp/miscellaneous/globals/allvars.cpp b/cuda-omp/omp/miscellaneous/globals/allvars.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9b7b46fa3aede1fd1b4a7d477c43d670fb60bf8a --- /dev/null +++ b/cuda-omp/omp/miscellaneous/globals/allvars.cpp @@ -0,0 +1,3 @@ +#include "allvars.hpp" + +MyData ***global_ptr{nullptr}; diff --git a/cuda-omp/omp/miscellaneous/globals/allvars.hpp b/cuda-omp/omp/miscellaneous/globals/allvars.hpp new file mode 100644 index 0000000000000000000000000000000000000000..50907cb09a9c06c240dfc015cb69f3ab5893d716 --- /dev/null +++ b/cuda-omp/omp/miscellaneous/globals/allvars.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include <cstddef> + +constexpr std::size_t X = 3; +constexpr std::size_t Y = 6; +constexpr std::size_t Z = 65536; +using MyData = double; + +// Global pointer declared in target region +#pragma omp declare target +extern MyData ***global_ptr; +#pragma omp end declare target diff --git a/cuda-omp/omp/miscellaneous/globals/globals.cpp b/cuda-omp/omp/miscellaneous/globals/globals.cpp new file mode 100644 index 0000000000000000000000000000000000000000..287a09df0014defc3aabc492692a7496b2858e13 --- /dev/null +++ b/cuda-omp/omp/miscellaneous/globals/globals.cpp @@ -0,0 +1,87 @@ +#include <iostream> +#include <vector> +#include <omp.h> +#include <cassert> +#include <new> + +#include "allvars.hpp" + +int main() +{ + // allocate memory on the host and set the global pointer + global_ptr = new (std::nothrow) MyData** [X]; + assert(global_ptr != nullptr); + for (std::size_t x=0 ; x<X ; x++) + { + global_ptr[x] = new (std::nothrow) MyData* [Y]; + assert(global_ptr[x] != nullptr); + + for (std::size_t y=0 ; y<Y ; y++) + { + global_ptr[x][y] = new (std::nothrow) MyData [Z]; + assert(global_ptr[x][y] != nullptr); + + for (std::size_t z=0 ; z<Z ; z++) + { + global_ptr[x][y][z] = static_cast<MyData>(1); + } // loop over Z + } // loop over Y + } // loop over X + + std::cout << "\n\t global_ptr allocated on the host \n" << std::endl; + +// // Allocate memory on the device and set the global pointer +// #pragma omp target enter data map(alloc: global_ptr[0:1][0:6][0:SIZE]) + +// for + + +// // Copy data from host to device +// #pragma omp target data map(to: host_data[0: SIZE]) +// { +// #pragma omp target teams distribute parallel for +// for (int index=0 ; index<SIZE ; index++) +// { +// const int tid = omp_get_thread_num(); +// const int team = omp_get_team_num(); +// const int nthr = omp_get_num_threads(); +// const int whoAmI = tid + (team * nthr); + +// MyData diff[6]; +// for (std::size_t i=0 ; i<6 : i++) +// { +// diff[i] = global_ptr[0][i][index] * ; +// } + +// { +// global_ptr[i] = (host_data[i] * 2); +// } +// } // kernel + +// // Copy data back from device to host using the global pointer +// #pragma omp target update from(global_ptr[0: SIZE]) +// } + +// std::cout << "\n\t Result after device computation:" << std::endl; +// for (std::size_t i=0 ; i<SIZE ; i++) +// { +// std::cout << global_ptr[i] << " "; +// } +// std::cout << std::endl; + + // Deallocate memory on the device + //#pragma omp target exit data map(delete: global_ptr) + + // deallocate host memory + for (std::size_t x=0 ; x<X ; x++) + { + for (std::size_t y=0 ; y<Y ; y++) + { + delete[] global_ptr[x][y]; + } + delete[] global_ptr[x]; + } + delete[] global_ptr; + + return 0; +} diff --git a/jacobi/mpi/miscellaneous/cartesian b/jacobi/mpi/miscellaneous/cartesian deleted file mode 100755 index c0bc080fe492702435b30f6f5d19d4a8fe49a821..0000000000000000000000000000000000000000 Binary files a/jacobi/mpi/miscellaneous/cartesian and /dev/null differ diff --git a/jacobi/mpi/miscellaneous/subarray b/jacobi/mpi/miscellaneous/subarray deleted file mode 100644 index 5295b41860fe0dfe7b99d8b60a0c49a893e90303..0000000000000000000000000000000000000000 Binary files a/jacobi/mpi/miscellaneous/subarray and /dev/null differ