Skip to content

Commit

Permalink
Finalize OpenMP
Browse files Browse the repository at this point in the history
  • Loading branch information
APN-Pucky committed Mar 23, 2019
1 parent a8b86fa commit 418d8c7
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 129 deletions.
Binary file modified SimpleTUOptimizeStarter-x86.exe
Binary file not shown.
10 changes: 8 additions & 2 deletions SimpleTUOptimizeStarter.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ IniRead, IniEndgame, %IniFileName%, %IniSection%, Endgame, 1
IniRead, IniFund, %IniFileName%, %IniSection%, Fund, 0
IniRead, Inix86, %IniFileName%, %IniSection%, x86, 0
IniRead, Inidebug, %IniFileName%, %IniSection%, debug, 0
IniRead, Iniopenmp, %IniFileName%, %IniSection%, openmp, 0
IniRead, Initime, %IniFileName%, %IniSection%, time, 0

Menu, MyMenu, Add, ownedcards.txt, MenuOwnedcards
Menu, MyMenu, Add, customdecks.txt, MenuCustomdecks
Expand Down Expand Up @@ -117,8 +119,10 @@ Gui, Add, Checkbox, vCommander Checked%IniCommander%, Commander lock
Gui, Add, Edit, vSimOptions r1 xs w600, %IniSimOptions%
Gui, Add, Button, default r2 w100 x100 y+15 section, Simulate
Gui, Add, Checkbox, vx86 Checked%Inix86%, x86 (32-bit)
Gui, Add, Checkbox, vopenmp Checked%IniOpenMP%, openmp
Gui, Add, Button, r2 w100 ys xs+200, Exit
Gui, Add, Checkbox, vdebug Checked%IniDebug%, debug
Gui, Add, Checkbox, vtime Checked%IniTime%, time
Gui, Show,, Simple TUO Starter %VersionOfStarter% (version of %VersionOfTUO%)
return

Expand All @@ -137,7 +141,7 @@ GuiControl, , Edit3, %EnemiesDeck% ; this will put the content of the variable i
GuiControl, , Edit11, %SimOptions% ; this will put the content of the variable in the editbox (edit11 is taken by the winspy)
Gui, Submit, NoHide ; save the changes and not hide the windows)

selTUO := (x86 ? (debug ? "tuo-x86-debug" : "tuo-x86") : (debug ? "tuo-debug" : "tuo"))
selTUO := "tuo" . (x86 ? "-x86" : "") . (openmp ? "-openmp" : "") . (debug ? "-debug" : (time ? "-time" : "")) . ".exe"
selMode := (Mode == 1 ? "pvp" : Mode == 2 ? "pvp-defense" : Mode == 3 ? "gw" : Mode == 4 ? "gw-defense" :Mode == 5 ? "brawl" : Mode == 6 ? "brawl-defense" : Mode == 7 ? "raid" : Mode == 8 ? "campaign" : "surge")
selOrder := (Order == 1 ? "random" : Order == 2 ? "ordered" : "flexible")
selOperation := (Operation == 1 ? "climb" : Operation == 2 ? "sim" : Operation == 3 ? "reorder": Operation == 4 ? "climbex" : Operation == 5 ? "anneal" : Operation==6 ? "debug sim" : Operation==7 ?"climb_forts" : "genetic")
Expand Down Expand Up @@ -171,7 +175,7 @@ return

MenuHelp:
Gui, Submit
selTUO := (x86 ? (debug ? "tuo-x86-debug" : "tuo-x86") : (debug ? "tuo-debug" : "tuo"))
selTUO := "tuo" . (x86 ? "-x86" : "") . (openmp ? "-openmp" : "") . (debug ? "-debug" : (time ? "-time" : "")) . ".exe"
Run, cmd.exe /c title TUOptimizeOutput && echo %selTUO% && %selTUO% & pause
Gui, Show
return
Expand Down Expand Up @@ -326,6 +330,8 @@ IniWrite, %Endgame%, %IniFileName%, %IniSection%, Endgame
IniWrite, %Fund%, %IniFileName%, %IniSection%, Fund
IniWrite, %x86%, %IniFileName%, %IniSection%, x86
IniWrite, %debug%, %IniFileName%, %IniSection%, debug
IniWrite, %openmp%, %IniFileName%, %IniSection%, openmp
IniWrite, %time%, %IniFileName%, %IniSection%, time

while true
{
Expand Down
Binary file modified SimpleTUOptimizeStarter.exe
Binary file not shown.
6 changes: 3 additions & 3 deletions build/windows/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MXE_DIR=/usr/lib/mxe


declare -a a_openmp=("" "-openmp" )
declare -a a_debug=("" "-debug" )
declare -a a_debug=("" "-debug" "-time")
declare -a a_bit=("" "-x86" )

for omp in "${a_openmp[@]}"
Expand All @@ -31,8 +31,8 @@ if [ "$bit" = "-x86" ]; then
MXE_TARGET=i686-w64-mingw32.static
fi

#No windows timer on debug
if [ "$dbg" = "-debug" ]; then
#No windows timer on default
if [ "$dbg" = "" ]; then
DFLAGS="${DFLAGS} -DDEBUG:STRING=\"-DNTIMER\""
fi
#activate openmp
Expand Down
Binary file removed tuo-eval
Binary file not shown.
Binary file removed tuo-eval-red
Binary file not shown.
Binary file removed tuo-less
Binary file not shown.
Binary file removed tuo-omp-cmp
Binary file not shown.
Binary file removed tuo-omp-no2-evaluate
Binary file not shown.
Binary file removed tuo-org
Binary file not shown.
125 changes: 1 addition & 124 deletions tyrant_optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,130 +1139,7 @@ class Process
for(unsigned i =0; i < c_num_threads;++i)
omp_destroy_lock(&locks[i]);
}


void openmp_evaluate(EvaluatedResults & evaluated_results) {
std::vector<std::vector<Results<uint64_t>>> all_results(thread_num_iterations);
std::vector<Results<uint64_t>> save_results(evaluated_results.first);
std::vector<Results<uint64_t>> result(evaluated_results.first);
std::vector<Results<uint64_t>> results(evaluated_results.first);
#pragma omp declare reduction \
(VecPlus:std::vector<Results<uint64_t>>: omp_out=merge(omp_out,omp_in))
#pragma omp parallel default(none) shared(thread_num_iterations,results,all_results,\
optimization_mode,confidence_level,max_possible_score,thread_best_results, min_increment_of_score)
{
SimulationData* sim = threads_data.at(omp_get_thread_num());
sim->set_decks(this->your_decks, this->enemy_decks);
#pragma omp for schedule(runtime)
for(unsigned i =0; i < thread_num_iterations;++i) {
all_results[i] = sim->evaluate(); //calculate single sim
}
//sum results
#pragma omp for reduction(VecPlus:results) schedule(runtime)
for(unsigned k=0; k < thread_num_iterations;++k)
{
if(all_results[k].size() >0)
{
if(results.size()==0)
results = all_results[k];
else
results =merge(results,all_results[k]); //calculate single sim
}
}
}

for( unsigned i =0; i< results.size();++i)
evaluated_results.first[i] =results[i]; //+?
evaluated_results.second+=thread_num_iterations;
}

void openmp_compare(EvaluatedResults & evaluated_results) {
std::vector<std::vector<Results<uint64_t>>> all_results(thread_num_iterations);
bool compare_stop{false};
bool skip[thread_num_iterations] = {false};
std::vector<Results<uint64_t>> results(evaluated_results.first);
unsigned count{0};
#pragma omp parallel default(none) shared(skip,count,results,compare_stop,thread_num_iterations,all_results,\
optimization_mode,confidence_level,max_possible_score,thread_best_results, min_increment_of_score)
{
SimulationData* sim = threads_data.at(omp_get_thread_num());
sim->set_decks(this->your_decks, this->enemy_decks);
#pragma omp for schedule(runtime)
for(unsigned i =0; i < thread_num_iterations;++i) {
if(!compare_stop)
{
//calculate single sim
all_results[i]= sim->evaluate();

//#pragma omp master
if(omp_get_thread_num()==0)
{
for(unsigned k =0; k<thread_num_iterations;++k)
{
if(!skip[k] && all_results[k].size() >0)
{
count++;
if(results.size()==0)
results = all_results[k];
else
results =merge(results,all_results[k]); //calculate single sim
skip[k]= true;
}
}
unsigned score_accum = 0;
// Multiple defense decks case: scaling by factors and approximation of a "discrete" number of events.
unsigned trials;
auto prob = 1-confidence_level;
long double max_possible ;
long double successes;


long double score_accum_d = 0.0;
for (unsigned j = 0; j < results.size(); ++j)
{
score_accum_d += results[j].points * sim->factors[j]; //lock threads here?
}
score_accum_d /= std::accumulate(sim->factors.begin(), sim->factors.end(), .0);
score_accum = score_accum_d;
max_possible= max_possible_score[(size_t)optimization_mode];

//APN
trials = count;
successes = score_accum / max_possible;
if(successes > trials)
{
successes = trials;
printf("WARNING: biominal successes {%Le} > trials {%d} in Threads\n", successes,trials);
//_DEBUG_MSG(2,"WARNING: biominal successes > trials in Threads");
}


// Get a loose (better than no) upper bound. TODO: Improve it.
compare_stop = (boost::math::binomial_distribution<>::find_upper_bound_on_p(trials, successes, prob) * max_possible <
thread_best_results->points + min_increment_of_score);
}
}
}
}
/*unsigned count{0};
std::vector<Results<uint64_t>> results;
for(unsigned k=0; k < thread_num_iterations;k++)
{
if(all_results[k].size() >0)
{
count++;
if(results.size()==0)
results = all_results[k];
else
results =merge(results,all_results[k]); //calculate single sim
}
}*/

for( unsigned i =0; i< results.size();++i)
evaluated_results.first[i] +=results[i];
evaluated_results.second+=thread_num_iterations;
}



static std::vector<Results<uint64_t>> merge(std::vector<Results<uint64_t>> out, std::vector<Results<uint64_t>> in)
{
Expand Down

0 comments on commit 418d8c7

Please sign in to comment.