Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
AlephCudaVector.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7#include "arcane/aleph/AlephArcane.h"
8#include "arcane/aleph/cuda/AlephCuda.h"
9
10
11//---------------------------------------------------------------------------//
12
13
14ARCANE_BEGIN_NAMESPACE
15
16template <class T> CNC_Vector<T>::CNC_Vector(unsigned int size, unsigned int alignment) {
17 data_ = NULL ;
18 base_mem_ = NULL ;
19 size_ = 0 ;
20 allocate(size, alignment) ;
21}
22
23template <class T> CNC_Vector<T>::~CNC_Vector() { deallocate() ; }
24
25//---------------------------------------------------------------------------//
26
28template <class T> void CNC_Vector<T>::allocate(unsigned int size, unsigned int alignment) {
29 deallocate() ;
30 if(size != 0) {
31 base_mem_ = (char*)malloc(size * sizeof(T) + alignment -1) ;
32 char* p = base_mem_ ;
33 // GMY 20090825 original: while(unsigned __int64(p) % alignment) { p++ ; }
34 while (((unsigned long long) p) % alignment) { ++p; }
35 data_ = (T*)p ;
36 for(unsigned int i=0; i<size; i++) {
37 // Direct call to the constructor, see dlist.h for more explanations.
38 new(&data_[i])T() ;
39 }
40 }
41 size_ = size ;
42}
43
44//---------------------------------------------------------------------------//
45
46template <class T> void CNC_Vector<T>::set_all(const T& value) {
47 for(unsigned int i=0; i<size_; i++) {
48 data_[i] = value ;
49 }
50}
51
52//---------------------------------------------------------------------------//
53
54template <class T> T& CNC_Vector<T>::operator()(unsigned int i) {
55 return data_[i] ;
56}
57
58//---------------------------------------------------------------------------//
59
60template <class T> const T& CNC_Vector<T>::operator()(unsigned int i) const {
61 return data_[i] ;
62}
63
64//---------------------------------------------------------------------------//
65
66template <class T> T& CNC_Vector<T>::operator[](unsigned int index) {
67 return data_[index] ;
68}
69
70//---------------------------------------------------------------------------//
71
72template <class T> const T& CNC_Vector<T>::operator[](unsigned int index) const {
73 return data_[index] ;
74}
75
76//---------------------------------------------------------------------------//
78template <class T> T& CNC_Vector<T>::from_linear_index(unsigned int index) {
79 return data_[index] ;
80}
81
82//---------------------------------------------------------------------------//
83
84template <class T> const T& CNC_Vector<T>::from_linear_index(unsigned int index) const {
85 return data_[index] ;
86}
87
88//---------------------------------------------------------------------------//
89
90template <class T> unsigned int CNC_Vector<T>::size() const { return size_ ; }
91
92//---------------------------------------------------------------------------//
93
94template <class T> unsigned int CNC_Vector<T>::alignment() const { return alignment_ ; }
95
96//---------------------------------------------------------------------------//
97
98template <class T> void CNC_Vector<T>::clear() { allocate(0) ; }
99
100//---------------------------------------------------------------------------//
101
103template <class T> const T* CNC_Vector<T>::data() const { return data_ ; }
104
105//---------------------------------------------------------------------------//
106
108template <class T> T* CNC_Vector<T>::data() { return data_ ; }
109
110//---------------------------------------------------------------------------//
111
112template <class T> unsigned int CNC_Vector<T>::mem_usage() const {
113 return size_ * sizeof(T) + sizeof(thisclass) ;
114}
115
116//---------------------------------------------------------------------------//
117
118template <class T> void CNC_Vector<T>::print () const {
119 for(unsigned int index=0; index<size_; index++){
120 //printf("\t[%d]=%ld\n", index, data_[index]);
121 }
122}
123
124
125//---------------------------------------------------------------------------//
126
127template <class T> void CNC_Vector<T>::deallocate() {
128 if(size_ != 0) {
129 for(unsigned int i=0; i<size_; i++) {
130 // direct call to the destructor
131 data_[i].~T() ;
132 }
133 free(base_mem_) ;
134 data_ = NULL ;
135 base_mem_ = NULL ;
136 size_ = 0 ;
137 }
138}
139
140
141template class CNC_Vector<double>;
142template class CNC_Vector<long>;
143template class CNC_Vector<std::set<unsigned int> >;
144
145
146ARCANE_END_NAMESPACE
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120