16#include "tbci/basics.h"
17#include "tbci/vector_sig.h"
18#include "tbci/tbci_traits.h"
21#if !defined(NO_GD) && !defined(AUTO_DECL)
22# include "tbci/bvector_gd.h"
27#ifndef TBCI_DISABLE_EXCEPT
35 :
NumErr(
"Error in Vector library") {}
45# pragma interface "bvector.h"
48template <
typename T>
class TMatrix;
49template <
typename T>
class Matrix;
52template <
typename T>
class TVector;
54template <
typename T>
class Vector;
81#ifdef HAVE_BCXX_INHER_BREAKS_FRIEND_BUG
88 explicit BVector (
const unsigned long = 0);
89 BVector (
const T&,
const unsigned long);
126 typename tbci_traits<T>::const_refval_type
131 typename tbci_traits<T>::const_refval_type
136 T&
set(
const T& val,
unsigned long idx)
137 {
return this->
set(idx) = val; }
141 typename tbci_traits<T>::const_refval_type
195 static const char*
vec_info() {
return "BVector"; }
197#ifndef HAVE_PROMOTION_BUG
198# ifndef HAVE_GCC295_TMPLFRNDCLS_BUG
215 for (
unsigned long i = 0;
i <
dim;
i++)
vec[
i] = bv(
i);
220#ifdef HAVE_BCXX_INHER_BREAKS_FRIEND_BUG
223 TVector<T> *
res,
const Matrix<T> * mat,
const Vector<T> *
vec);
225 TVector<T> *
res,
const Matrix<T> * mat,
const Vector<T> *
vec);
256#if !defined(__clang__) || !defined(CPLX)
257 for (
unsigned long i=0;
i <
dim; ++
i)
258 vec[
i] = va_arg (vl,
T);
260 throw VecErr(
"vararg not supported for cplx in clang");
261#warning no vararg support with cplx numbers and clang
286 vec = NEW (T, v.dim);
289 TBCICOPY(vec, v.vec, T, dim);
318# define LAPACK_INLINE
354 return this->
fill (value);
400 if (
vec[j] <
vec[j-1] ) {
461inline typename tbci_traits<T>::const_refval_type
512 for (
unsigned long i=0;
i<
dim;
i++)
523 for (
unsigned long i=0;
i<
dim;
i++)
534 for (
unsigned long i = 0;
i < v.
dim;
i++)
535 os << v.
vec[
i] <<
"\n";
537 for (
unsigned long i = 0;
i < v.
dim;
i++)
538 os << v.
vec[
i] <<
" ";
547 STD__ cerr <<
"BVector (" << __FILE__ <<
":" << __LINE__
548 <<
") Input on pointers not possible!" <<
STD__ endl;
568 for (
unsigned long i = 1;
i < v.
dim;
i++) {
570 if (s !=
',') in.putback(s);
605{
return (b1.
concat (b2)); }
618#if defined(SMP) && !defined(SMP_VECSLICE)
619# define SMP_VECSLICE 262144
621#if defined(SMP) && defined(__i386__) && !defined(SMP_VECSCALAR)
622# define NOSMP_VECSCALAR
623# define NOSMP_VECFABS
626# define SMP_VECSLICE2 (SMP_VECSLICE/sizeof(T))
630#if defined(SMP) && !defined(NO_SMP_VECVEC)
642int _par_comp (
const unsigned long sz,
const T* v1,
const T* v2))
644 volatile long res = 0;
651 do_vv_comp<T> (sz, v1, v2,
res);
654 const unsigned first = slice_offset(1, n_thr, sz, v1);
655 unsigned long st, en = first;
657 for (
unsigned t = 0; t < n_thr-1; ++t) {
658 st = en; en = slice_offset(t+2, n_thr, sz, v1);
660 v1+st, v2+st, (
void*)0);
663 do_vv_comp<T> (first, v1, v2,
res);
666 for (
unsigned t = 0; t < n_thr-1; ++t) {
684void _par_copy (
const unsigned long sz,
T* v1,
const T* v2))
692 _tbci_copy<T> (sz, v1, v2);
695 const unsigned first = slice_offset(1, n_thr, sz, v1);
696 unsigned long st, en = first;
698 for (
unsigned t = 0; t < n_thr-1; ++t) {
699 st = en; en = slice_offset(t+2, n_thr, sz, v1);
701 v1+st, v2+st, (
void*)0);
704 _tbci_copy (first, v1, v2);
707 for (
unsigned t = 0; t < n_thr-1; ++t)
716 _tbci_fill<T> (tc->
t_size,
722void _par_fill (
const unsigned long sz,
T* v1,
typename tbci_traits<T>::loop_const_refval_type val))
730 _tbci_fill<T> (sz, v1, val);
733 const unsigned first = slice_offset(1, n_thr, sz, v1);
734 unsigned long st, en = first;
736 for (
unsigned t = 0; t < n_thr-1; ++t) {
737 st = en; en = slice_offset(t+2, n_thr, sz, v1);
739 v1+st, &val, (
void*)0);
742 _tbci_fill<T> (first, v1, val);
745 for (
unsigned t = 0; t < n_thr-1; ++t)
754 _tbci_fill_fn<T> (tc->
t_size,
756 *(vec_fill_fn<T>*)(tc->
t_par[1]),
762void _par_fill_fn (
const unsigned long sz,
T* v1, vec_fill_fn<T> fn,
void *par))
770 _tbci_fill_fn<T> (sz, v1, fn, par);
773 const unsigned first = slice_offset(1, n_thr, sz, v1);
774 unsigned long st, en = first;
776 for (
unsigned t = 0; t < n_thr-1; ++t) {
777 st = en; en = slice_offset(t+2, n_thr, sz, v1);
779 v1+st, (
void*)&fn, par, (
void*)0);
782 _tbci_fill_fn<T> (first, v1, fn, par);
785 for (
unsigned t = 0; t < n_thr-1; ++t)
792int _par_comp (
const unsigned long sz,
const T* v1,
const T* v2)
795 do_vv_comp<T> (sz, v1, v2,
res);
800void _par_copy(
const unsigned long sz,
T* v1,
const T* v2)
802 _tbci_copy<T> (sz, v1, v2);
806void _par_fill (
const unsigned long sz,
T* v1,
typename tbci_traits<T>::loop_const_refval_type val)
808 _tbci_fill<T> (sz, v1, val);
812void _par_fill_fn (
const unsigned long sz,
T* v1, vec_fill_fn<T> fn,
void *par)
814 _tbci_fill_fn<T> (sz, v1, fn, par);
819#if defined(SMP) && defined(HAVE_LIBNUMA)
826 const unsigned long sz = bv.
size();
835 (
unsigned long)v1, (
unsigned long)(v1+sz));
838 const unsigned first = slice_offset(1, n_thr, sz, v1);
839 unsigned long st, en = first;
841 unsigned long res = 0;
842 for (
unsigned t = 0; t < n_thr-1; ++t) {
843 st = en; en = slice_offset(t+2, n_thr, sz, v1);
846 v1+st, v1+en, (
void*)0);
850 (
unsigned long)v1, (
unsigned long)(v1+first));
853 for (
unsigned t = 0; t < n_thr-1; ++t) {
long int Vector< T > & index
#define BCHK(cond, exc, txt, ind, rtval)
#define LIKELY(expr)
branch prediction note that we sometimes on purpose mark the unlikely possibility likely and vice ver...
#define TBCICOMP(n, o, t, s)
#define TBCICLEAR(n, t, s)
#define EXPCHK(cond, exc, txt, ind, rtval)
#define PREFETCH_R(addr, loc)
In case gcc does not yet support __builtin_prefetch(), we have handcoded assembly with gcc for a few ...
#define PREFETCH_W(addr, loc)
#define TBCIFILL(n, v, t, s)
#define TBCICOPY(n, o, t, s)
int numa_optimize(const BVector< T > &bv, bool fault_in)
void job_vv_comp(struct thr_ctrl *tc)
void job_vec_fill(struct thr_ctrl *tc)
STD__ ostream & operator<<(STD__ ostream &os, const BVector< T > &v)
BVector< T > concat(const BVector< T > &b1, const BVector< T > &b2)
void job_vv_copy(struct thr_ctrl *tc)
void job_vec_fill_fn(struct thr_ctrl *tc)
STD__ istream & operator>>(STD__ istream &in, BVector< T > &v)
provides basic Vector functionality but arithmetic operators (+=, - , *, /...).
bool operator>(const BVector< T > &bv) const
T *const & vecptr() const
const_iterator begin() const
unsigned long size() const HOT
bool operator>=(const BVector< T > &bv) const
T *const & get_fortran_vector() const
BVector< T > & setsize(const unsigned long size)
bool operator!=(const BVector< T > &bv) const
BVector< T > & operator=(const T &a)
static const char * vec_info()
bool contains(const T &, unsigned long *=0) const
BVector< T > & fill(const T &) HOT
friend NOINST BVector< T > &FRIEND_TBCI2__ bvfillm FGD(BVector< T > &, const Matrix< T > &m)
T * iterator
STL-like iterator support.
BVector< T > & bubble_sort()
BVector< T > & resize(const BVector< T > &)
Actually it's a resize and copy (some people would expect the assignment op to do this).
BVector< T > & remove(const unsigned long)
BVector(const BVector< U > &bv)
BVector< T > & setptr(T *pointer)
bool operator==(const BVector< T > &) const HOT
KG, 2001-06-29: Strange: If we don't inline this, we seems to get better performance in our solver be...
T aligned_value_type TALIGN(MIN_ALIGN2)
BVector< T > & cheapdownsize(const unsigned long)
bool operator<(const BVector< T > &bv) const
const_iterator end() const
const T & getcref(const unsigned long idx) const
BVector< T > & swap(BVector< T > &v)
tbci_traits< T >::const_refval_type get(const unsigned long idx) const HOT
T & operator[](const unsigned long i)
T & operator()(const unsigned long) HOT
BVector< T > concat(const BVector< T > &) const
BVector< T > & push_back(const T &value)
performs poorly
bool operator<=(const BVector< T > &bv) const
T & set(const unsigned long idx) HOT
T & set(const T &val, unsigned long idx)
BVector< T > & alias(const BVector< T > &bv)
BVector< T > & append(const T &)
performs poorly
void set_fortran_vector(T *pointer)
BVector< T > & copy(const BVector< T > &bv)
copy does a resize, if necessary
Temporary Base Class (non referable!) (acc.
Temporary Base Class Idiom: Class TVector is used for temporary variables.
VecErr(const char *t, const long i=0)
#define TBCIDELETE(t, v, sz)
#define REALLOC(v, os, t, s)
void do_mat_vec_mult(const unsigned start, const unsigned end, TVector< T > *res, const Matrix< T > *mat, const Vector< T > *vec)
void do_mat_vec_transmult(const unsigned start, const unsigned end, TVector< T > *res, const Matrix< T > *mat, const Vector< T > *vec)
BVector< T > & bvfillm(BVector< T > &bv, const Matrix< T > &m)
const unsigned TMatrix< T > const Matrix< T > * a
const unsigned TMatrix< T > * res
int _par_comp(const unsigned long sz, const T *v1, const T *v2)
void _par_fill(const unsigned long, T *const, typename tbci_traits< T >::loop_const_refval_type)
void _par_copy(const unsigned long sz, T *v1, const T *v2)
void thread_start_off(const int thr_no, thr_job_t job, const unsigned long off, const unsigned long sz,...)
void thread_wait(const int thr_no, struct job_output *out)
void thread_start(const int thr_no, thr_job_t job, const unsigned long sz,...)
struct thr_struct * threads
void(* thr_job_t)(struct thr_ctrl *)
Before the double inclusion guard on purpose!