libstdc++ parallel mode fill

Kay-Michael Wuerzner wuerzner@gmail.com
Wed Oct 8 10:11:00 GMT 2008


Hello,

I recently started using the paralleled version of gcc's libstdc++. I
have a question concerning the fill algorithm.

The threshold variable __gnu_parallel::_Settings::fill_minimal_n
suggests that their is a parallel version of the fill algorithm. Now,
the resize(size_t  n, const T& val = T ()) function of std::vector
seems to use std::fill (via some internal functions) to fill the new
elements of the vector. Although, the resize size function is not
executed in parallel (while sorting elements is) in the following test
program.

#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>

int main (  )
{
        std::vector<int> v;
	v.resize ( 500000000 );
	
	srand ( time(NULL) );
	unsigned int i;
	std::cerr << "Filling..." << std::endl;
	#pragma omp parallel for
	for ( i = 0; i < v.size (); ++i )
	{
		v[i] = rand () % 10 + 1;
	}
	std::cerr << "...done." << std::endl;

	std::cerr << "Sorting..." << std::endl;
	sort ( v.begin (), v.end () );
	std::cerr << "...done." << std::endl;

        return 0;
}

Is this an intended behavior? If yes, why? If not, can I somehow force
the usage of parallel fill?

Thanks in advance.
Best regards,
Kay



More information about the Gcc-help mailing list