HyperspaceExplorer 0.7.1
Multithreading.h
00001 /*
00002     Hyperspace Explorer - visualizing higher-dimensional geometry
00003     Copyright (C) 2012  Lene Preuss <lene.preuss@gmail.com>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License along
00016     with this program; if not, write to the Free Software Foundation, Inc.,
00017     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018 
00019 */
00020 
00021 #ifndef PARTITIONEDMULTITHREADEDMAP_H
00022 #define PARTITIONEDMULTITHREADEDMAP_H
00023 
00024 #include "MultithreadingPrivate.h"
00025 
00026 #include <QtConcurrentMap>
00027 
00029 
00038 namespace Multithreading {
00039 
00040     template <class RandomAccessContainer, typename Function> 
00041     RandomAccessContainer mapped(const RandomAccessContainer &container, Function function) {
00042         return QtConcurrent::blockingMapped<RandomAccessContainer>(container, function);
00043     }
00044     
00047 
00065     template <class RandomAccessContainer, typename Function> 
00066     void partitionedMap(
00067         const RandomAccessContainer &container, RandomAccessContainer &output, Function function, 
00068         unsigned tasks_per_processor = 1
00069     ) {
00070         auto tasks = Private::Kernel<RandomAccessContainer, Function>::generateKernels(container, output, function, tasks_per_processor);
00071 
00072         Private::Kernel<RandomAccessContainer, Function>::startTasks(tasks);
00073         
00074         Private::Kernel<RandomAccessContainer, Function>::waitForTasks(tasks);
00075     }
00076 
00079 
00096     template <class RandomAccessContainer, typename Function> 
00097     void partitionedMap(
00098         RandomAccessContainer &container, Function function, unsigned tasks_per_processor = 1
00099     ) {
00100         partitionedMap(container, container, function, tasks_per_processor);
00101     }
00102 
00105 
00123     template <class RandomAccessContainer, typename Function> 
00124     RandomAccessContainer partitionedMapped(
00125         const RandomAccessContainer &container, Function function, unsigned tasks_per_processor = 1
00126     ) {
00127         RandomAccessContainer output(container.size());
00128         
00129         partitionedMap(container, output, function, tasks_per_processor);
00130 
00131         return output;
00132     }
00133     
00134 }
00135 
00136 #endif  /* PARTITIONEDMULTITHREADEDMAP_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends

Generated on Mon Apr 9 2012 20:25:16 for HyperspaceExplorer 0.7.1 by doxygen 1.7.4  -  Hosted bySourceForge.net Logo