Discontinuous Galerkin Library
#include "dg/algorithm.h"
average_dispatch.h
Go to the documentation of this file.
1#pragma once
2
3#include "../blas2.h"
4#include "average_cpu.h"
5#if THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_CUDA
6#include "average_gpu.cuh"
7#elif THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_OMP
8#include "average_omp.h"
9#endif
10
11namespace dg{
14
25template<class ContainerType>
26void transpose( unsigned nx, unsigned ny, const ContainerType& in, ContainerType& out)
27{
28 assert(&in != &out);
29 using value_type = get_value_type<ContainerType>;
30 dg::blas2::parallel_for( [nx,ny]DG_DEVICE( unsigned k, const value_type* ii, value_type* oo)
31 {
32 unsigned i = k/nx, j = k%nx;
33 oo[j*ny+i] = ii[i*nx+j];
34 }, nx*ny, in, out);
35}
36
46template<class ContainerType>
47void extend_line( unsigned nx, unsigned ny, const ContainerType& in, ContainerType& out)
48{
49 assert(&in != &out);
50 using value_type = get_value_type<ContainerType>;
51 dg::blas2::parallel_for( [nx]DG_DEVICE( unsigned k, const value_type* ii, value_type* oo)
52 {
53 unsigned i = k/nx, j = k%nx;
54 oo[i*nx+j] = ii[j];
55 }, nx*ny, in, out);
56}
66template<class ContainerType>
67void extend_column( unsigned nx, unsigned ny, const ContainerType& in, ContainerType& out)
68{
69 assert(&in != &out);
70 using value_type = get_value_type<ContainerType>;
71 dg::blas2::parallel_for( [nx]DG_DEVICE( unsigned k, const value_type* ii, value_type* oo)
72 {
73 unsigned i = k/nx, j = k%nx;
74 oo[i*nx+j] = ii[i];
75 }, nx*ny, in, out);
76}
78
80template<class ContainerType>
81void average( unsigned nx, unsigned ny, const ContainerType& in0, const ContainerType& in1, ContainerType& out)
82{
83 static_assert( std::is_same<get_value_type<ContainerType>, double>::value, "We only support double precision dot products at the moment!");
84 const double* in0_ptr = thrust::raw_pointer_cast( in0.data());
85 const double* in1_ptr = thrust::raw_pointer_cast( in1.data());
86 double* out_ptr = thrust::raw_pointer_cast( out.data());
87 average( get_execution_policy<ContainerType>(), nx, ny, in0_ptr, in1_ptr, out_ptr);
88}
89
90#ifdef MPI_VERSION
91template<class ContainerType>
92void mpi_average( unsigned nx, unsigned ny, const ContainerType& in0, const ContainerType& in1, ContainerType& out, MPI_Comm comm, MPI_Comm comm_mod, MPI_Comm comm_mod_reduce)
93{
94 static_assert( std::is_same<get_value_type<ContainerType>, double>::value, "We only support double precision dot products at the moment!");
95 const double* in0_ptr = thrust::raw_pointer_cast( in0.data());
96 const double* in1_ptr = thrust::raw_pointer_cast( in1.data());
97 double* out_ptr = thrust::raw_pointer_cast( out.data());
98 average_mpi( get_execution_policy<ContainerType>(), nx, ny, in0_ptr, in1_ptr, out_ptr, comm, comm_mod, comm_mod_reduce);
99}
100#endif //MPI_VERSION
102
103}//namespace dg
#define DG_DEVICE
Expands to __host__ __device__ if compiled with nvcc else is empty.
Definition: functions.h:9
void parallel_for(Stencil f, unsigned N, ContainerType &&x, ContainerTypes &&... xs)
; Customizable and generic for loop
Definition: blas2.h:378
void extend_column(unsigned nx, unsigned ny, const ContainerType &in, ContainerType &out)
Copy a line into columns of output vector.
Definition: average_dispatch.h:67
void extend_line(unsigned nx, unsigned ny, const ContainerType &in, ContainerType &out)
Copy a line into rows of output vector.
Definition: average_dispatch.h:47
void transpose(unsigned nx, unsigned ny, const ContainerType &in, ContainerType &out)
Transpose vector.
Definition: average_dispatch.h:26
typename TensorTraits< std::decay_t< Vector > >::value_type get_value_type
Definition: tensor_traits.h:38
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...