Commit 96dc8327 authored by Jens Korinth's avatar Jens Korinth

Update rot13 kernel

parent b89ccf99
......@@ -6,5 +6,5 @@ link_directories("$ENV{TAPASCO_HOME}/arch/axi4mm/lib/${CMAKE_SYSTEM_PROCESSOR}"
add_executable(rot13 rot13.cpp)
add_executable(tapasco-rot13 tapasco_rot13.cpp)
target_link_libraries(tapasco-rot13 platform tapasco atomic)
target_link_libraries(tapasco-rot13 platform tapasco atomic pthread)
set_target_properties(rot13 tapasco-rot13 PROPERTIES COMPILE_FLAGS "-Wall -std=c++11 -g")
......@@ -30,7 +30,7 @@ using namespace std;
static constexpr size_t MAX_LEN = 4096;
static inline char testrot13(const char c)
static inline char char_rot13(const char c)
{
if (c < 'A' || c > 'Z') return c;
return c >= 'N' ? c - 13 : c + 13;
......@@ -42,7 +42,7 @@ void rot13(uint32_t const len, char const text_in[MAX_LEN],
char buf_in[MAX_LEN], buf_out[MAX_LEN];
memcpy(buf_in, text_in, len);
for (size_t i = 0; i < len; ++i)
buf_out[i] = testrot13(buf_in[i]);
buf_out[i] = char_rot13(buf_in[i]);
memcpy(text_out, buf_out, len);
}
......
......@@ -59,14 +59,14 @@ static char *read_file(char const *fn, size_t& file_sz)
int main(int argc, char *argv[])
{
size_t sz;
assert(argc > 1); // need filename
Tapasco tapasco; // init TPC
char *filedata = read_file(argv[1], sz); // read data
assert(argc > 1); // need filename
Tapasco tapasco; // init Tapasco
char *filedata = read_file(argv[1], sz); // read data
atomic<long> nr_jobs { static_cast<long>
(sz / MAX_LEN + (sz % MAX_LEN ? 1 : 0)) }; // number of jobs
size_t const nr_threads = tapasco.func_instance_count(13);// number PEs
vector<future<void> > fs; // futures
char *text_out = new char[sz]; // out buffer
(sz / MAX_LEN + (sz % MAX_LEN ? 1 : 0)) }; // number of jobs
size_t const nr_threads = tapasco.func_instance_count(13); // number PEs
vector<future<void> > fs; // futures
char *text_out = new char[sz]; // out buffer
for (size_t i = 0; i < nr_threads; ++i) {
fs.push_back(async(launch::async, [&]() {
......@@ -93,7 +93,6 @@ int main(int argc, char *argv[])
for (auto& f : fs)
f.get(); // wait for threads to finish
cout << text_out << endl;
delete[] text_out;
delete[] filedata;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment