forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 145
Resolve the segmentation fault occurring in the pw float implementation #6130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
7b855e6
add unit test
A-006 4c779e8
add intergrate test
A-006 f9e7710
fix process
A-006 a8d72af
modify jd
A-006 5faf27e
update bug
A-006 4773008
set fftw float
A-006 503bf58
add the float BPCG
A-006 4b5df98
add float test
A-006 16cb172
fix compile bug
A-006 f5c1fc1
fix error
A-006 677e5d6
fix the compile test
A-006 98decc4
Merge branch 'develop' into fft_float2
A-006 f632326
Merge branch 'develop' into fft_float2
A-006 300713c
add
A-006 1dbacf8
remove the test file
A-006 f565945
change the file
A-006 e1601ee
revert bug
A-006 f6fd16d
set the float type
A-006 bed7852
Merge branch 'develop' into fft_float2
A-006 80344ac
reset the FFT_MEASURE
A-006 c60bf81
update unittest
A-006 ed18346
change readme
A-006 1f66367
update threashold
A-006 4c63669
Merge branch 'develop' into fft_float2
A-006 7553e06
use the test file
A-006 385b010
fix unresonable comments
A-006 2e13c7f
update eslover before all runners
A-006 2bf18b9
Merge branch 'develop' into fft_float2
A-006 a224da7
fix compile bug
A-006 59b73f5
fix bug
A-006 f750e10
Merge branch 'develop' into fft_float2
mohanchen d193075
update README
A-006 a9b53a1
change chebyshev MPI part
A-006 5c156e5
Merge branch 'develop' into fft_float2
A-006 d5084f6
add new test
A-006 aa443f1
delete old test
A-006 2d2a550
remove old tests
A-006 b1f144e
add change
A-006 c60d13f
Merge branch 'develop' into fft_float2
A-006 df3c712
update tick
A-006 ca1b0d9
add back marco
A-006 5ca14cd
update change
A-006 be074ab
Merge branch 'develop' into fft_float2
A-006 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,4 +23,4 @@ __pycache__ | |
| abacus.json | ||
| *.npy | ||
| toolchain/install/ | ||
| toolchain/abacus_env.sh | ||
| toolchain/abacus_env.sh | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
207 changes: 207 additions & 0 deletions
207
source/module_base/test_parallel/math_chebyshev_mpi_test.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| #include "../math_chebyshev.h" | ||
| #include "mpi.h" | ||
| #include "module_base/parallel_comm.h" | ||
| #include "gmock/gmock.h" | ||
| #include "gtest/gtest.h" | ||
| /************************************************ | ||
| * unit test of class Chebyshev MPI part | ||
| ***********************************************/ | ||
|
|
||
| /** | ||
| * - Tested Functions: | ||
| * - checkconverge | ||
| */ | ||
| class toolfunc | ||
| { | ||
| public: | ||
| double x7(double x) | ||
| { | ||
| return pow(x, 7); | ||
| } | ||
| double x6(double x) | ||
| { | ||
| return pow(x, 6); | ||
| } | ||
| double expr(double x) | ||
| { | ||
| return exp(x); | ||
| } | ||
| std::complex<double> expi(std::complex<double> x) | ||
| { | ||
| const std::complex<double> j(0.0, 1.0); | ||
| return exp(j * x); | ||
| } | ||
| std::complex<double> expi2(std::complex<double> x) | ||
| { | ||
| const std::complex<double> j(0.0, 1.0); | ||
| const double PI = 3.14159265358979323846; | ||
| return exp(j * PI / 2.0 * x); | ||
| } | ||
| // Pauli matrix: [0,-i;i,0] | ||
| int LDA = 2; | ||
| double factor = 1; | ||
| void sigma_y(std::complex<double>* spin_in, std::complex<double>* spin_out, const int m = 1) | ||
| { | ||
| const std::complex<double> j(0.0, 1.0); | ||
| if (this->LDA < 2) { | ||
| this->LDA = 2; | ||
| } | ||
| for (int i = 0; i < m; ++i) | ||
| { | ||
| spin_out[LDA * i] = -factor * j * spin_in[LDA * i + 1]; | ||
| spin_out[LDA * i + 1] = factor * j * spin_in[LDA * i]; | ||
| } | ||
| } | ||
| #ifdef __ENABLE_FLOAT_FFTW | ||
| float x7(float x) | ||
| { | ||
| return pow(x, 7); | ||
| } | ||
| float x6(float x) | ||
| { | ||
| return pow(x, 6); | ||
| } | ||
| float expr(float x) | ||
| { | ||
| return exp(x); | ||
| } | ||
| std::complex<float> expi(std::complex<float> x) | ||
| { | ||
| const std::complex<float> j(0.0, 1.0); | ||
| return exp(j * x); | ||
| } | ||
| std::complex<float> expi2(std::complex<float> x) | ||
| { | ||
| const std::complex<float> j(0.0, 1.0); | ||
| const float PI = 3.14159265358979323846; | ||
| return exp(j * PI / 2.0f * x); | ||
| } | ||
| // Pauli matrix: [0,-i;i,0] | ||
| void sigma_y(std::complex<float>* spin_in, std::complex<float>* spin_out, const int m = 1) | ||
| { | ||
| const std::complex<float> j(0.0, 1.0); | ||
| if (this->LDA < 2) | ||
| this->LDA = 2; | ||
| for (int i = 0; i < m; ++i) | ||
| { | ||
| spin_out[LDA * i] = -j * spin_in[LDA * i + 1]; | ||
| spin_out[LDA * i + 1] = j * spin_in[LDA * i]; | ||
| } | ||
| } | ||
| #endif | ||
| }; | ||
| class MathChebyshevTest : public testing::Test | ||
| { | ||
| protected: | ||
| ModuleBase::Chebyshev<double>* p_chetest; | ||
| ModuleBase::Chebyshev<float>* p_fchetest; | ||
| toolfunc fun; | ||
| int dsize = 0; | ||
| int my_rank = 0; | ||
| void SetUp() override | ||
| { | ||
| int world_rank; | ||
| MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); | ||
| int world_size; | ||
| MPI_Comm_size(MPI_COMM_WORLD, &world_size); | ||
|
|
||
| int color = (world_rank < world_size / 2) ? 0 : 1; | ||
| int key = world_rank; | ||
|
|
||
| MPI_Comm_split(MPI_COMM_WORLD, color, key, &POOL_WORLD); | ||
|
|
||
| int pool_rank, pool_size; | ||
| MPI_Comm_rank(POOL_WORLD, &pool_rank); | ||
| MPI_Comm_size(POOL_WORLD, &pool_size); | ||
| } | ||
| void TearDown() override | ||
| { | ||
| } | ||
| }; | ||
|
|
||
| TEST_F(MathChebyshevTest, checkconverge) | ||
| { | ||
| const int norder = 100; | ||
| p_chetest = new ModuleBase::Chebyshev<double>(norder); | ||
| auto fun_sigma_y | ||
| = [&](std::complex<double>* in, std::complex<double>* out, const int m = 1) { fun.sigma_y(in, out, m); }; | ||
|
|
||
| std::complex<double>* v = new std::complex<double>[4]; | ||
| v[0] = 1.0; | ||
| v[1] = 0.0; | ||
| v[2] = 0.0; | ||
| v[3] = 1.0; //[1 0; 0 1] | ||
| double tmin = -1.1; | ||
| double tmax = 1.1; | ||
| bool converge; | ||
| converge = p_chetest->checkconverge(fun_sigma_y, v, 2, 2, tmax, tmin, 0.2); | ||
| EXPECT_TRUE(converge); | ||
| converge = p_chetest->checkconverge(fun_sigma_y, v + 2, 2, 2, tmax, tmin, 0.2); | ||
| EXPECT_TRUE(converge); | ||
| EXPECT_NEAR(tmin, -1.1, 1e-8); | ||
| EXPECT_NEAR(tmax, 1.1, 1e-8); | ||
|
|
||
| tmax = -1.1; | ||
| converge = p_chetest->checkconverge(fun_sigma_y, v, 2, 2, tmax, tmin, 2.2); | ||
| EXPECT_TRUE(converge); | ||
| EXPECT_NEAR(tmin, -1.1, 1e-8); | ||
| EXPECT_NEAR(tmax, 1.1, 1e-8); | ||
|
|
||
| // not converge | ||
| v[0] = std::complex<double>(0, 1), v[1] = 1; | ||
| fun.factor = 1.5; | ||
| tmin = -1.1, tmax = 1.1; | ||
| converge = p_chetest->checkconverge(fun_sigma_y, v, 2, 2, tmax, tmin, 0.2); | ||
| EXPECT_FALSE(converge); | ||
|
|
||
| fun.factor = -1.5; | ||
| tmin = -1.1, tmax = 1.1; | ||
| converge = p_chetest->checkconverge(fun_sigma_y, v, 2, 2, tmax, tmin, 0.2); | ||
| EXPECT_FALSE(converge); | ||
| fun.factor = 1; | ||
|
|
||
| delete[] v; | ||
| delete p_chetest; | ||
| } | ||
|
|
||
| #ifdef __ENABLE_FLOAT_FFTW | ||
| TEST_F(MathChebyshevTest, checkconverge_float) | ||
| { | ||
| const int norder = 100; | ||
| p_fchetest = new ModuleBase::Chebyshev<float>(norder); | ||
|
|
||
| std::complex<float>* v = new std::complex<float>[4]; | ||
| v[0] = 1.0; | ||
| v[1] = 0.0; | ||
| v[2] = 0.0; | ||
| v[3] = 1.0; //[1 0; 0 1] | ||
| float tmin = -1.1; | ||
| float tmax = 1.1; | ||
| bool converge; | ||
|
|
||
| auto fun_sigma_yf | ||
| = [&](std::complex<float>* in, std::complex<float>* out, const int m = 1) { fun.sigma_y(in, out, m); }; | ||
| converge = p_fchetest->checkconverge(fun_sigma_yf, v, 2, 2, tmax, tmin, 0.2); | ||
| EXPECT_TRUE(converge); | ||
| converge = p_fchetest->checkconverge(fun_sigma_yf, v + 2, 2, 2, tmax, tmin, 0.2); | ||
| EXPECT_TRUE(converge); | ||
| EXPECT_NEAR(tmin, -1.1, 1e-6); | ||
| EXPECT_NEAR(tmax, 1.1, 1e-6); | ||
|
|
||
| delete[] v; | ||
| delete p_fchetest; | ||
| } | ||
| #endif | ||
|
|
||
| int main(int argc, char** argv) | ||
| { | ||
| #ifdef __MPI | ||
| MPI_Init(&argc, &argv); | ||
| #endif | ||
| testing::InitGoogleTest(&argc, argv); | ||
| int result = RUN_ALL_TESTS(); | ||
| #ifdef __MPI | ||
| MPI_Finalize(); | ||
| #endif | ||
| return result; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.