Note: The default ITS GitLab runner is a shared resource and is subject to slowdowns during heavy usage.
You can run your own GitLab runner that is dedicated just to your group if you need to avoid processing delays.

Commit 33f74e34 authored by Guangting Yu's avatar Guangting Yu
Browse files

first MPI run success (with identical tasks)

parent 415fb811
#include <iostream>
#include <algorithm>
#include <numeric>
#include <atomic>
#include <limits>
......@@ -56,6 +56,11 @@ class EulerSum{
for(auto& n:tasks) n.join();
unique_lock<mutex> lck(m);
cv.wait(lck, [this]{return counter==tasks.size();});
if(result.size()>1){
std::sort(result.begin(), result.end(),
[](const vector<size_t>& a, const vector<size_t>& b){return a.front() < b.front();});
if(search_min) result.resize(1);
}
}
void thread_child(size_t sum){
......@@ -110,7 +115,7 @@ class EulerSum{
}
}else{
for(v[idx]=(idx==0 ? 1: v[idx-1]);
accumulate(v.begin(), v.begin()+idx+1, 0)<=
static_cast<size_t>(accumulate(v.begin(), v.begin()+idx+1, 0))<=
sum-(idx+2==v.size() ? v[idx] : v.size()-idx);
v[idx]++){
generate_simplex(v, sum, idx+1);
......@@ -121,10 +126,8 @@ class EulerSum{
public:
EulerSum(size_t l, size_t p, size_t r):
length(l), power(p), range(std::max(r,l)) {
if(power>10){
std::cerr << "warning: unstable\n";
}
search_min = true;
// not tested for p>10
}
// stop after finding minimum
......@@ -134,30 +137,8 @@ public:
}
// called by MPI node
void run(size_t width){
vector<vector<size_t>>& run(size_t width){
thread_parent(range+width);
for(auto&v : result){
printf("%lu^%lu\t=\t", v[0], power);
printf("%lu^%lu", v[1], power);
for(auto it=v.begin()+2; it!=v.end();it++){
printf("\t+\t%lu^%lu", *it, power);
}
printf("\n");
}
return result;
}
};
int main(int argc, char* argv[]){
if(argc!=4){
std::cerr << "input:\tlength\tpower\trange\n";
return EXIT_FAILURE;
}
EulerSum instance(
static_cast<size_t>(atoi(argv[1])),
static_cast<size_t>(atoi(argv[2])),
static_cast<size_t>(atoi(argv[3]))
);
instance.configure(true);
instance.run(1024);
return EXIT_SUCCESS;
}
compiler = g++
standard = -std=c++17
source = main.cc
std = -std=c++17
libs = -lm -lgmp -pthread
flag = -Wall -Wextra -Wpedantic
exce = main
debug:
$(compiler) $(source) -g $(standard) $(libs) -o $(exce)
release: $(exce)
$(compiler) $(source) -O3 $(standard) $(libs) -o $(exce)
EulerSum: EulerSum.cc
g++ $< -g -c $(flag) $(std) $(libs) -o $@.o
mpi_call: mpi_caller.cc EulerSum.o
mpicxx $^ $(std) $(libs) $(flag) -o $(exce)
clean:
rm $(exce)
rm $(exce) *.o
#include "EulerSum.cc"
#include <iostream>
#include <mpi.h>
void print_soln(std::vector<vector<size_t>>& soln, size_t p){
for(auto&v : soln){
printf("%lu^%lu\t=\t", v[0], p);
printf("%lu^%lu", v[1], p);
for(auto it=v.begin()+2; it!=v.end();it++){
printf("\t+\t%lu^%lu", *it, p);
}
printf("\n");
}
}
int main(int argc, char* argv[]){
if(argc!=4){
std::cerr << "input:\tlength\tpower\trange\n";
return EXIT_FAILURE;
}
size_t s[3]={0,0,0};
for(int i=1; i<argc; ++i){
s[i-1]=static_cast<size_t>(atoi(argv[i]));
}
EulerSum instance(s[0],s[1],s[2]);
instance.configure(false);
print_soln(instance.run(16), s[1]);
return EXIT_SUCCESS;
}
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