|
Boost Users : |
Subject: [Boost-users] uBlas and openMP?
From: mik (mirko.cambi_at_[hidden])
Date: 2010-01-20 06:07:51
Hi all,
I'm working on a project using uBlas. I'm using dense vector and dense
matrix, the dimensions of these structures are very big.
So, I was thinking about the opportunity to modify some algorithms of
uBlas using multi-thread programming.
I've tried to do this using openMP. Below, you find my first attempt.
This is a piece of the original code in vector_assign.hpp
// Explicitly indexing
template<template <class T1, class T2> class F, class V, class E>
// BOOST_UBLAS_INLINE This function seems to be big. So we do not let
the compiler inline it.
void indexing_vector_assign (V &v, const vector_expression<E> &e) {
typedef F<typename V::reference, typename E::value_type>
functor_type;
typedef typename V::size_type size_type;
size_type size (BOOST_UBLAS_SAME (v.size (), e ().size ()));
#ifndef BOOST_UBLAS_USE_DUFF_DEVICE
for (size_type i = 0; i < size; ++ i)
functor_type::apply (v (i), e () (i));
#else
size_type i (0);
DD (size, 2, r, (functor_type::apply (v (i), e () (i)), ++ i));
#endif
}
And I modified the inner for in this way:
int i;
#pragma omp parallel private(i) shared(v, e)
{
#pragma omp for
for (i = 0; i < size; ++ i)
functor_type::apply (v (i), e () (i));
}
I tried the code and it run.
Yes I know that it's better if I use the clause schedule in the pragma for,
but the real question is: do you think that this code is enough general? Can
I extend it with the operations?
Thank you in advance
Mirko
--- Ad maiora semper.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net