Tinker9 70bd052 (Thu Nov 9 12:11:35 2023 -0800)
Loading...
Searching...
No Matches
dvector.h
1#pragma once
2#include "tool/darray.h"
3
4namespace tinker {
5template <class T>
7{
8 typedef T value_type;
9
10 DeviceAllocator() noexcept {}
11
12 template <class U>
14 {}
15
16 template <class U>
17 bool operator==(const DeviceAllocator<U>&) const noexcept
18 {
19 return true;
20 }
21
22 template <class U>
23 bool operator!=(const DeviceAllocator<U>&) const noexcept
24 {
25 return false;
26 }
27
28 T* allocate(size_t n) const
29 {
30 T* p;
31 if (n != 0)
33 else
34 p = nullptr;
35 return p;
36 }
37
38 void deallocate(T* const p, size_t) const noexcept
39 {
40 if (p) darray::deallocate(p);
41 }
42};
43}
44
45namespace tinker {
46template <class T>
47class dvector : private std::vector<T, DeviceAllocator<T>>
48{
49private:
50 typedef std::vector<T, DeviceAllocator<T>> Base;
51
52 using Base::resize; // Resizing is not allowed.
53
54public:
55 using Base::data;
56 using Base::reserve;
57};
58}
Definition: dvector.h:48
int n
Number of atoms padded by WARP_SIZE.
static void deallocate(PTR p)
Definition: darray.h:154
static void allocate(size_t nelem, PTR *pp)
Definition: darray.h:139
Definition: testrt.h:9
Definition: dvector.h:7
void deallocate(T *const p, size_t) const noexcept
Definition: dvector.h:38
T value_type
Definition: dvector.h:8
DeviceAllocator(const DeviceAllocator< U > &) noexcept
Definition: dvector.h:13
bool operator!=(const DeviceAllocator< U > &) const noexcept
Definition: dvector.h:23
T * allocate(size_t n) const
Definition: dvector.h:28
bool operator==(const DeviceAllocator< U > &) const noexcept
Definition: dvector.h:17
DeviceAllocator() noexcept
Definition: dvector.h:10