Skip to content

Commit

Permalink
v0.15. Major upudate. Performance is improved by 25% by using steps f…
Browse files Browse the repository at this point in the history
…ast sin/cos/tan function. The serial dynamic simulation time of v0.14.1 on a Intel i7-10710u takes about 120s for simulation of 10s of a 12.5k bus system (sgcc-east-northwest) with step of 5ms. The new time consumption of v0.15 becomes about 90s. If run with parallel number=3, the time consumption becomes about 60s. asin/acos/atan/sqrt should be further improved in the future.
  • Loading branch information
changgang committed Feb 8, 2020
1 parent d407281 commit e823969
Show file tree
Hide file tree
Showing 45 changed files with 582 additions and 294 deletions.
91 changes: 46 additions & 45 deletions code/STEPS.depend

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion code/header/STEPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class STEPS
void set_toolkit_name(const string& name);
string get_toolkit_name() const;

void enable_use_steps_fast_math_logic();
void disable_use_steps_fast_math_logic();
bool get_use_steps_fast_math_logic();

void set_thread_number(unsigned int n);
unsigned int get_thread_number() const;

Expand Down Expand Up @@ -78,7 +82,6 @@ class STEPS
public:
char steps_char_buffer[STEPS_MAX_TEMP_CHAR_BUFFER_SIZE];
STEPS_API_SEARCH_BUFFER api_search_buffer;

private:
string toolkit_name;

Expand Down
2 changes: 1 addition & 1 deletion code/header/basic/steps_enum.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef STEPS_ENUM_H
#define STEPS_ENUM_H

#include <iso646.h>
#include <iso646.h>

// bus enum
enum BUS_TYPE
Expand Down
37 changes: 30 additions & 7 deletions code/header/basic/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,40 @@ double deg2rad(double angle);

double radps2hz(double w);
double hz2radps(double f);

double steps_sin(double angle_in_rad);
double steps_fast_sin(double angle_in_rad);

double steps_cos(double angle_in_rad);
double steps_fast_cos(double angle_in_rad);

double steps_tan(double angle_in_rad);
double steps_fast_tan(double angle_in_rad);

double steps_asin(double x);
double steps_fast_asin(double x);

double steps_acos(double x);
double steps_fast_acos(double x);

double steps_atan(double x);
double steps_fast_atan(double x);

double round_angle_in_rad_to_PI(double angle);
double round_angle_in_rad_to_HALF_PI(double angle);

double steps_fast_complex_abs(const complex<double>& z);
double steps_fast_complex_arg(const complex<double>& z);
double steps_fast_pow(double base, double exp);
double steps_fast_sine(double angle_in_rad);
double steps_fast_arcsine(double angle_in_rad);
double steps_fast_cosine(double angle_in_rad);
double steps_fast_arccosine(double angle_in_rad);
double steps_fast_tangent(double angle_in_rad);
double steps_fast_arctangent(double angle_in_rad);
double steps_fast_pow(double base, double exp);

double steps_sqrt(double x);
double steps_fast_sqrt(double x);

double steps_inv_sqrt(double x);
double steps_fast_inv_sqrt(double x);
float quick_inv_sqrt_Quake3(float x);
float quick_inv_sqrt_Lomont(float x);
double quick_double_inv_sqrt_Lomont(double x);

string trim_string(string str, const string& garbage="");
string replace_string_contents(string str, const string& source, const string& destination);
Expand Down
6 changes: 6 additions & 0 deletions code/header/basic/utility_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class UTILITY_TEST : public Test::Suite
void test_steps_fast_complex_abs();
void test_steps_fast_complex_arg();

void test_steps_fast_sin();
void test_steps_fast_cos();
void test_steps_fast_tan();
void test_steps_fast_sqrt();
void test_steps_fast_inv_sqrt();

void test_radps2hz();
void test_hz2radps();

Expand Down
2 changes: 2 additions & 0 deletions code/header/steps_namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ extern STEPS default_toolkit;
extern STEPS* toolkits[STEPS_MAX_TOOLKIT_SIZE];
extern std::mutex mtx;

extern bool use_steps_fast_math;

#endif // STEPS_NAMESPACE_H
3 changes: 2 additions & 1 deletion code/main_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ int main(int argc, char* argv[])
ts.add(unique_ptr<Test::Suite>(new OWNERSHIP_TEST));
ts.add(unique_ptr<Test::Suite>(new RATING_TEST));
ts.add(unique_ptr<Test::Suite>(new UTILITY_TEST));
/*
ts.add(unique_ptr<Test::Suite>(new SPARSE_MATRIX_TEST));
ts.add(unique_ptr<Test::Suite>(new COMPLEX_SPARSE_MATRIX_TEST));
Expand Down Expand Up @@ -337,7 +338,7 @@ int main(int argc, char* argv[])
ts.add(unique_ptr<Test::Suite>(new PVGU1_TEST));
ts.add(unique_ptr<Test::Suite>(new DYNAMICS_SIMULATOR_TEST));
ts.add(unique_ptr<Test::Suite>(new DYNAMICS_SIMULATOR_TEST));*/

//ts.add(unique_ptr<Test::Suite>(new CCT_SEARCHER_TEST));
//ts.add(unique_ptr<Test::Suite>(new POWERFLOW_CASE_GENERATOR_TEST));
Expand Down
19 changes: 19 additions & 0 deletions code/source/STEPS.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#include "header/STEPS.h"
#include "header/basic/utility.h"
#include "header/steps_namespace.h"
#include "header/basic/steps_enum.h"
#include <iostream>
#include <chrono>
#include <thread>
using namespace std;

STEPS::STEPS(const string& name, const string& log_file)
{
enable_use_steps_fast_math_logic();

ostringstream osstream;
std::this_thread::sleep_for(std::chrono::milliseconds(10));

Expand Down Expand Up @@ -68,6 +71,22 @@ string STEPS::get_toolkit_name() const
return toolkit_name;
}


void STEPS::enable_use_steps_fast_math_logic()
{
use_steps_fast_math = true;
}

void STEPS::disable_use_steps_fast_math_logic()
{
use_steps_fast_math = false;
}

bool STEPS::get_use_steps_fast_math_logic()
{
return use_steps_fast_math;
}

void STEPS::set_thread_number(unsigned int n)
{
thread_number = n;
Expand Down
11 changes: 11 additions & 0 deletions code/source/apis/steps_api_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ bool api_get_toolkit_bool_data(char* parameter_name, unsigned int toolkit_index)
{
return toolkit.is_optimize_network_enabled();
}
if(PARAMETER_NAME=="USE STEPS FAST MATH LOGIC")
{
return toolkit.get_use_steps_fast_math_logic();
}

show_parameter_not_supported_with_api(PARAMETER_NAME, __FUNCTION__);
return toolkit.steps_char_buffer;
Expand All @@ -181,6 +185,13 @@ void api_set_toolkit_bool_data(char* parameter_name, bool value, unsigned int to
else
return toolkit.disable_optimize_network();
}
if(PARAMETER_NAME=="USE STEPS FAST MATH LOGIC")
{
if(value==true)
return toolkit.enable_use_steps_fast_math_logic();
else
return toolkit.disable_use_steps_fast_math_logic();
}

show_parameter_not_supported_with_api(PARAMETER_NAME, __FUNCTION__);
return;
Expand Down
Loading

0 comments on commit e823969

Please sign in to comment.