コード例 #1
0
ファイル: main.cpp プロジェクト: dnawym/Concurrency
std::list<T> parallel_quick_sort(std::list<T> input)
{
	//std::cout << "parallel_quick_sort list size = " << input.size() << std::endl;
	thread_counter++;
    if(input.empty())
    {
        return input;
    }
    std::list<T> result;
    result.splice(result.begin(),input,input.begin());
    T const& pivot=*result.begin();
    auto divide_point=std::partition(input.begin(),input.end(),
        [&](T const& t){return t<pivot;});
    std::list<T> lower_part;
    lower_part.splice(lower_part.end(),input,input.begin(),
        divide_point);
    
    if (lower_part.size() <= 10000)
    {
    	auto new_lower(
        	sequential_quick_sort(std::move(lower_part)));
        	
        if (input.size() > 1)
        {
        	auto new_higher(
        	parallel_quick_sort(std::move(input)));
        	
        	result.splice(result.end(),new_higher);
		}
		else
		{
			result.splice(result.end(), input);
		}

        result.splice(result.begin(),new_lower);
	}
	else
	{
		std::future<std::list<T> > new_lower(
			std::async(&parallel_quick_sort<T>,std::move(lower_part)));
        if (input.size() > 1)
        {
        	auto new_higher(
        	parallel_quick_sort(std::move(input)));
        	
        	result.splice(result.end(),new_higher);
		}
		else
		{
			result.splice(result.end(), input);
		}
    	result.splice(result.begin(),new_lower.get());
	}
    
    return result;
}
コード例 #2
0
ファイル: qsort.cpp プロジェクト: condy0919/experimentations
std::list<T> parallel_quick_sort(std::list<T> input) {
    if (input.empty())
        return input;

    std::list<T> result;
    result.splice(result.begin(), input, input.begin());
    const T& pivot = *result.begin();

    auto pt = std::partition(input.begin(), input.end(),
                             [&](const T& x) { return x < pivot; });
    std::list<T> lower_part;
    lower_part.splice(lower_part.end(), input, input.begin(), pt);

    std::future<std::list<T>> new_lower(
        std::async(&parallel_quick_sort<T>, std::move(lower_part)));

    auto new_higher = parallel_quick_sort(std::move(input));
    result.splice(result.end(), new_higher);
    result.splice(result.begin(), new_lower.get());
    return result;
}
コード例 #3
0
std::list<T> parallel_quick_sort(std::list<T> input)
{
    if(input.empty())
    {
        return input;
    }
    std::list<T> result;
    result.splice(result.begin(),input,input.begin());
    T const& pivot=*result.begin();
    auto divide_point=std::partition(input.begin(),input.end(),
        [&](T const& t){return t<pivot;});
    std::list<T> lower_part;
    lower_part.splice(lower_part.end(),input,input.begin(),
        divide_point);
    std::future<std::list<T> > new_lower(
        std::async(&parallel_quick_sort<T>,std::move(lower_part)));
    auto new_higher(
        parallel_quick_sort(std::move(input)));
    result.splice(result.end(),new_higher);
    result.splice(result.begin(),new_lower.get());
    return result;
}