Skip to content

Commit 201f752

Browse files
authored
Fix and reopen UT in HContainer output. (#5781)
1 parent 9bf2533 commit 201f752

File tree

4 files changed

+46
-49
lines changed

4 files changed

+46
-49
lines changed

source/module_base/parallel_2d.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,24 @@ bool Parallel_2D::in_this_processor(const int iw1_all, const int iw2_all) const
1212

1313
int Parallel_2D::get_global_row_size() const
1414
{
15+
if (!is_serial)
16+
{
1517
#ifdef __MPI
16-
return desc[2];
17-
#else
18-
return nrow;
18+
return desc[2];
1919
#endif
20+
}
21+
return nrow;
2022
}
2123

2224
int Parallel_2D::get_global_col_size() const
2325
{
26+
if (!is_serial)
27+
{
2428
#ifdef __MPI
25-
return desc[3];
26-
#else
27-
return ncol;
29+
return desc[3];
2830
#endif
31+
}
32+
return ncol;
2933
}
3034

3135
#ifdef __MPI
@@ -133,6 +137,7 @@ void Parallel_2D::set_serial(const int mg, const int ng)
133137
std::iota(local2global_col_.begin(), local2global_col_.end(), 0);
134138
global2local_row_ = local2global_row_;
135139
global2local_col_ = local2global_col_;
140+
is_serial = true;
136141
#ifdef __MPI
137142
blacs_ctxt = -1;
138143
#endif

source/module_base/parallel_2d.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ class Parallel_2D
129129
/// process coordinate in the BLACS grid
130130
int coord[2] = {-1, -1};
131131

132+
/// whether to use the serial mode
133+
bool is_serial = false;
134+
132135
protected:
133136
/// map from global index to local index
134137
std::vector<int> global2local_row_;

source/module_hamilt_lcao/module_hcontainer/output_hcontainer.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,42 +40,34 @@ void Output_HContainer<T>::write(int rx_in, int ry_in, int rz_in)
4040
int find_R = 0;
4141
for (int iR = 0; iR < size_for_loop_R; iR++)
4242
{
43-
std::cout << __FILE__ << " " << __LINE__ << std::endl;
44-
4543
this->_hcontainer->loop_R(iR, rx, ry, rz);
4644
if (rx == rx_in && ry == ry_in && rz == rz_in)
4745
{
48-
std::cout << __FILE__ << " " << __LINE__ << std::endl;
49-
5046
find_R += 1;
5147
this->write_single_R(rx, ry, rz);
52-
std::cout << __FILE__ << " " << __LINE__ << std::endl;
53-
5448
break;
5549
}
56-
std::cout << __FILE__ << " " << __LINE__ << std::endl;
57-
5850
}
5951
if (find_R == 0)
6052
{
61-
ModuleBase::WARNING_QUIT("Output_HContainer::write", "Cannot find the R vector from the HContaine");
53+
ModuleBase::WARNING_QUIT("Output_HContainer::write", "Cannot find the R vector from the HContainer.");
6254
}
6355
}
6456

6557
template <typename T>
6658
void Output_HContainer<T>::write_single_R(int rx, int ry, int rz)
6759
{
68-
std::cout << __FILE__ << " " << __LINE__ << std::endl;
69-
60+
if (this->_hcontainer->get_paraV() == nullptr)
61+
{
62+
ModuleBase::WARNING_QUIT("Output_HContainer::write_single_R", "paraV is nullptr! Unable to write the matrix.");
63+
}
7064
this->_hcontainer->fix_R(rx, ry, rz);
71-
std::cout << __FILE__ << " " << __LINE__ << std::endl;
7265

7366
ModuleIO::SparseMatrix<T> sparse_matrix
7467
= ModuleIO::SparseMatrix<T>(_hcontainer->get_nbasis(), _hcontainer->get_nbasis());
75-
std::cout << __FILE__ << " " << __LINE__ << std::endl;
68+
assert(_hcontainer->get_nbasis()>0);
7669

7770
sparse_matrix.setSparseThreshold(this->_sparse_threshold);
78-
std::cout << __FILE__ << " " << __LINE__ << std::endl;
7971

8072
for (int iap = 0; iap < this->_hcontainer->size_atom_pairs(); ++iap)
8173
{
@@ -93,7 +85,6 @@ void Output_HContainer<T>::write_single_R(int rx, int ry, int rz)
9385
}
9486
}
9587
}
96-
std::cout << __FILE__ << " " << __LINE__ << std::endl;
9788

9889
if (sparse_matrix.getNNZ() != 0)
9990
{

source/module_hamilt_lcao/module_hcontainer/test/CMakeLists.txt

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,35 +42,33 @@ add_test(NAME hontainer_para_test
4242
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
4343
)
4444

45-
#AddTest(
46-
# TARGET hcontainer_output_test
47-
# LIBS parameter base ${math_libs} device
48-
# SOURCES test_hcontainer_output.cpp
49-
# tmp_mocks.cpp
50-
# ../output_hcontainer.cpp
51-
# ../base_matrix.cpp
52-
# ../hcontainer.cpp
53-
# ../atom_pair.cpp
54-
# ../../../module_basis/module_ao/parallel_2d.cpp
55-
# ../../../module_basis/module_ao/parallel_orbitals.cpp
56-
# ../../../module_io/sparse_matrix.cpp
57-
#)
45+
AddTest(
46+
TARGET hcontainer_output_test
47+
LIBS parameter base ${math_libs} device
48+
SOURCES test_hcontainer_output.cpp
49+
tmp_mocks.cpp
50+
../output_hcontainer.cpp
51+
../base_matrix.cpp
52+
../hcontainer.cpp
53+
../atom_pair.cpp
54+
../../../module_basis/module_ao/parallel_orbitals.cpp
55+
../../../module_io/sparse_matrix.cpp
56+
)
5857

5958
install(DIRECTORY support DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
6059

61-
#AddTest(
62-
# TARGET hcontainer_readCSR_test
63-
# LIBS parameter base ${math_libs} device cell_info
64-
# SOURCES test_hcontainer_readCSR.cpp
65-
# ../base_matrix.cpp
66-
# ../hcontainer.cpp
67-
# ../atom_pair.cpp
68-
# ../output_hcontainer.cpp
69-
# ../../../module_basis/module_ao/parallel_2d.cpp
70-
# ../../../module_basis/module_ao/parallel_orbitals.cpp
71-
# ../../../module_io/sparse_matrix.cpp
72-
# ../../../module_io/csr_reader.cpp
73-
# ../../../module_io/file_reader.cpp
74-
# ../../../module_io/output.cpp
75-
#)
60+
AddTest(
61+
TARGET hcontainer_readCSR_test
62+
LIBS parameter base ${math_libs} device cell_info
63+
SOURCES test_hcontainer_readCSR.cpp
64+
../base_matrix.cpp
65+
../hcontainer.cpp
66+
../atom_pair.cpp
67+
../output_hcontainer.cpp
68+
../../../module_basis/module_ao/parallel_orbitals.cpp
69+
../../../module_io/sparse_matrix.cpp
70+
../../../module_io/csr_reader.cpp
71+
../../../module_io/file_reader.cpp
72+
../../../module_io/output.cpp
73+
)
7674
endif()

0 commit comments

Comments
 (0)