Skip to content

Commit 0991c48

Browse files
committed
Test with threads
1 parent fdda7d0 commit 0991c48

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

examples/Example_get_apr.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ Advanced (Direct) Settings:
3838
#include "ConfigAPR.h"
3939
#include "Example_get_apr.h"
4040

41-
int main(int argc, char **argv) {
42-
43-
//input parsing
44-
cmdLineOptions options;
41+
#include <future>
42+
#include <thread>
4543

46-
options = read_command_line_options(argc,argv);
4744

45+
int runAPR(cmdLineOptions options) {
4846
//the apr datastructure
4947
APR<uint16_t> apr;
5048

@@ -144,10 +142,34 @@ int main(int argc, char **argv) {
144142
std::cout << "Oops, something went wrong. APR not computed :(." << std::endl;
145143
}
146144
return 0;
145+
}
146+
147+
148+
int main(int argc, char **argv) {
149+
150+
//input parsing
151+
cmdLineOptions options;
147152

153+
options = read_command_line_options(argc, argv);
154+
std::vector<std::future<int>> fv;
155+
fv.emplace_back(std::async(std::launch::async, [=]{ return runAPR(options); }));
156+
fv.emplace_back(std::async(std::launch::async, [=]{ return runAPR(options); }));
157+
fv.emplace_back(std::async(std::launch::async, [=]{ return runAPR(options); }));
158+
int n = 3;
159+
std::cout << "Waintig..." <<std::endl;
160+
for (int i = 0; i < fv.size()*3; ++i) {
161+
fv[i % n].wait();
162+
fv[i % n] = std::async(std::launch::async, [=]{ return runAPR(options); });
163+
}
164+
165+
for (int i = 0; i < fv.size(); ++i) fv[i].wait();
166+
167+
std::cout << "DONE!" <<std::endl;
168+
return fv[0].get();
148169
}
149170

150171

172+
151173
bool command_option_exists(char **begin, char **end, const std::string &option)
152174
{
153175
return std::find(begin, end, option) != end;

src/algorithm/APRConverter.hpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,7 @@ inline bool APRConverter<ImageType>::get_apr_method(APR<ImageType> &aAPR, PixelD
235235
t.start_timer(" =========== ALL");
236236
{
237237
GpuProcessingTask<ImageType> gpt1(image_temp, local_scale_temp, par, bspline_offset, (*apr).level_max());
238-
GpuProcessingTask<ImageType> gpt2(image_temp, local_scale_temp, par, bspline_offset, (*apr).level_max());
239-
GpuProcessingTask<ImageType> gpt3(image_temp, local_scale_temp, par, bspline_offset, (*apr).level_max());
240-
GpuProcessingTask<ImageType> gpt4(image_temp, local_scale_temp, par, bspline_offset, (*apr).level_max());
241-
for (int i = 0; i < 2; ++i) {
242-
gpt1.doAll();
243-
gpt2.doAll();
244-
gpt3.doAll();
245-
gpt4.doAll();
246-
// gpt3.sendDataToGpu();
247-
// gpt3.processOnGpu();
248-
// gpt3.getDataFromGpu();
249-
}
238+
gpt1.doAll();
250239
}
251240
t.stop_timer();
252241
method_timer.stop_timer();

0 commit comments

Comments
 (0)