Blitz logo

Blitz Devel :

From: Patrick Guio (patrick.guio_at_[hidden])
Date: 2002-10-09 17:18:38


On Wed, 9 Oct 2002, Theodore Papadopoulo wrote:

I have tried the patches with both Intell icc/linux and g++ 2.96 linux and
I get into trouble with testsuite/Adnene-Ben-Abdallah-1.cpp

With icc, I get the following error message
../blitz/array-impl.h(2478): error: swap is not a template
      friend void
swap<>(Array<P_numtype,N_rank>&,Array<P_numtype,N_rank>&);
                  ^
          detected during instantiation of class "blitz::Array<P_numtype,
N_rank> [with P_numtype=double, N_rank=1]" at line 7 of
"Adnene-Ben-Abdallah-1.cpp"

With g++
../blitz/array-impl.h: In instantiation of `blitz::Array<double, 1>':
Adnene-Ben-Abdallah-1.cpp:7: instantiated from here
../blitz/array-impl.h:2478: invalid use of undefined type `class
blitz::Array<double, 1>'
../blitz/array-impl.h:182: forward declaration of `class
blitz::Array<double, 1>'
make[1]: *** [Adnene-Ben-Abdallah-1.o] Error 1

A way to avoid this error message is to declare the frien function inside
the class definition of Array
friend void swap(Array<P_numtype,N_rank>&,Array<P_numtype,N_rank>&) {
.... }

Sincerely, Patrick

>
> Here is a patch I intend to commit tomorrow if no one opposes.
> It's main purpose is to remove some warning with unused arguments,
> to make the function swap work with Arrays.
>
> Three potentially controversial things are:
>
> + Removal of math.h if cmath is included, I do not see how it can
> hurt, but I'm only using one compiler ...
>
> + Protection of _bz_intel_kludge with a __INTEL_COMPILER.
> Actually I'm not even sure that this is necessary with modern INTEL
> compilers (the bug is for version 4.0), this is certainly not perfect
> but at least it improves things. Can someone with an intel compiler
> test this ?
>
> + I used typename directly instead of _bz_typename.
> Are there any modern compiler that does not accept the typename
> construct around ??? In my opinion, we should start to move towards
> using typename every where in template parameter definition.
> I notice that boost (that is tested againts several compilers) uses
> typename and class indifferently. Since (AFAIK), class is deprecated
> we should move towards typename.
>
> Thank's
>
> Theo.
>
>
> 2002-10-08 Theodore Papadopoulo <Theodore.Papadopoulo_at_[hidden]>
> * blitz/memblock.h: Add support for swapping memblocks.
> * blitz/array-impl.h: Overload the swap function to work with
> Array.
> * blitz/blitz.h: Do not include math.h if cmath is included.
> * blitz/array/eval.cc: Move or remove unused statements.
> * blitz/traversal.cc: Protect _bz_intel_kludge with
> #ifdef __INTEL_COMPILER.
>
> Index: blitz/array-impl.h
> ===================================================================
> RCS file: /cvsroot/blitz/blitz/blitz/array-impl.h,v
> retrieving revision 1.10
> diff -c -3 -p -r1.10 array-impl.h
> *** blitz/array-impl.h 30 Aug 2002 22:12:49 -0000 1.10
> --- blitz/array-impl.h 9 Oct 2002 09:58:42 -0000
> *************** class IndirectArray;
> *** 162,167 ****
> --- 162,169 ----
>
> struct _bz_endTag {};
>
> + template <typename P_numtype, int N_rank>
> + void swap(Array<P_numtype,N_rank>&,Array<P_numtype,N_rank>&);
>
>
> /*
> *************** protected:
> *** 2473,2478 ****
> --- 2475,2482 ----
>
> void doTranspose(int destRank, int sourceRank, T_array& array);
>
> + friend void swap<>(Array<P_numtype,N_rank>&,Array<P_numtype,N_rank>&);
> +
> protected:
> //////////////////////////////////////////////
> // Data members
> *************** ostream& operator<<(ostream&, const Arra
> *** 2552,2557 ****
> --- 2556,2571 ----
>
> template<class T_numtype, int N_rank>
> istream& operator>>(istream& is, Array<T_numtype,N_rank>& x);
> +
> + template <typename P_numtype, int N_rank>
> + void swap(Array<P_numtype,N_rank>& a,Array<P_numtype,N_rank>& b) {
> + MemoryBlockReference<P_numtype>::swap(a,b);
> + std::swap(a.storage_,b.storage_);
> + std::swap(a.length_,b.length_);
> + std::swap(a.stride_,b.stride_);
> + std::swap(a.zeroOffset_,b.zeroOffset_);
> + }
> +
>
> BZ_NAMESPACE_END
>
> Index: blitz/blitz.h
> ===================================================================
> RCS file: /cvsroot/blitz/blitz/blitz/blitz.h,v
> retrieving revision 1.9
> diff -c -3 -p -r1.9 blitz.h
> *** blitz/blitz.h 19 Jul 2002 20:40:32 -0000 1.9
> --- blitz/blitz.h 9 Oct 2002 09:58:42 -0000
> ***************
> *** 115,123 ****
>
> #ifdef BZ_MATH_FN_IN_NAMESPACE_STD
> #include <cmath>
> #endif
> -
> - #include <math.h>
>
> #ifdef BZ_HAVE_COMPLEX
> #include <complex>
> --- 115,123 ----
>
> #ifdef BZ_MATH_FN_IN_NAMESPACE_STD
> #include <cmath>
> + #else
> + #include <math.h>
> #endif
>
> #ifdef BZ_HAVE_COMPLEX
> #include <complex>
> Index: blitz/memblock.h
> ===================================================================
> RCS file: /cvsroot/blitz/blitz/blitz/memblock.h,v
> retrieving revision 1.9
> diff -c -3 -p -r1.9 memblock.h
> *** blitz/memblock.h 19 Jul 2002 20:42:53 -0000 1.9
> --- blitz/memblock.h 9 Oct 2002 09:58:42 -0000
> *************** public:
> *** 382,387 ****
> --- 382,392 ----
> return block_->references();
> }
>
> + static void swap(MemoryBlockReference<P_type>& a,MemoryBlockReference<P_type>& b) {
> + std::swap(a.data_,b.data_);
> + std::swap(a.block_,b.block_);
> + }
> +
> protected:
>
> void changeToNullBlock()
> Index: blitz/traversal.cc
> ===================================================================
> RCS file: /cvsroot/blitz/blitz/blitz/traversal.cc,v
> retrieving revision 1.3
> diff -c -3 -p -r1.3 traversal.cc
> *** blitz/traversal.cc 6 Mar 2002 17:18:11 -0000 1.3
> --- blitz/traversal.cc 9 Oct 2002 09:58:42 -0000
> ***************
> *** 48,56 ****
> --- 48,58 ----
>
> BZ_NAMESPACE(blitz)
>
> + #ifdef __INTEL_COMPILER
> // Next line is a workaround for Intel C++ V4.0 oddity, due
> // to Allan Stokes.
> static set<TraversalOrder<2> > *_bz_intel_kludge;
> + #endif
>
> //template<int N_dimensions>
> //_bz_typename TraversalOrderCollection<N_dimensions>::T_set
> Index: blitz/array/eval.cc
> ===================================================================
> RCS file: /cvsroot/blitz/blitz/blitz/array/eval.cc,v
> retrieving revision 1.6
> diff -c -3 -p -r1.6 eval.cc
> *** blitz/array/eval.cc 27 May 2002 19:48:57 -0000 1.6
> --- blitz/array/eval.cc 9 Oct 2002 09:58:42 -0000
> *************** Array<T_numtype, N_rank>::evaluateWithSt
> *** 444,450 ****
> */
>
> const int maxRank = ordering(0);
> - const int secondLastRank = ordering(1);
>
> // Create an iterator for the array receiving the result
> FastArrayIterator<T_numtype, N_rank> iter(*this);
> --- 444,449 ----
> *************** Array<T_numtype, N_rank>::evaluateWithSt
> *** 567,575 ****
>
> if ((useUnitStride) || (useCommonStride))
> {
> - T_numtype * _bz_restrict end = const_cast<T_numtype*>(iter.data())
> - + lastLength;
> -
> #ifdef BZ_USE_FAST_READ_ARRAY_EXPR
>
> /*
> --- 566,571 ----
> *************** Array<T_numtype, N_rank>::evaluateWithSt
> *** 618,623 ****
> --- 614,622 ----
> // This bit of code not really needed; should remove at some
> // point, along with the test for BZ_USE_FAST_READ_ARRAY_EXPR
>
> + T_numtype * _bz_restrict end = const_cast<T_numtype*>(iter.data())
> + + lastLength;
> +
> while (iter.data() != end)
> {
> T_update::update(*const_cast<T_numtype*>(iter.data()), *expr);
> *************** Array<T_numtype, N_rank>::evaluateWithIn
> *** 736,744 ****
> // index traversal for the source expression
>
> const int maxRank = ordering(0);
> - const int secondLastRank = ordering(1);
>
> #ifdef BZ_DEBUG_TRAVERSE
> cout << "Index traversal: N_rank = " << N_rank << endl;
> cout << "maxRank = " << maxRank << " secondLastRank = " << secondLastRank
> << endl;
> --- 735,743 ----
> // index traversal for the source expression
>
> const int maxRank = ordering(0);
>
> #ifdef BZ_DEBUG_TRAVERSE
> + const int secondLastRank = ordering(1);
> cout << "Index traversal: N_rank = " << N_rank << endl;
> cout << "maxRank = " << maxRank << " secondLastRank = " << secondLastRank
> << endl;
> *************** cout.flush();
> *** 757,764 ****
>
> for (int i=0; i < N_rank; ++i)
> last(i) = storage_.base(i) + length_(i);
> -
> - int lastLength = length(maxRank);
>
> while (true) {
>
> --- 756,761 ----
>
> --------------------------------------------------------------------
> Theodore Papadopoulo
> Email: Theodore.Papadopoulo_at_[hidden] Tel: (33) 04 92 38 76 01
> --------------------------------------------------------------------
>
>
>
> _______________________________________________
> Blitz-dev mailing list
> Blitz-dev_at_[hidden]
> http://www.oonumerics.org/mailman/listinfo.cgi/blitz-dev
>

======================================================================
                                  Patrick Guio
                    Institute of Physics, University of Oslo
                      P.O. box 1048, Blindern, N-0316 Oslo
               Tel : (+47) 22 84 40 60 - Fax : (+47) 22 85 56 71
                        E-mail : patrick.guio_at_[hidden]
                  URL : http://folk.uio.no/~patricg

_______________________________________________
Blitz-dev mailing list
Blitz-dev_at_[hidden]
http://www.oonumerics.org/mailman/listinfo.cgi/blitz-dev