Setter of size and optimize assignment operator
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2192 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
e7f40af5f7
commit
f1916d1880
1 changed files with 123 additions and 110 deletions
|
|
@ -2,7 +2,7 @@
|
|||
<moCudaVector.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Thé Van LUONG, Karima Boufaras
|
||||
Karima Boufaras, Thé Van LUONG
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can use,
|
||||
|
|
@ -70,7 +70,7 @@ template<class ElemT, class Fitness>
|
|||
|
||||
vect = new ElemType[_size];
|
||||
|
||||
create();
|
||||
//create();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -78,7 +78,7 @@ template<class ElemT, class Fitness>
|
|||
*/
|
||||
|
||||
~moCudaVector() {
|
||||
if (N > 1)
|
||||
if (N >= 1)
|
||||
delete[] vect;
|
||||
}
|
||||
|
||||
|
|
@ -86,9 +86,7 @@ template<class ElemT, class Fitness>
|
|||
*How to fill the vector.
|
||||
*/
|
||||
|
||||
virtual void create() {
|
||||
|
||||
}
|
||||
virtual void create() =0;
|
||||
|
||||
/**
|
||||
*Assignment operator
|
||||
|
|
@ -98,6 +96,8 @@ template<class ElemT, class Fitness>
|
|||
|
||||
virtual moCudaVector& operator=(const moCudaVector & _vector) {
|
||||
|
||||
if (N >= 1)
|
||||
delete[] vect;
|
||||
N = _vector.N;
|
||||
vect = new ElemType[N];
|
||||
for (unsigned i = 0; i < N; i++)
|
||||
|
|
@ -109,10 +109,8 @@ template<class ElemT, class Fitness>
|
|||
|
||||
/**
|
||||
*An accessor read only on the i'th element of the vector (function inline can be called from host or device).
|
||||
*@param
|
||||
*_i The i'th element of vector.
|
||||
*@return
|
||||
*The i'th element of the vector for read only
|
||||
*@param _i The i'th element of vector.
|
||||
*@return The i'th element of the vector for read only
|
||||
*/
|
||||
|
||||
inline __host__ __device__ const ElemType & operator[](unsigned _i) const {
|
||||
|
|
@ -144,6 +142,21 @@ template<class ElemT, class Fitness>
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
*Function inline to set the size of vector, called from host and device.
|
||||
*@param _size the vector size
|
||||
*/
|
||||
|
||||
inline __host__ __device__ void setSize(unsigned _size) {
|
||||
|
||||
N=_size;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the solution
|
||||
*/
|
||||
|
||||
virtual void printOn(std::ostream& os) const {
|
||||
EO<Fitness>::printOn(os);
|
||||
os << ' ';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue