mirror of
https://gitlab.com/Trygve/contour-creator.git
synced 2024-11-22 07:10:18 +00:00
Attempted parallelization of casemaps
This commit is contained in:
parent
40d41fc065
commit
cf72fbfefa
24
src/main.cpp
24
src/main.cpp
@ -9,6 +9,7 @@
|
|||||||
#include <gdal/gdal.h>
|
#include <gdal/gdal.h>
|
||||||
#include "gdal/gdal_priv.h"
|
#include "gdal/gdal_priv.h"
|
||||||
#include <gdal/gdal_frmts.h>
|
#include <gdal/gdal_frmts.h>
|
||||||
|
#include <omp.h>
|
||||||
|
|
||||||
CaseMap produce_casemap(HeightMap* heightmap, float z)
|
CaseMap produce_casemap(HeightMap* heightmap, float z)
|
||||||
{
|
{
|
||||||
@ -29,6 +30,28 @@ CaseMap produce_casemap(HeightMap* heightmap, float z)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<CaseMap> vector_casemap(HeightMap* heightmap, int interval)
|
||||||
|
{
|
||||||
|
int num_contours = (heightmap->max - heightmap->min)/interval;
|
||||||
|
std::vector<CaseMap> vector_contours;
|
||||||
|
omp_set_num_threads(8);
|
||||||
|
|
||||||
|
#pragma omp parallel
|
||||||
|
{
|
||||||
|
std::vector<CaseMap> vec_private;
|
||||||
|
#pragma omp for
|
||||||
|
for (int i = 1; i <= num_contours; i++)
|
||||||
|
{
|
||||||
|
vec_private.push_back(produce_casemap(heightmap, heightmap->min + interval*i));
|
||||||
|
std::cout << "Execute thread " << omp_get_num_threads << " ";
|
||||||
|
}
|
||||||
|
#pragma omp critical
|
||||||
|
vector_contours.insert(vector_contours.end(), vec_private.begin(), vec_private.end());
|
||||||
|
|
||||||
|
}
|
||||||
|
return vector_contours;
|
||||||
|
}
|
||||||
|
|
||||||
void write_output_file(CaseMap* casemap, const char *filepath)
|
void write_output_file(CaseMap* casemap, const char *filepath)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -143,4 +166,5 @@ int main(int argc, const char* argv[])
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
write_output_file(&casemap, "out.shp");
|
write_output_file(&casemap, "out.shp");
|
||||||
|
vector_casemap(&map, 1);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user