Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/stdpar/tsp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ ifeq ("$(wildcard $(HIPSTDPARPRIMPATH)/rocprim)","")
endif

CC = $(LLVM_INSTALL_DIR)/bin/clang++
opts=-I. -DNDEBUG -O3 --hipstdpar --hipstdpar-path=$(HIPSTDPARPATH) --hipstdpar-thrust-path=$(HIPSTDPARTHRUSTPATH) --hipstdpar-prim-path=$(HIPSTDPARPRIMPATH) --offload-arch=$(LLVM_GPU_ARCH) -std=c++17
#opts=-I. -DNDEBUG -O3 --hipstdpar --hipstdpar-path=$(HIPSTDPARPATH) --hipstdpar-thrust-path=$(HIPSTDPARTHRUSTPATH) --hipstdpar-prim-path=$(HIPSTDPARPRIMPATH) --offload-arch=$(LLVM_GPU_ARCH) -std=c++17
opts=-I. -g -O0 --hipstdpar --hipstdpar-path=$(HIPSTDPARPATH) --hipstdpar-thrust-path=$(HIPSTDPARTHRUSTPATH) --hipstdpar-prim-path=$(HIPSTDPARPRIMPATH) --offload-arch=$(LLVM_GPU_ARCH) -std=c++20

# Build both babelstream stdpar binaries
tsp:tsp.o
Expand Down
51 changes: 0 additions & 51 deletions examples/stdpar/tsp/SimpleTimer.h

This file was deleted.

82 changes: 0 additions & 82 deletions examples/stdpar/tsp/counting_iterator.h

This file was deleted.

38 changes: 16 additions & 22 deletions examples/stdpar/tsp/tsp.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "route_iterator.h"
#include "route_cost.h"
#include "tsp_utils.h"
#include "counting_iterator.h"
#include "SimpleTimer.h"

// #include <thrust/iterator/counting_iterator.h>
// #include <thrust/system/omp/execution_policy.h>
Expand All @@ -15,8 +13,13 @@
#include <iostream>

#include <algorithm>
#include <chrono>
#include <execution>
#include <numeric>
#include <ranges>

using namespace std;
using namespace std::chrono;

// ============================================
// ============================================
Expand Down Expand Up @@ -79,23 +82,20 @@ void test_city_distance()

} // test_city_distance

// ============================================
// ============================================

template<int N>
route_cost find_best_route(int const* distances)
{

int X = factorial(N);
return
std::transform_reduce(std::execution::par_unseq,
counting_iterator(0),
counting_iterator(factorial(N)),
std::views::iota(0, X).begin(),
std::views::iota(0, X).end(),
route_cost(),
//route_cost::minf,
[](route_cost x, route_cost y) { return x.cost < y.cost ? x : y; },
[=](int64_t i)
{
int cost = 0;

route_iterator<N> it(i);

// first city visited
Expand All @@ -106,40 +106,34 @@ route_cost find_best_route(int const* distances)
while (!it.done())
{
int to = it.next();
cost += distances[to + N*from];
cost += distances[to + N * from];
from = to;
}

// debug
// printf("route #%d cost=%d\n",i,cost);

// update best_route -> reduction
return route_cost(i, cost);
});

} // find_best_route
}

// ============================================================
// ============================================================
//! \param[in] nbRepeat number of repeat (for accurate time measurement)

template <int N>
void solve_traveling_salesman(int nbRepeat = 1)
{
// find best route
auto distances_small = init_distance_matrix_small(N);

route_cost best_route;

SimpleTimer timer;
timer.start();
auto start = high_resolution_clock::now();
for (int i = 0; i<nbRepeat; ++i)
best_route = find_best_route<N>(distances_small.data());
timer.stop();

double time = timer.elapsedSeconds()/nbRepeat;
auto end = high_resolution_clock::now();

duration<double, milli> elapsed = (end - start) / nbRepeat;
// print best route
printf("Trav Salesman Prob N=%d, best route cost is: %d, average time is %f seconds\n",N, best_route.cost, time);
printf("Trav Salesman Prob N=%d, best route cost is: %d, average time is %f seconds\n",N, best_route.cost, elapsed.count());

printf("Solution route is ");
route_iterator<N> rit(best_route.route);
Expand Down