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:
boufaras 2011-03-14 17:01:36 +00:00
commit f1916d1880

View file

@ -2,7 +2,7 @@
<moCudaVector.h> <moCudaVector.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 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 This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use, 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]; vect = new ElemType[_size];
create(); //create();
} }
/** /**
@ -78,7 +78,7 @@ template<class ElemT, class Fitness>
*/ */
~moCudaVector() { ~moCudaVector() {
if (N > 1) if (N >= 1)
delete[] vect; delete[] vect;
} }
@ -86,9 +86,7 @@ template<class ElemT, class Fitness>
*How to fill the vector. *How to fill the vector.
*/ */
virtual void create() { virtual void create() =0;
}
/** /**
*Assignment operator *Assignment operator
@ -98,6 +96,8 @@ template<class ElemT, class Fitness>
virtual moCudaVector& operator=(const moCudaVector & _vector) { virtual moCudaVector& operator=(const moCudaVector & _vector) {
if (N >= 1)
delete[] vect;
N = _vector.N; N = _vector.N;
vect = new ElemType[N]; vect = new ElemType[N];
for (unsigned i = 0; i < N; i++) 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). *An accessor read only on the i'th element of the vector (function inline can be called from host or device).
*@param *@param _i The i'th element of vector.
*_i The i'th element of vector. *@return The i'th element of the vector for read only
*@return
*The i'th element of the vector for read only
*/ */
inline __host__ __device__ const ElemType & operator[](unsigned _i) const { 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 { virtual void printOn(std::ostream& os) const {
EO<Fitness>::printOn(os); EO<Fitness>::printOn(os);
os << ' '; os << ' ';