Skip to content
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

Collapsed style in StlPrettyPrint. #3512

Merged
merged 2 commits into from
Oct 5, 2021
Merged

Conversation

ye-luo
Copy link
Contributor

@ye-luo ye-luo commented Oct 5, 2021

Proposed changes

Long vectors are lengthy. walkers_per_crowd has num_crowd elements. walkers_per_rank has num_rank elements.
num_crowd can be hundreds in CPU runs and num_ranks can be tens of thousands.
Usually these vectors has very limited distinct values and are better printed in collapsed style.
[3, 3, 2, 2] is printed as [3(x2), 2(x2)]

What type(s) of changes does this code introduce?

  • New feature

Does this introduce a breaking change?

  • No

What systems has this change been tested on?

epyc-server

Checklist

  • Yes. This PR is up to date with current the current state of 'develop'
  • Yes. Code added or changed in the PR has been clang-formatted
  • Yes. This PR adds tests to cover any new code, or to catch a bug that is being fixed

@ye-luo ye-luo requested a review from PDoakORNL October 5, 2021 14:09
Comment on lines +28 to 44
auto cursor = rhs.begin();
while (cursor != rhs.end())
{
auto last = rhs.end();
last--;
copy(rhs.begin(), last, std::ostream_iterator<T>(out, ", "));
out << *last;
// each iteration handles one unique value
const T ref_value = *cursor;
size_t count = 1;
while (++cursor != rhs.end() && *cursor == ref_value)
count++;
out << ref_value;
// identical elements are collapsed
if (count > 1)
out << "(x" << count << ")";
// if not the last element, add a separator
if (cursor != rhs.end())
out << ", ";
}
out << "]";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The internals of this operator would be better extracted to a function. More precisely, two functions - one for the original code (print all the values), and one for the run-length encoded output. Then the << operator can call the appropriate function. It seems likely that there would be cases where one would want to specify the type of output directly (regular or compressed).

Copy link
Contributor Author

@ye-luo ye-luo Oct 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the use of this StlPrettyPrint.hpp need to be changed to the new style. Keeping two functions is only necessary when both use cases appear.

Copy link
Contributor

@markdewing markdewing Oct 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you certain that the compressed output format is desirable every where an STL vector is printed? It seems unlikely to me (though that's just a prior belief before actually analyzing all such places). A point of program variation has been identified, and it seems wise to express it in the code. We may want separation between policy (what "<<" outputs for an STL vector) and implementation (how details of a particular format works).

I imagine the structure to be something like:

template <typename T>
std::ostream& prettPrintSTLVector(std::ostream& out, const std::vector<T>& rhs)
{
   ... old formatting code ...
}

template <typename T>
std::ostream& prettPrintSTLVectorRLE(std::ostream& out, const std::vector<T>& rhs)
{
   ... new formatting code ...
}

template<typename T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& rhs)
{
    return prettyPrintSTLVectorRLE(out, rhs);
}

Then the unit test code tests the implementations (prettyPrintSTLVector...) and not the policy ("<<").

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually even with two functions. I feel it is cumbersome to make a selection via operator <<. by including different header files?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's probably a better design. Ideally, one could say something like std::cout << prettyPrintSTLVector(vec) << std::endl; to specify a particular format. Maybe the formatting functions should return a std::string? (std::string prettyPrintSTLVector(std::vector<T> &in))

Copy link
Contributor Author

@ye-luo ye-luo Oct 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now QMCDriverNew::startup is the only consumer. In general, there is no reason to print in qmcpack output in uncompressed format. As the print is always in one line and we never want long lines.
If printing is needed for debugging purpose, the develop can do whatever they need.
So I don't really feel the need to keep both.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markdewing what does RLE stands for?
If we implement two versions, there is definitely need to separate them and test against individual ones. What @PDoakORNL mentioned about state manipulation is interesting but it looks like for rainy day fun. Can we defer all these attempts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RLE = Run-length encoding.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can defer this.

@ye-luo ye-luo force-pushed the fix-StlPrettyPrint branch from 9ec6c70 to 486884f Compare October 5, 2021 18:47
Copy link
Contributor

@PDoakORNL PDoakORNL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially used this for debugging, and one of the purposes I used this for was dump out data in a format python liked. Then I used to to write output from QMCDriverNew and that appears to be the only place in the codebase it's still used. The compressed version is much nicer for general users and for the places its actually used.

I would like there still to be an operator<< available for vectors because its annoying not to have one in application.

iostream does have some hooks that allow code to put temporary state into a stream which I think is what I would do if I wanted two operator<< implementations for std::vector I could switch between. That's definitely not needed at the moment and the c++ golf implementation will still be in the repo to recover if needed.

@ye-luo
Copy link
Contributor Author

ye-luo commented Oct 5, 2021

Start testing in-house

@ye-luo ye-luo merged commit 132b560 into QMCPACK:develop Oct 5, 2021
@ye-luo ye-luo deleted the fix-StlPrettyPrint branch October 5, 2021 20:28
PDoakORNL added a commit to PDoakORNL/qmcpack that referenced this pull request Oct 6, 2021
commit 22cc717
Author: Peter Doak <doakpw@ornl.gov>
Date:   Wed Oct 6 13:05:22 2021 -0400

    propagating mw_invertPsiM const API changes

commit fea01c4
Merge: 4e8b3f4 f7874e4
Author: Peter Doak <doakpw@ornl.gov>
Date:   Wed Oct 6 12:38:07 2021 -0400

    Merge branch 'develop' into matrix_update_engines_direct_2

commit f7874e4
Merge: 319938f 3a1fc75
Author: Ye Luo <yeluo@anl.gov>
Date:   Wed Oct 6 10:57:22 2021 -0500

    Merge pull request QMCPACK#3514 from ye-luo/fix-omp-nocuda

    Fix omp offload without cuda

commit 3a1fc75
Merge: 4b2ef72 319938f
Author: Ye Luo <yeluo@anl.gov>
Date:   Tue Oct 5 21:49:12 2021 -0500

    Merge branch 'develop' into fix-omp-nocuda

commit 319938f
Merge: c093820 1a71e25
Author: Ye Luo <yeluo@anl.gov>
Date:   Tue Oct 5 21:27:24 2021 -0500

    Merge pull request QMCPACK#3510 from camelto2/dirac_converter_msd

    Dirac converter with MSD wave functions

commit 4b2ef72
Author: Ye Luo <yeluo@anl.gov>
Date:   Tue Oct 5 20:43:26 2021 -0500

    Mark all the RefVector const.

commit 3191d09
Author: Ye Luo <yeluo@anl.gov>
Date:   Tue Oct 5 20:38:22 2021 -0500

    Revert integration with DiracMatrixComputeOMPTarget

commit 1a71e25
Merge: 9414af2 c093820
Author: Ye Luo <yeluo@anl.gov>
Date:   Tue Oct 5 18:36:14 2021 -0500

    Merge branch 'develop' into dirac_converter_msd

commit 9414af2
Author: camelto2 <cmelton@sandia.gov>
Date:   Tue Oct 5 17:28:37 2021 -0600

    fix libxml leak

commit c093820
Merge: 132b560 309afa1
Author: Ye Luo <yeluo@anl.gov>
Date:   Tue Oct 5 16:55:34 2021 -0500

    Merge pull request QMCPACK#3513 from quantumsteve/available_supported

    cif2cell_supported not set

commit 309afa1
Merge: 94b98f5 132b560
Author: Ye Luo <yeluo@anl.gov>
Date:   Tue Oct 5 15:51:21 2021 -0500

    Merge branch 'develop' into available_supported

commit 132b560
Merge: 67490d9 486884f
Author: Ye Luo <yeluo@anl.gov>
Date:   Tue Oct 5 15:28:08 2021 -0500

    Merge pull request QMCPACK#3512 from ye-luo/fix-StlPrettyPrint

    Collapsed style in StlPrettyPrint.

commit 94b98f5
Author: Steven Hahn <hahnse@ornl.gov>
Date:   Tue Oct 5 15:02:00 2021 -0400

    copy/paste error

    Signed-off-by: Steven Hahn <hahnse@ornl.gov>

commit 486884f
Author: Ye Luo <yeluo@anl.gov>
Date:   Tue Oct 5 13:47:02 2021 -0500

    Remove unused header inclusion.

commit a468c4a
Author: Ye Luo <yeluo@anl.gov>
Date:   Tue Oct 5 01:12:10 2021 -0500

    Collapsed style in StlPrettyPrint.

commit 67490d9
Merge: aca1bf6 4ea1d47
Author: Ye Luo <yeluo@anl.gov>
Date:   Tue Oct 5 12:22:50 2021 -0500

    Merge pull request QMCPACK#3511 from quantumsteve/cif2cell_available

    Check if cif2cell is available before running ntest_nexus_structure

commit 4ea1d47
Author: Steven Hahn <hahnse@ornl.gov>
Date:   Tue Oct 5 11:02:22 2021 -0400

    Add Python 3.10.0

    Signed-off-by: Steven Hahn <hahnse@ornl.gov>

commit 20d2e84
Author: Steven Hahn <hahnse@ornl.gov>
Date:   Tue Oct 5 10:03:43 2021 -0400

    Check if cif2cell is available before running test

    Signed-off-by: Steven Hahn <hahnse@ornl.gov>

commit bbfe24f
Author: camelto2 <cmelton@sandia.gov>
Date:   Mon Oct 4 16:09:36 2021 -0600

    fix uninnitialized warning

commit ee35c16
Author: camelto2 <cmelton@sandia.gov>
Date:   Mon Oct 4 14:51:18 2021 -0600

    remove unused code in DiracParser

commit 0983b0a
Author: camelto2 <cmelton@sandia.gov>
Date:   Mon Oct 4 14:18:26 2021 -0600

    update manual entry for convert4qmc with DIRAC

commit 8e064a0
Author: camelto2 <cmelton@sandia.gov>
Date:   Mon Oct 4 14:11:11 2021 -0600

    clang formatting

commit 806d493
Author: camelto2 <cmelton@sandia.gov>
Date:   Mon Oct 4 14:04:21 2021 -0600

    update unit and converter tests to reflect changes in MSD for dirac

    I updated the gold.orbs.h5 to use convert4qmc -dirac df_Bi.out -TargetState 14 -prefix gold -nojastrow
    This tests the converter to make sure it can grab an arbitrary excited state to store in the hdf5.
    However, this change made it so that I needed to update the multi_slater unit tests, which relied
    on this gold.orbs.h5 file. Also, added to the unit test is reading the CI coeffs directly from the h5 file

commit 3c48afd
Merge: a4ebddb aca1bf6
Author: camelto2 <cmelton@sandia.gov>
Date:   Mon Oct 4 09:30:53 2021 -0600

    Merge remote-tracking branch 'upstream/develop' into dirac_converter_msd

commit aca1bf6
Merge: 618cdb2 2318723
Author: Paul R. C. Kent <kentpr@ornl.gov>
Date:   Sun Oct 3 13:02:42 2021 -0400

    Merge pull request QMCPACK#3505 from anbenali/Convert4qmcGuessH5Format

    Convert4qmc guess h5 format

commit 2318723
Author: Anouar Benali <abenali.sci@gmail.com>
Date:   Sun Oct 3 01:09:41 2021 -0500

    fixing passing an hdf5 file without the -orbitals tag. closing bug # QMCPACK#3503

commit 273ecb0
Author: Anouar Benali <abenali.sci@gmail.com>
Date:   Sat Oct 2 23:57:51 2021 -0500

    Change default behavior of convert4qmc: Will only generate inputs with Jastrows unless -nojastrow is specified, then only inputs with no jastrow will be generated

commit 618cdb2
Merge: c0ed5f1 0a13c01
Author: Paul R. C. Kent <kentpr@ornl.gov>
Date:   Sat Oct 2 13:32:16 2021 -0400

    Merge pull request QMCPACK#3502 from ye-luo/fix-nightly

    Fix and update nightly test scripts.

commit 0a13c01
Author: Ye Luo <yeluo@anl.gov>
Date:   Sat Oct 2 11:29:44 2021 -0500

    Fix and update nightly test scripts.

commit c0ed5f1
Merge: 4b9b609 b7ce2c8
Author: Ye Luo <yeluo@anl.gov>
Date:   Fri Oct 1 18:33:06 2021 -0500

    Merge pull request QMCPACK#3501 from ye-luo/fix-hip

    Fix HIP CMake

commit b7ce2c8
Author: Ye Luo <yeluo@anl.gov>
Date:   Fri Oct 1 17:27:49 2021 -0500

    Fix HIP CMake.

commit 4b9b609
Merge: 91fa888 4042431
Author: Ye Luo <yeluo@anl.gov>
Date:   Fri Oct 1 15:37:41 2021 -0500

    Merge pull request QMCPACK#3489 from prckent/ppconvertcmakeclean

    Fix ppconvert memory bugs and enable in testing

commit 4042431
Merge: d48bd76 91fa888
Author: Ye Luo <yeluo@anl.gov>
Date:   Fri Oct 1 14:37:23 2021 -0500

    Merge remote-tracking branch 'origin/develop' into ppconvertcmakeclean

commit d48bd76
Author: Ye Luo <yeluo@anl.gov>
Date:   Fri Oct 1 14:37:06 2021 -0500

    Update README.md about CUDA_ARCH

commit 91fa888
Author: William F Godoy <williamfgc@yahoo.com>
Date:   Wed Sep 29 11:10:37 2021 -0400

    Add docs for macOS CI

commit fe5aa2d
Author: William F Godoy <williamfgc@yahoo.com>
Date:   Wed Sep 29 09:46:20 2021 -0400

    Add Python dependencies on macOS runner

commit 60724b9
Author: William F Godoy <williamfgc@yahoo.com>
Date:   Tue Sep 28 17:06:13 2021 -0400

    Reduce brew dependencies

commit 72d4c01
Author: William F Godoy <williamfgc@yahoo.com>
Date:   Tue Sep 28 16:39:07 2021 -0400

    Add macOS CI on GitHub Actions

    gcc-11 real build
    brew dependencies

commit 7ee1a1d
Merge: d008890 a4bb505
Author: Paul R. C. Kent <kentpr@ornl.gov>
Date:   Fri Oct 1 13:37:48 2021 -0400

    Merge pull request QMCPACK#3492 from quantumsteve/cudatoolkit

    Eliminate deprecated find_package(CUDA) from qmcpack

commit a4ebddb
Author: camelto2 <cmelton@sandia.gov>
Date:   Fri Oct 1 10:43:24 2021 -0600

    fix for spinors in h5 and xml for MSD

commit a4bb505
Merge: d947ca1 d008890
Author: Ye Luo <yeluo@anl.gov>
Date:   Fri Oct 1 12:08:40 2021 -0400

    Merge remote-tracking branch 'origin/develop' into cudatoolkit

commit d947ca1
Author: Ye Luo <yeluo@anl.gov>
Date:   Fri Oct 1 12:08:26 2021 -0400

    Update build_olcf_summit_Clang.sh

commit d008890
Merge: a556925 d546e4e
Author: Ye Luo <yeluo@anl.gov>
Date:   Fri Oct 1 11:08:04 2021 -0500

    Merge pull request QMCPACK#3498 from ye-luo/opt-J2

    Fix and optimize offload J2

commit 3884a95
Author: camelto2 <cmelton@sandia.gov>
Date:   Thu Sep 30 22:27:46 2021 -0600

    correct MSD xml generated

commit d546e4e
Author: Ye Luo <yeluo@anl.gov>
Date:   Thu Sep 30 22:19:53 2021 -0500

    Minimize recompute in J2.

commit 517dea7
Author: Ye Luo <yeluo@anl.gov>
Date:   Thu Sep 30 01:14:49 2021 -0500

    Cure non-determinisitic offload J2.

    Reproducer:
    NiO a64 batched_driver performance test. Run 1 VMC step with 1 thread over and over.
    The scalar.dat is not deterministic. Kinetic is different.
    mw_updateVGL. Inject print before and after the offload region. walker 13 and electron 741.
    Sometimes the value is not updated even if a walker is accepted.

commit 587634d
Author: Ye Luo <yeluo@anl.gov>
Date:   Thu Sep 30 19:10:31 2021 -0500

    Update installation.rst

commit f8ed8db
Merge: fe7fba7 a556925
Author: Ye Luo <yeluo@anl.gov>
Date:   Thu Sep 30 19:01:19 2021 -0500

    Merge remote-tracking branch 'origin/develop' into cudatoolkit

commit fe7fba7
Author: Ye Luo <yeluo@anl.gov>
Date:   Thu Sep 30 19:00:23 2021 -0500

    Allow OFFLOAD_ARCH not being set for NVHPC.

commit a9e69a1
Author: Ye Luo <yeluo@anl.gov>
Date:   Thu Sep 30 18:43:55 2021 -0500

    Make NVHPC support CMAKE_CUDA_ARCHITECTURES as a list.

commit be7893e
Author: Ye Luo <yeluo@anl.gov>
Date:   Thu Sep 30 16:58:44 2021 -0500

    Our header only wrappers needs cuda include path.

commit 9b36461
Merge: 575ea73 34953ef
Author: camelto2 <cmelton@sandia.gov>
Date:   Thu Sep 30 14:38:47 2021 -0600

    Merge remote-tracking branch 'upstream/develop' into dirac_converter_msd

commit 575ea73
Author: camelto2 <cmelton@sandia.gov>
Date:   Thu Sep 30 14:37:43 2021 -0600

    enable complete open shell CI parsing for DIRAC converter

commit 8f1b5af
Author: Steven Hahn <hahnse@ornl.gov>
Date:   Thu Sep 30 16:30:05 2021 -0400

    update documentation

    Signed-off-by: Steven Hahn <hahnse@ornl.gov>

commit afd2294
Author: Steven Hahn <hahnse@ornl.gov>
Date:   Thu Sep 30 16:06:50 2021 -0400

    Check LLVM offload only contains one architecture

    Signed-off-by: Steven Hahn <hahnse@ornl.gov>

commit 3ca4e31
Merge: 3ba75e9 b5571ec
Author: Paul R. C. Kent <kentpr@ornl.gov>
Date:   Thu Sep 30 14:51:29 2021 -0400

    Merge pull request #1 from williamfgc/ppconvertcmakeclean-fix-leaks

    Ppconvertcmakeclean fix memory leaks

commit b5571ec
Author: William F Godoy <williamfgc@yahoo.com>
Date:   Thu Sep 30 13:46:49 2021 -0400

    Revert clang-format related changes

commit 9b2e2fb
Author: William F Godoy <williamfgc@yahoo.com>
Date:   Thu Sep 30 11:47:07 2021 -0400

    Fix leaks associated with Grid raw pointer

    Use std::shared_ptr to enable copy constructors

commit 216d9dd
Author: William F Godoy <williamfgc@yahoo.com>
Date:   Thu Sep 30 10:47:27 2021 -0400

    Address leaks in XMLWriterClass

    Use std::shared_ptr to allow for deep copy constructors

commit 058e446
Author: Ye Luo <yeluo@anl.gov>
Date:   Thu Sep 30 10:06:18 2021 -0400

    Update recipes under config for CUDA change.

commit b39aea6
Author: Ye Luo <yeluo@anl.gov>
Date:   Wed Sep 29 19:06:57 2021 -0500

    Set CMAKE_CUDA_ARCHITECTURES early.

commit ebf7849
Author: Ye Luo <yeluo@anl.gov>
Date:   Wed Sep 29 19:02:47 2021 -0500

    Make platform_cuda_legacy depend on CUDA::cudart

commit 81457ad
Merge: 57e55d3 ed14d86
Author: Ye Luo <yeluo@anl.gov>
Date:   Wed Sep 29 17:52:01 2021 -0500

    Merge remote-tracking branch 'origin/develop' into cudatoolkit

commit 57e55d3
Author: Ye Luo <yeluo@anl.gov>
Date:   Wed Sep 29 17:30:50 2021 -0500

    Set back CUDA default to C++14.

commit 734415c
Author: Ye Luo <yeluo@anl.gov>
Date:   Wed Sep 29 17:24:08 2021 -0500

    CMAKE_CUDA_ARCHITECTURES needs CMake 3.18.

commit 707977e
Author: Ye Luo <yeluo@anl.gov>
Date:   Wed Sep 29 17:22:44 2021 -0500

    More accurate stopper message.

commit 761745b
Author: Steven Hahn <hahnse@ornl.gov>
Date:   Wed Sep 29 17:36:10 2021 -0400

    Apply changes recommended by @ye-lou.

    Signed-off-by: Steven Hahn <hahnse@ornl.gov>

commit b607510
Author: Steven Hahn <hahnse@ornl.gov>
Date:   Wed Sep 29 15:06:19 2021 -0400

    Don't change required CMake version

    Signed-off-by: Steven Hahn <hahnse@ornl.gov>

commit ed13bd8
Author: Steven Hahn <hahnse@ornl.gov>
Date:   Fri Sep 24 10:47:26 2021 -0400

    Eliminate depricated find_package(CUDA) from qmcpack

    Replace it with first-class language support and find_package(CUDAToolkit)

    Signed-off-by: Steven Hahn <hahnse@ornl.gov>

commit 3ba75e9
Author: Paul Kent <kentpr@ornl.gov>
Date:   Tue Sep 28 22:04:05 2021 -0400

    Test label

commit dc39dba
Author: Paul Kent <kentpr@ornl.gov>
Date:   Tue Sep 28 21:55:32 2021 -0400

    Try public in cmake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants