기본 정보
- 저자
- DOI
- 10.48550/arxiv.1609.03930
- 저널
- arXiv (Cornell University)
- 발행년도
- 2022
- 발행기관
- Cornell University
- 피인용수
- 0
- 라이선스
- 0
- 논문 유형
- –
- 언어
- –
- 원문 페이지
- https://doi.org/10.48550/arxiv.1609.03930
- 토픽
- Laser Material Processing Techniques
- OpenAlex ID
- W6891889729
평가 내용
- 관련도
- 사업분야
- 산업용 섬유 · (10) 아라미드
- 부 분야
- –
- R&D 측면
- –
- 확신도
- –
- 근거 용어
- –
- 판단 근거
- 임베딩 유사도 기반 평가로 '산업용 섬유 > 아라미드' 분야에 선정된 논문입니다.
- R&D 활용 포인트
- –
- 평가 입력
- –
초록
The open source ALPS (Algorithms and Libraries for Physics Simulations) project provides a collection of physics libraries and applications, with a focus on simulations of lattice models and strongly correlated systems. The libraries provide a convenient set of well-documented and reusable components for developing condensed matter physics simulation code, and the applications strive to make commonly used and proven computational algorithms available to a non-expert community. In this paper we present an updated and refactored version of the core ALPS libraries geared at the computational physics software development community, rewritten with focus on documentation, ease of installation, and software maintainability.
본문 79,930자
본문 펼치기
## Updated Core Libraries of the ALPS Project
A. Gaenko <sup>a,</sup> <sup>_∗_</sup>, A. E. Antipov <sup>a</sup>, G. Carcassi <sup>a</sup>, T. Chen <sup>b</sup>, X. Chen <sup>a</sup>, Q. Dong <sup>a</sup>,
L. Gamper <sup>c</sup>, J. Gukelberger <sup>d</sup>, R. Igarashi <sup>e</sup>, S. Iskakov <sup>a</sup>, M. K¨onz <sup>c</sup>, J. P. F. LeBlanc <sup>a,f</sup>,
R. Levy <sup>a,g</sup>, P. N. Ma <sup>h</sup>, J. E. Paki <sup>a</sup>, H. Shinaoka <sup>i</sup>, S. Todo <sup>j,k</sup>, M. Troyer <sup>c</sup>, E. Gull <sup>a</sup>
_aUniversity_ _of_ _Michigan,_ _Ann_ _Arbor,_ _Michigan_ _48109,_ _USA_
_bWest_ _Chester_ _University_ _of_ _Pennsylvania,_ _West_ _Chester,_ _Pennsylvania_ _19383,_ _USA_
_cTheoretische_ _Physik,_ _ETH_ _Zurich,_ _8093_ _Zurich,_ _Switzerland_
_dD´epartement_ _de_ _Physique,_ _Universit´e_ _de_ _Sherbrooke,_ _Sherbrooke,_ _Qu´ebec,_ _J1K_ _2R1,_ _Canada_
_eInformation_ _Technology_ _Center,_ _the_ _University_ _of_ _Tokyo,_ _Tokyo_ _113-8658,_ _Japan_
_fDepartment_ _of_ _Physics_ _and_ _Physical_ _Oceanography,_ _Memorial_ _University_ _of_ _Newfoundland,_ _St._
_Johns,_ _Newfoundland_ _&_ _Labrador_ _A1B_ _3X7,_ _Canada_
_gUniversity_ _of_ _Illinois,_ _Urbana-Champaign,_ _Illinois_ _61820,_ _USA_
_hNational_ _University_ _of_ _Singapore,_ _Singapore_
_iDepartment_ _of_ _Physics,_ _Saitama_ _University,_ _Saitama_ _338-8570,_ _Japan_
_jDepartment_ _of_ _Physics,_ _University_ _of_ _Tokyo,_ _Tokyo_ _113-0033,_ _Japan_
_kInstitute_ _for_ _Solid_ _State_ _Physics,_ _University_ _of_ _Tokyo,_ _Kashiwa_ _277-8581,_ _Japan_
Abstract
The open source ALPS (Algorithms and Libraries for Physics Simulations) project provides a collection of physics libraries and applications, with a focus on simulations of
lattice models and strongly correlated systems. The libraries provide a convenient set
of well-documented and reusable components for developing condensed matter physics
simulation code, and the applications strive to make commonly used and proven computational algorithms available to a non-expert community. In this paper we present an
updated and refactored version of the core ALPS libraries geared at the computational
physics software development community, rewritten with focus on documentation, ease
of installation, and software maintainability.
PROGRAM SUMMARY
_Program_ _Title:_ ALPS Core libraries
_Project_ _homepage:_ http://alpscore.org
_Catalogue_ _identifier:_ _Journal_ _Reference:_ _Operating_ _system:_ Unix, Linux, OSX
_Programming_ _language:_ `C++`
_Computers:_ any architecture with suitable compilers including PCs, clusters and supercomputers
_RAM:_ Highly problem-dependent
_Distribution_ _format:_ GitHub, downloadable as zip
_Licensing_ _provisions:_ GNU General Public License
_Classification:_ 6.5, 7.3, 20
_∗_ Corresponding author.
_Email_ _address:_ `galexv@umich.edu` (A. Gaenko)
_Preprint_ _submitted_ _to_ _Computer_ _Physics_ _Communications_ _December_ _16,_ _2016_
_Keywords:_ Many-body physics, Strongly correlated systems, Monte Carlo, C++, High Performance Computing
_External_ _routines/libraries:_ `CMake`, `MPI`, `Boost`, `HDF5` .
_Nature_ _of_ _problem:_ Need for modern, lightweight, tested and documented libraries covering
the basic requirements of rapid development of efficient physics simulation codes, especially for
modeling strongly correlated electron systems.
_Solution_ _method:_
We present a `C++` open source computational library that provides a convenient set of components for developing parallel physics simulation code. The library features a short development
cycle and up-to-date user documentation.
_Running_ _time:_ Tests take of the order of several minutes; Otherwise highly problem dependent
(from minutes to several days).
1. Introduction
The open source ALPS (Algorithms and Libraries for Physics Simulations) project
[1, 2, 3] provides a collection of physics libraries and applications, especially suited for
the simulation of lattice models and strongly correlated systems. The ALPS libraries
provide well-documented, reusable components for developing condensed matter physics
simulation code, while ALPS applications’ goal is to make commonly used and proven
computational algorithms available to a non-expert community.
Computer codes based on the ALPS libraries have provided physical insights in
many subfields of condensed matter. Highlights include nonequilibrium dynamics [4, 5],
continuous-time quantum Monte Carlo [6, 7], LDA+DMFT materials simulations [8],
simulations of quantum [9] and classical [10] spin, correlated boson [11] and fermion [12]
models, as well as cuprate superconductivity [13].
In this paper we present an updated and refactored version of the main ALPS Libraries (here and thereafter referred to as “ALPS core libraries” or, as a whole, “the
library”). The focus of the update is on providing a set of lightweight, thoroughly tested
and documented libraries to code developers that implement generic algorithms and utilities for rapid development of efficient computational physics applications. Substantial
portions of the code are significantly rewritten compared to the previous version of the
ALPS Libraries, and special emphasis is placed on a short development cycle and up-todate user documentation.
A snapshot of the code at the time of submission of this paper is available at
the CPC program library. Later versions will be available from the main site, `[http:](http://alpscore.org)`
`[//alpscore.org](http://alpscore.org)`, together with in-depth user documentation, tutorials, and examples.
Development versions of the library are available from the public `Git` repository at
`[https://github.com/ALPSCore/ALPSCore](https://github.com/ALPSCore/ALPSCore)` . Several application codes are built on the
core libraries and are distributed independently.
The remainder of this paper is organized as follows: In section 2 we introduce and
motivate the library; in section 3, we provide an overview of the library components;
in section 4, we list the software packages prerequisite for compiling and installing the
library, as well as outline the installation procedure; in section 5, we describe the development and testing cycle of the library; in section 6 we specify the ALPS citation policy
and license, and in sections 7 and 8 we summarize the paper and acknowledge our contributors. Additionally, Appendix A provides installation examples and Appendix B an
2
example of code using the library to program a two-dimensional Ising model simulation
with single spin flip updates.
2. Motivation, target audience, philosophy
Our library is intended to be used by two communities: directly by computational
physicists who develop their own computer codes, and indirectly by users who use applications based on the library. There are a number of challenges that such a scientific
developer faces:
_Framework/boilerplate_ _code._ A typical computational physics program (for example, a
Monte Carlo simulation code) contains parts that have little to do with the scientific
problem that the simulation strives to get insight into. Those parts form the necessary
framework for running the simulation, and are responsible for various auxiliary tasks
such as reading the parameters of the simulation or saving intermediate and final results.
Auxiliary ‘boilerplate’ code is often imported with little or no changes from application to
application. As writing the auxiliary code is secondary to solving the scientific problem
at hand, it is therefore given less attention. However, the auxiliary code is not necessarily
trivial and redeveloping it from scratch results in unnecessary duplication of effort and
reduced code quality.
_Code reuse problem._ For the same reasons, physics code often lacks modularization: parts
of the code are not properly separated by well-defined interfaces, and the scientific code
is buried deep inside the boilerplate/framework. The resulting lack of interoperability
hinders the exchange of code with other research groups and results in further unnecessary
duplication of effort.
_Process management._ As codes grow, they become progressively more difficult to manage
and document. The lack of modularity and documentation makes it hard for researchers
outside the primary developers group to contribute to the project. A possibility of unintentional disruption of code functionality by introducing changes effectively discourages
implementing new features.
_High_ _performance_ _computing_ _requirements._ Although programming in a high-level language (such as `Python` ) may help in solving the framework/boilerplate code problem,
the use of a high-level language is often problematic. Computational physics algorithms
are complex, and the computational kernels implementing them are resource-demanding
and in most of the cases must make use of multi-node and multi-core capabilities of
contemporary HPC (High Performance Computing) hardware. The high-performance
requirements necessitate implementation of the kernels in a lower-level language, such as
`C++`, and utilizing `MPI` and `OpenMP` parallel programming techniques. The task of including high-performance parallelized kernels into high-level language framework, although
technically feasible, is far from being trivial.
The purpose of the ALPS core libraries is to reduce the user’s time and effort to
develop and test complex scientific applications. This project addresses the abovementioned challenges by providing reusable and widely-used, high-performance, well
3
documented software building blocks with open architecture. To facilitate reuse, the library utilizes high level of abstraction without compromising performance. To encourage
reuse and contributions, the library strives to maintain current user-level and developerlevel documentation, easy installation procedure, as well as a short development cycle
with rapid bugfixes and frequent releases. The manageability requirements are addressed
via documented code, modular structure, and extensive testing. The project is open to
contributions in the form of bug reports, feature requests, and code.
3. Some of the key library components
In this section, we provide a brief overview of the purpose and functionality of some
of the key components comprising the ALPS core libraries. Additional information is
available online and as part of the `Doxygen` code documentation. It should be noted
that the components maintain minimal interdependence, and using a component in a
program does not bring in other components, unless they are required dependencies, in
which case they will be used automatically.
_Building_ _a_ _parallel_ _Monte_ _Carlo_ _simulation._ A generic Monte Carlo simulation can be
easily assembled from the classes provided by _Monte_ _Carlo_ _Scheduler_ component. The
programmer needs to define only the problem-specific methods that are called at each
Monte Carlo step, such as methods to update the configuration of the Monte Carlo chain
and to collect the measured data. The simulation is parallelized implicitly, using one `MPI`
process per chain. Appendix B contains an example of a Monte Carlo simulation using
these Scheduler classes.
_Computing_ _observable_ _averages,_ _errors,_ _correlation_ _times,_ _and_ _cross-correlation._ To collect Monte Carlo simulation data and to estimate and propagate Monte Carlo errors of
potentially correlated data, the _Accumulators_ library component is to be used, especially
in cases where correlations in time or cross-correlations between different variables exist.
The Accumulator objects support arithmetic operations and elementary mathematical
functions, e.g. division of one observable by another or the multiplication of two observables. The non-linear error propagation through these operations is also supported.
Several Accumulator objects provide different trade-offs between memory consumption, overhead time, and functionality. In order of decreasing memory and measurement
requirements they are:
1. `FullBinningAccumulator` : provides access to data autocorrelation length, autocorrelation-corrected error bars, and proper error propagation in non-linear functions using Jackknife [14] resampling technique.
2. `LogBinningAccumulator` : provides access to data autocorrelation estimates and
autocorrelation-corrected error bars.
3. `NoBinningAccumulator` : estimates the error bars of the data without regard to
autocorrelation.
4. `MeanAccumulator` : maintains only the mean value of the data (no error bars or
autocorrelation length).
A typical use of accumulators in a Monte Carlo simulation is demonstrated
in Appendix B.
4
_Storing,_ _restoring,_ _and_ _checkpointing_ _simulation_ _results._ To store the results of a simulation in a cross-platform format for subsequent analysis, one can use the _Archive_ component. The component provides convenient interface to saving and loading of common `C++`
data structures (primitive types, complex numbers, STL vectors and maps), as well as of
objects of user-defined classes `HDF5` [15], which is the universally supported and machine
independent data format. Use of the Archive component for application checkpointing
is illustrated in Appendix B.
_Reading_ _command-line_ _arguments_ _and_ _parameter_ _files._ Input parameters to a simulation
can be passed via a combination of a parameter file and command line arguments. The
_Parameters_ library component is responsible for parsing the files and the command line,
and providing access to the data in the form of an associative array (akin to `C++` `map` or
`Python` dictionary). The parameter files use the standard “ `*.ini` ” format, a plain text
format with a line-based syntax containing `key` `=` `value` pairs, optionally divided into
sections. The use of the Parameters component is illustrated in Appendix B.
_Working_ _with_ _Green’s_ _functions._ The _Green’s_ _Functions_ component provides a type-safe
interface to manipulate objects representing bosonic or fermionic many-body Green’s
functions, self-energies, susceptibilities, polarization functions, and similar objects. From
a programmer’s perspective, these objects are multidimensional arrays of floating-point
or complex numbers, defined over a set of meshes and addressable by a tuple of indices,
each belonging to a grid. Currently, Matsubara (imaginary frequency), imaginary time,
power, momentum space, real space, and arbitrary index meshes are supported.
These many-body objects often need to be supplemented with analytic tail information encapsulating the high frequency / small time moments of the Green’s functions,
so that high precision Fourier transforms, density evaluations, or energy evaluations can
be performed. The Green’s function library component provides this functionality in
addition to saving to and loading from binary `HDF5` files. An example illustrating the use
of the Green’s function classes is given in Appendix C.
4. Prerequisites and Installation
To build the ALPS core libraries, any recent `C++` compiler can be used; the libraries
are tested with `GCC` [16] 4.2 and above, Intel [17] `C++` 10.0 and above, and Clang [18] 3.2
and above. The library follows the `C++` 03 standard [19] to facilitate the portability to a
wide range of programming environments, including HPC clusters with older compilers.
The library depends on the following external packages:
- The `CMake` build system [20] of version 2.8.12 and above.
- The `Boost` `C++` libraries [21] of version 1.54.0 and above. Compiled libraries are
only needed from the program option, serialization, and file system libraries.
- The `HDF5` library [15] version 1.8 and above.
To make use of (optional) parallel capabilities, an `MPI` implementation supporting standard 2.1 [22] and above is required. Generating the developer’s documentation requires
`Doxygen` [23] along with its dependencies.
5
The installation of the ALPS core libraries follows the standard procedure for any
`CMake` -based package. The first step is to download the ALPS core libraries source
code; the recommended way is to download the latest ALPS core libraries release
from `[https://github.com/ALPSCore/ALPSCore/releases](https://github.com/ALPSCore/ALPSCore/releases)` . Assuming that all abovementioned prerequisite software is installed, the installation consists of unpacking the
release archive and running `CMake` from a temporary build directory, as outlined in the
shell session example below (the `$` sign designates a shell prompt):
`$` `tar` `-xzf` `ALPSCore -0.5.4. tar.gz` 1
`$` `mkdir` `build` 2
`$` `cd` `build` 3
`$` `export` `ALPSCore_DIR =` `$HOME/software/ALPSCore` 4
`$` `cmake` `-DCMAKE_INSTALL_PREFIX = $ALPSCore_DIR` `\` 5
`-DCMAKE_BUILD_TYPE =Release` `\` 6
`../ ALPSCore -0.5.4` 7
`$` `make` 8
`$` `make` `test` 9
`../ ALPSCore -0.5.4` 7
`$` `make` `install` 10
The command at line 1 unpacks the release archive (version 0.5.4 in this example); at line 4 the destination install directory of the ALPS core libraries is set
( `$HOME/software/ALPSCore` in this example).
The ALPS core libraries come with an extensive set of tests; it is strongly recommended to run the tests (via `make` `test` ) to verify the correctness of the build, as it is
done at line 9 in the example above.
The installation procedure is outlined in more details in Appendix A; also, the file
`common/build/build.jenkins.sh` in the library release source tree contains a build and
installation script that can be further consulted for various build options.
On Mac OS X operating system, the ALPS core libraries package can be downloaded and installed from the `MacPorts` [24] or
`HomeBrew` [25] repositories, using commands `port` `install` `alpscore` or
`brew` `tap` `homebrew/science` `&&` `brew` `install` `alpscore`, respectively.
5. Development and Test Cycle
The ALPS core libraries development emphasizes a short development cycle and frequent releases of operational code, along with user-level and programmer-level documentation. The techniques we employ to achieve these goals are discussed below.
_5.1._ _Distributed_ _version_ _control_ _and_ _collaborative_ _development_
In accordance with modern software practices, all changes introduced in the course
of development of ALPS core libraries are tracked using a distributed version control
system, `Git` [26]. The version control system preserves the history of changes in every
source file in its database (the `Git` repository), associating each change (a “commit”) with
its originator, and allows the author to comment on each set of changes. The version
control system allows one to create independent lines of code development (branches),
with subsequent optional merging of those lines.
The master version of the repository with ALPS core libraries, which is publicly available for downloading, is hosted on the GitHub [27] hosting service. The distributed nature of `Git` allows any developer to work independently on his or her own copy (“clone”)
of the repository, and then request to merge his or her clone into this publicly-visible
6
repository (submit a “pull request”); after reviewing the code changes that the developer
made, the request is granted by one of the members of the core development team.
In addition to the repository, GitHub provides an issue tracker. Any registered
GitHub user is able to submit a question, a bug report or a feature request via the
tracking system. The developer team is notified that a new issue is open and then
triages the issue, marking it according to its severity (for example, “bug”, “enhancement”, “question”); assigns a developer to be responsible for it; and associates a code
development “milestone” with it. The issue can be further commented on by other users
and developers, creating a thread of conversation. Once the issue is resolved or otherwise
addressed, it is marked as “closed”.
GitHub also provides hosting space for Wiki pages, which the project uses for userlevel documentation and tutorials. The Wiki documentation contains direct links to
repository code, and thus simplifies keeping the code samples up to date. The ALPS
core libraries project encourages collaboration and feedback from the user community by
opening issues, submitting pull requests, and contributing to the Wiki documentation
pages.
_5.2._ _Test-driven_ _development_ _and_ _continuous_ _integration_
Test-driven development (TDD) is a software development process that emphasizes
creating a test for a feature prior to implementing it. Among the advantages of TDD
are increased test coverage (because every new feature has a corresponding test), higher
confidence in test validity (because the test is ensured to fail on unimplemented feature)
and improved code quality [28]. We follow the TDD process in the development of the
ALPS core libraries, whenever practical.
Typically, each test verifies the behavior of a single function or object method in
isolation from other methods of the same class; this approach is known as “unit testing”.
However, many components of ALPS core libraries depend on functionality provided by
other components (for example, Monte Carlo scheduler uses Accumulators and Parameters). In this way, a unit test of an object method provided by a component tests the
coordinated working of the component’s dependencies, and can be considered a form
of integration test. It should also be noted that only publicly accessible (rather than
private) methods are invoked in testing. In our development process, a unit tests is also
a form of documentation, demonstrating both the correct way to call a method and the
interface specification.
In order to avoid maintenance problems associated with merging several branches
of development and possible breaking of code functionality, the ALPS core libraries
development adopted the Continuous Integration [29] practice. Continuous Integration
prescribes frequent merging of the code into the main repository and running tests (in our
case, the unit/integration test suite) to make sure that the code functions as expected.
To build the code and run the test suite we utilize the Jenkins Continuous Integration
tool [30]. In order to conduct unit and integration testing of the ALPS core libraries on
wider range of operating environments, we make use of a cloud-based service (provided
by CloudBees [31]). When a developer merges his or her series of commits into the central
repository, an automated upload to the cloud-based service occurs, followed by building of
the library and running the test suites in different environments, under different operating
systems (Linux and Mac OS X) and using various versions of compilers and libraries. The
test results are immediately available for developers to analyze and correct any errors.
7
The same build process also generates developer-level documentation from documenting
comments embedded in the code.
Once all outstanding issues are resolved, new features are implemented or existing
ones are improved, and the test suites are passed in all supported environments, a developer requests GitHub to generate a release. By virtue of the Continuous Integration
process, the code in repository at that stage is ensured to be free of known issues; therefore, the release is essentially a compressed archive of the snapshot of the repository,
ready to be installed and deployed. When the state of the repository is marked as a release, a request is automatically sent to the Zenodo [32] service to download and archive
the release in Zenodo’s searchable database; Zenodo also generates a citable DOI code
associated with the release. The complete development and test cycle of the ALPS core
libraries project, discussed above, is illustrated by Figure 1.
Figure 1: Development cycle of ALPS core libraries. Developer’s commit to public
GitHub repository causes automatic rebuild on CloudBees service via Jenkins. Releases
are automatically published on Zenodo.
6. License and citation policy
The GitHub version of ALPS core libraries is licensed under the GNU General Public
License version 2 (GPL v. 2) [33] or later; for compatibility reasons with the journal the
version released here is licensed under GPL v. 3. The older ALPS license under which
previous versions of the code were licensed [3] has been retired. We kindly request that
the present paper be cited, along with any relevant original physics or algorithmic paper,
in any published work utilizing an application code that uses this library.
7. Summary
We have presented an updated and repackaged version of the core ALPS libraries, a
lightweight `C++` library, designed to facilitate rapid development of computational physics
8
applications, and have described its main features. The collaborative, test-driven development process utilizing the continuous integration approach has been also described.
8. Acknowledgments
Work on the ALPS library project is supported by the Simons collaboration on the
many-electron problem. Aspects of the library are supported by NSF DMR-1606348 and
DOE ER 46932.
9. References
References
[1] F. Alet, P. Dayal, A. Grzesik, A. Honecker, M. Krner, A. Luchli, S. R. Manmana, I. P. Mc
Culloch, F. Michel, R. M. Noack, G. Schmid, U. Schollwck, F. Stckli, S. Todo, S. Trebst,
M. Troyer, P. Werner, S. Wessel, The ALPS project: Open [source](http://dx.doi.org/10.1143/JPSJS.74S.30) software for strongly correlated [systems,](http://dx.doi.org/10.1143/JPSJS.74S.30) Journal of the Physical Society of Japan 74 (Suppl) (2005) 30–35. `[arXiv:http:](http://arxiv.org/abs/http://dx.doi.org/10.1143/JPSJS.74S.30)`
`[//dx.doi.org/10.1143/JPSJS.74S.30](http://arxiv.org/abs/http://dx.doi.org/10.1143/JPSJS.74S.30)`, `[doi:10.1143/JPSJS.74S.30](http://dx.doi.org/10.1143/JPSJS.74S.30)` .
URL `[http://dx.doi.org/10.1143/JPSJS.74S.30](http://dx.doi.org/10.1143/JPSJS.74S.30)`
[2] A. Albuquerque, F. Alet, P. Corboz, P. Dayal, A. Feiguin, S. Fuchs, L. Gamper, E. Gull, S. Grtler,
A. Honecker, R. Igarashi, M. Krner, A. Kozhevnikov, A. Luchli, S. Manmana, M. Matsumoto,
I. McCulloch, F. Michel, R. Noack, G. Pawowski, L. Pollet, T. Pruschke, U. Schollwck, S. Todo,
S. Trebst, M. Troyer, P. Werner, S. Wessel, [The ALPS project release 1.3:](http://www.sciencedirect.com/science/article/pii/S0304885306014983) Open-source software for
strongly [correlated](http://www.sciencedirect.com/science/article/pii/S0304885306014983) systems, Journal of Magnetism and Magnetic Materials 310 (2, Part 2) (2007)
1187 - 1193, proceedings of the 17th International Conference on MagnetismThe International
Conference on Magnetism. `[doi:http://dx.doi.org/10.1016/j.jmmm.2006.10.304](http://dx.doi.org/http://dx.doi.org/10.1016/j.jmmm.2006.10.304)` .
URL `[http://www.sciencedirect.com/science/article/pii/S0304885306014983](http://www.sciencedirect.com/science/article/pii/S0304885306014983)`
[3] B. Bauer, L. D. Carr, H. G. Evertz, A. Feiguin, J. Freire, S. Fuchs, L. Gamper, J. Gukelberger,
E. Gull, S. Guertler, A. Hehn, R. Igarashi, S. V. Isakov, D. Koop, P. N. Ma, P. Mates, H. Matsuo,
O. Parcollet, G. Pawowski, J. D. Picon, L. Pollet, E. Santos, V. W. Scarola, U. Schollw¨ock, C. Silva,
[B. Surer, S. Todo, S. Trebst, M. Troyer, M. L. Wall, P. Werner, S. Wessel, The ALPS project release](http://stacks.iop.org/1742-5468/2011/i=05/a=P05001)
2.0: open source software [for](http://stacks.iop.org/1742-5468/2011/i=05/a=P05001) strongly correlated systems, Journal of Statistical Mechanics: Theory
and Experiment 2011 (05) (2011) P05001.
URL `[http://stacks.iop.org/1742-5468/2011/i=05/a=P05001](http://stacks.iop.org/1742-5468/2011/i=05/a=P05001)`
[4] M. Eckstein, M. Kollar, P. Werner, Thermalization after an [interaction](http://link.aps.org/doi/10.1103/PhysRevLett.103.056403) quench in the Hubbard
[model,](http://link.aps.org/doi/10.1103/PhysRevLett.103.056403) Phys. Rev. Lett. 103 (2009) 056403. `[doi:10.1103/PhysRevLett.103.056403](http://dx.doi.org/10.1103/PhysRevLett.103.056403)` .
URL `[http://link.aps.org/doi/10.1103/PhysRevLett.103.056403](http://link.aps.org/doi/10.1103/PhysRevLett.103.056403)`
[5] P. Werner, T. Oka, A. J. Millis, Diagrammatic Monte Carlo [simulation](http://link.aps.org/doi/10.1103/PhysRevB.79.035320) of nonequilibrium systems,
Phys. Rev. B 79 (2009) 035320. `[doi:10.1103/PhysRevB.79.035320](http://dx.doi.org/10.1103/PhysRevB.79.035320)` .
URL `[http://link.aps.org/doi/10.1103/PhysRevB.79.035320](http://link.aps.org/doi/10.1103/PhysRevB.79.035320)`
[6] P. Werner, A. Comanac, L. de’ Medici, M. Troyer, A. J. Millis, Continuous-time [solver](http://link.aps.org/doi/10.1103/PhysRevLett.97.076405) for quantum
[impurity](http://link.aps.org/doi/10.1103/PhysRevLett.97.076405) models, Phys. Rev. Lett. 97 (2006) 076405. `[doi:10.1103/PhysRevLett.97.076405](http://dx.doi.org/10.1103/PhysRevLett.97.076405)` .
URL `[http://link.aps.org/doi/10.1103/PhysRevLett.97.076405](http://link.aps.org/doi/10.1103/PhysRevLett.97.076405)`
[7] E. Gull, P. Werner, O. Parcollet, M. Troyer, Continuous-time [auxiliary-field](http://stacks.iop.org/0295-5075/82/i=5/a=57003) Monte Carlo for quan
tum [impurity](http://stacks.iop.org/0295-5075/82/i=5/a=57003) models, EPL (Europhysics Letters) 82 (5) (2008) 57003.
URL `[http://stacks.iop.org/0295-5075/82/i=5/a=57003](http://stacks.iop.org/0295-5075/82/i=5/a=57003)`
[8] [J. Ferber, K. Foyevtsova, R. Valent´ı, H. O. Jeschke, LDA + DMFT study of the effects of correlation](http://link.aps.org/doi/10.1103/PhysRevB.85.094505)
in [LiFeAs,](http://link.aps.org/doi/10.1103/PhysRevB.85.094505) Phys. Rev. B 85 (2012) 094505. `[doi:10.1103/PhysRevB.85.094505](http://dx.doi.org/10.1103/PhysRevB.85.094505)` .
URL `[http://link.aps.org/doi/10.1103/PhysRevB.85.094505](http://link.aps.org/doi/10.1103/PhysRevB.85.094505)`
[9] E. Cremades, S. Gmez-Coca, D. Aravena, S. Alvarez, E. Ruiz, Theoretical [study](http://dx.doi.org/10.1021/ja302851n) of exchange
coupling in 3d-Gd complexes: [Large magnetocaloric effect systems,](http://dx.doi.org/10.1021/ja302851n) Journal of the American Chemical Society 134 (25) (2012) 10532–10542, pMID: 22640027. `[arXiv:http://dx.doi.org/10.1021/](http://arxiv.org/abs/http://dx.doi.org/10.1021/ja302851n)`
`[ja302851n](http://arxiv.org/abs/http://dx.doi.org/10.1021/ja302851n)`, `[doi:10.1021/ja302851n](http://dx.doi.org/10.1021/ja302851n)` .
URL `[http://dx.doi.org/10.1021/ja302851n](http://dx.doi.org/10.1021/ja302851n)`
9
[10] D. Bergman, J. Alicea, E. Gull, S. Trebst, L. Balents, Order-by-disorder [and](http://dx.doi.org/10.1038/nphys622) spiral spin-liquid in
frustrated [diamond-lattice](http://dx.doi.org/10.1038/nphys622) antiferromagnets, Nat Phys 3 (7) (2007) 487–491.
URL `[http://dx.doi.org/10.1038/nphys622](http://dx.doi.org/10.1038/nphys622)`
[11] L. Pollet, J. D. Picon, H. P. B¨uchler, M. Troyer, Supersolid phase with [cold](http://link.aps.org/doi/10.1103/PhysRevLett.104.125302) polar molecules on a
[triangular](http://link.aps.org/doi/10.1103/PhysRevLett.104.125302) lattice, Phys. Rev. Lett. 104 (2010) 125302. `[doi:10.1103/PhysRevLett.104.125302](http://dx.doi.org/10.1103/PhysRevLett.104.125302)` .
URL `[http://link.aps.org/doi/10.1103/PhysRevLett.104.125302](http://link.aps.org/doi/10.1103/PhysRevLett.104.125302)`
[12] J. P. F. LeBlanc, A. E. Antipov, F. Becca, I. W. Bulik, G. K.-L. Chan, C.-M. Chung, Y. Deng,
M. Ferrero, T. M. Henderson, C. A. Jim´enez-Hoyos, E. Kozik, X.-W. Liu, A. J. Millis, N. V.
Prokof’ev, M. Qin, G. E. Scuseria, H. Shi, B. V. Svistunov, L. F. Tocchio, I. S. Tupitsyn, S. R.
White, S. Zhang, B.-X. Zheng, Z. Zhu, E. Gull, Solutions of the [two-dimensional](http://link.aps.org/doi/10.1103/PhysRevX.5.041041) Hubbard model:
Benchmarks and results from a [wide](http://link.aps.org/doi/10.1103/PhysRevX.5.041041) range of numerical algorithms, Phys. Rev. X 5 (2015) 041041.
`[doi:10.1103/PhysRevX.5.041041](http://dx.doi.org/10.1103/PhysRevX.5.041041)` .
URL `[http://link.aps.org/doi/10.1103/PhysRevX.5.041041](http://link.aps.org/doi/10.1103/PhysRevX.5.041041)`
[13] E. Gull, O. Parcollet, A. J. Millis, Superconductivity and the [pseudogap](http://link.aps.org/doi/10.1103/PhysRevLett.110.216405) in the two-dimensional
[Hubbard](http://link.aps.org/doi/10.1103/PhysRevLett.110.216405) model, Phys. Rev. Lett. 110 (2013) 216405. `[doi:10.1103/PhysRevLett.110.216405](http://dx.doi.org/10.1103/PhysRevLett.110.216405)` .
URL `[http://link.aps.org/doi/10.1103/PhysRevLett.110.216405](http://link.aps.org/doi/10.1103/PhysRevLett.110.216405)`
[14] R. G. Miller, The [Jackknife—a](http://www.jstor.org/stable/2334280) review, Biometrika 61 (1) (1974) 1–15.
URL `[http://www.jstor.org/stable/2334280](http://www.jstor.org/stable/2334280)`
[15] The HDF Group. [Hierarchical Data Format,](http://www.hdfgroup.org/HDF5/) version 5 [online] (1997–2016). `[http://www.hdfgroup.](http://www.hdfgroup.org/HDF5/)`
`[org/HDF5/](http://www.hdfgroup.org/HDF5/)` .
[16] [R. M. Stallman, the GCC Developer Community, Using the GNU Compiler Collection (1988–2016).](https://gcc.gnu.org/onlinedocs/gcc-6.1.0/gcc.pdf)
URL `[https://gcc.gnu.org/onlinedocs/gcc-6.1.0/gcc.pdf](https://gcc.gnu.org/onlinedocs/gcc-6.1.0/gcc.pdf)`
[17] Intel Corporation, User and Reference Guide for the Intel C++ Compiler 15.0 (2015).
URL `[https://software.intel.com/en-us/compiler_15.0_ug_c](https://software.intel.com/en-us/compiler_15.0_ug_c)`
[18] clang: a C language [family](http://clang.llvm.org/) frontend for LLVM [online] (2016). `[http://clang.llvm.org/](http://clang.llvm.org/)` .
[19] Programming languages - C++, Standard ISO/IEC 14882:2003, International Organization for
Standardization, Geneva, CH (Oct. 2003).
[20] K. Martin, B. Hoffman, Mastering CMake, Kitware, Inc, 2015.
[21] Boost [software](http://www.boost.org/) libraries [online] (2016). `[http://www.boost.org/](http://www.boost.org/)` .
[22] Message Passing Interface Forum, MPI: A Message-Passing Interface Standard, Version 2.1, High
Performance Computing Center Stuttgart (HLRS), 2008, https://www.mpi-forum.org/docs/mpi2.1/mpi21-report.pdf.
[23] D. van Heesch. [Doxygen](http://www.doxygen.org/) [online] (1997–2015). `[http://www.doxygen.org/](http://www.doxygen.org/)` .
[24] The MacPorts Project. [Macports](http://www.macports.org/) [online] (2007–2014). `[http://www.macports.org/](http://www.macports.org/)` .
[25] The HomeBrew Project. [HomeBrew](http://www.brew.sh/) [online] (2009–2016). `[http://www.brew.sh/](http://www.brew.sh/)` .
[26] [Git](http://git-scm.com/) [online] (2009–2016). `[http://git-scm.com/](http://git-scm.com/)` .
[27] [github](http://github.com/) [online]. `[http://github.com/](http://github.com/)` .
[28] K. Beck, Test-driven Development: By Example, Addison-Wesley Professional, 2003.
[29] K. Beck, C. Andres, Extreme Programming Explained: Embrace Change, Addison-Wesley Profes
sional, 2004, Ch. Development Strategy, p. 97.
[30] [Jenkins](http://jenkins.io/) [online]. `[http://jenkins.io/](http://jenkins.io/)` .
[31] [cloudbees](http://www.cloudbees.com/) [online]. `[http://www.cloudbees.com/](http://www.cloudbees.com/)` .
[32] [Zenodo](http://zenodo.org/) [online]. `[http://zenodo.org/](http://zenodo.org/)` .
[33] GNU general public license.
URL `[http://www.gnu.org/licenses/gpl.html](http://www.gnu.org/licenses/gpl.html)`
Appendix A. Detailed installation procedure
In the following discussion we assume that all prerequisite software (section 4) is
installed, and the ALPS core libraries release (here, release 0.5.4) is downloaded into
the current directory as `ALPSCore-0.5.4.tar.gz` . Also, we assume that the libraries
are to be installed in `ALPSCore` subdirectory of the current user’s home directory. The
commands are given assuming `bash` as a user shell.
The first step is to unpack the release archive and set the desired install directory:
`$` `tar` `-xzf` `ALPSCore -0.5.4.tar.gz` 1
`$` `export` `ALPSCore_DIR =` `$HOME/software/ALPSCore` 2
10
The next step is to perform the build of the library (note that the build should not
be performed in the source directory):
`$` `mkdir` `build` 3
`$` `cd` `build` 4
`$` `cmake` `../ ALPSCore -0.5.4` `-DCMAKE_INSTALL_PREFIX = $ALPSCore_DIR` `\` 5
`-DCMAKE_BUILD_TYPE =Release` 6
The `cmake` command at lines 5 and 6 accepts additional arguments in the format
`-D` _`variable`_ `=` _`value`_ . A number of relevant `CMake` variables is listed in Table A.1. The
installation process is also affected by environment variables, some of which are listed in
Table A.2; the `CMake` variables take precedence over the environment variables. The build
and installation script `common/build/build.jenkins.sh` in the ALPS core libraries release source tree provides an example of using some of the build options.
Appendix B. Example: 2D Ising model
_Appendix_ _B.1._ _Problem_ _statement_
This program implements a single-spin update Metropolis Monte Carlo algorithm for
computing properties of a well-known two-dimensional Ising model. The system under
consideration is a square lattice of spins _{si_ = _±_ 1 _}_ ; the periodic boundary conditions
are imposed, with a unit cell of size _L × L_, containing _N_ = _L_ <sup>2</sup> spins. The energy per
spin is given by
_E_ = _−_ <sup><u>1</u></sup>
_N_
( _i,j_ )
_sisj_ (B.1)
where ( _i, j_ ) runs over all nearest-neighbor pairs in the unit cell. The magnetization per
spin is given by
_M_ = <sup><u>1</u></sup>
_N_
_i_
_si_ (B.2)
where _i_ runs over all _N_ = _L_ <sup>2</sup> spins in the unit cell.
The properties of interest are thermal averages of energy _⟨E⟩_, magnetization _⟨M_ _⟩_,
absolute value of magnetization _⟨|M_ _|⟩_ and Binder cumulant:
_<u>⟨M</u>_ <sup>4</sup> _<u>⟩</u>_
_U_ = 1 _−_ (B.3)
3 _⟨M_ <sup>2</sup> _⟩_ <sup>2</sup>
computed at temperature _T_ (inverse temperature _β_ = 1 _/T_ ) expressed in energy units.
_Appendix_ _B.2._ _Build_ _process_
The build of the example program is controlled by the `CMakeLists.txt` file given by
the Listing 1.
Listing 1 : CMakeLists.txt file
`cmake_minimum_required (VERSION` `2.8.12)` 1
`project` `(ising2_mc` `CXX)` 2
3
`add_executable (` `$` `{ PROJECT_NAME }` `main.cpp` `ising.cpp)` 4
`add_executable (` `$` `{ PROJECT_NAME }_mpi` `main_mpi.cpp` `ising.cpp)` 5
6
11
<u>Variable</u> <u>Default</u> <u>value</u> <u>Comment</u>
`CMAKE` ~~`C`~~ `XX` ~~`C`~~ `OMPILER` (system default) Path to `C++` compiler executable.*
`CMAKE` ~~`I`~~ `NSTALL` ~~`P`~~ `REFIX` `/usr/local` library target install directory.
`CMAKE` ~~`B`~~ `UILD` ~~`T`~~ `YPE` Specifies build type; set to `Release` to
maximize performance.
`BOOST` ~~`R`~~ `OOT` `Boost` install directory. Set if `CMake`
fails to find `Boost` .
`Boost` ~~`N`~~ `O` ~~`S`~~ `YSTEM` `PATHS` `false` Set to `true` to disable search in default
system directories, if the wrong version
of `Boost` is found.
`Boost` ~~`N`~~ `O` ~~`B`~~ `OOST` ~~`C`~~ `MAKE` `false` Set to `true` to disable search for `Boost`
`CMake` file, if the wrong version of
`Boost` is found.
`Documentation` `ON` Build developer’s documentation.
`ENABLE` `MPI` `ON` Enable `MPI` build (set to `OFF` to
disable).
`Testing` `ON` Build unit tests (recommended).
`ALPS` ~~`B`~~ `UILD` ~~`T`~~ `YPE` `dynamic` Can be `dynamic` or `static` : build
libraries as dynamic (“shared”) or
static libraries, respectively.* _(Since_
_ALPSCore_ _0.5.5)_
_For_ _ALPSCore_ _version_ _0.5.4_ _and_ _older:_
`ALPS` ~~`B`~~ `UILD` ~~`S`~~ `HARED` `ON` Build shared ALPS core libraries.*
Mutually exclusive with
`ALPS` ~~`B`~~ `UILD` `STATIC=ON` .
`ALPS` ~~`B`~~ `UILD` ~~`S`~~ `TATIC` `OFF` Build static ALPS core libraries.*
Mutually exclusive with
`ALPS` ~~`B`~~ `UILD` `SHARED=ON` .
*Note: For the change of this variable to take effect, remove your build directory and redo the build.
Table A.1: `CMake` arguments relevant to building of ALPS core libraries.
<u>Variable</u> <u>Comment</u>
`CXX` Path to `C++` compiler executable.*
`BOOST` ~~`R`~~ `OOT` `Boost` install directory. Set if `CMake` fails to find `Boost` .
`HDF5` ~~`R`~~ `OOT` `HDF5` install directory. Set if `CMake` fails to find `HDF5` .
*Note: For the change of this variable to take effect, remove your build directory and redo the build.
Table A.2: Environment variables arguments relevant to building of ALPS core libraries.
12
`#` `Request` `the` `ALPSCore` `package` `(with` `all` `components )` 7
`#` `The` `ALPSCore` `package` `must` `be` `installed` `in` `some` 8
`#` `standard` `place` `(like` `/usr/local),` 9
`#` `or` `somewhere` `in` `your` `PATH.` 10
`#` `Otherwise,` `point` `ALPSCore_DIR` `environment` `variable` 11
`#` `to` `the` `ALPScore` `installation` `tree.` 12
`find_package (ALPSCore` `REQUIRED)` 13
14
`#` `Use` `ALPSCore_LIBRARIES` `variable` `to` `link` `to` `ALPSCore` 15
`target_link_libraries (` `$` `{ PROJECT_NAME }` `$` `{ ALPSCore_LIBRARIES })` 16
`target_link_libraries (` `$` `{ PROJECT_NAME }_mpi` `$` `{ ALPSCore_LIBRARIES })` 17
Lines 4 and 5 specify the source files that constitute the sequential and parallel versions of the program, respectively. Line 13 requests the ALPS core libraries (ALPSCore)
package that must be installed as described in section Appendix A; the installation
location must be in one of standard system directories such as `/usr/local`, in one of
the directories listed in the `PATH` environment variable, or in a directory pointed to by
`ALPSCore_DIR` environment variable. Lines 16 and 17 specify that the sequential and
parallel versions of the program use libraries provided by the ALPSCore package.
Assuming that the ALPS core libraries are installed as described above, the example
code is located in _/path/to/source_ directory, and the project is to be built in _/path/-_
_to/build_ directory, the following commands will build the project (the `$` sign designates
a shell prompt):
`$` `cd` _`/path/to/build`_ 1
`$` `cmake` _`/path/to/source`_ 2
`$` `make` 3
Two executable files, `ising2_mc` for the sequential version, and `ising2_mc_mpi` for the
parallel version, will be generated in the current directory.
_Appendix_ _B.3._ _Monte_ _Carlo_ _simulation_ _class_
The simulation class encapsulates the details of building a Markov chain, sampling
observables (in this case, the energy, magnetization, _etc._ ), and keeping track of the
progress of the calculation. Our simulation class `ising_sim` is declared in Listing 2,
line 11.
Listing 2 : ising.hpp header file: Declares interface of the simulation class
`#pragma` `once` 1
2
`#include` `<alps/mc/mcbase.hpp >` 3
`#include` `" storage_type .hpp"` 4
5
6
`//` `Simulation` `class` `for` `2D` `Ising` `model` `(square` `lattice).` 7
`//` `Extends` `alps ::mcbase,` `the` `base` `class` `of` `all` `Monte` `Carlo` `simulations .` 8
`//` `Defines` `its` `state,` `calculation` `functions` `(update/measure)` `and` 9
`//` `serialization` `functions` `(save/load)` 10
`class` `ising_sim` `:` `public` `alps :: mcbase` `{` 11
`//` `The` `internal` `state` `of` `our` `simulation` 12
`private` `:` 13
`int` `length;` `//` `the` `same` `in` `both` `dimensions` 14
`int` `sweeps;` 15
`int` `thermalization_sweeps ;` 16
`int` `total_sweeps ;` 17
`double` `beta;` 18
`storage_type` `spins;` 19
`double` `current_energy ;` 20
`double` `current_magnetization ;` 21
22
13
23
24
`public` `:` 25
`ising_sim( parameters_type` `const` `&` `parms,` `std :: size_t` `seed_offset` `=` `0);` 26
27
`static` `void` `define_parameters ( parameters_type` `&` `parameters );` 28
29
`virtual` `void` `update ();` 30
`virtual` `void` `measure ();` 31
`virtual` `double` `fraction_completed ()` `const` `;` 32
33
`using` `alps :: mcbase :: save;` 34
`using` `alps :: mcbase :: load;` 35
`virtual` `void` `save(alps :: hdf5 :: archive` `&` `ar)` `const` `;` 36
`virtual` `void` `load(alps :: hdf5 :: archive` `&` `ar);` 37
`};` 38
The simulation class is required to inherit from `alps::mcbase`, and it must define
the following virtual methods with the corresponding semantics:
- `void` `update()` (line 30): Attempt a step in the phase space, accept or reject it;
- `void` `measure()` (line 31): Compute and accumulate observables;
- `double` `fraction_completed()` `const` (line 32): report the fraction of the computation that is completed.
Also, a static method `void` `define_parameters()` (line 28) should be provided that
declares (“defines”) the input parameters pertinent to the simulation (see section 3).
Listing 2 also declares a number of implementation-specific private data members
(lines 14–23) holding the internal state of the Markov chain. The `include` statement
in line 4 refers to the header file containing implementation details: storage of spins
in a two-dimensional array; for the sake of completeness, the implementations of the
corresponding class is briefly discussed in subsection Appendix B.7.
The implementation of the simulation class is provided by `ising.cpp` file. <sup>1</sup> Lines 5–
21 in the implementation file (Listing 3) define the input parameters that are relevant to
the simulation: size of the unit cell, number of thermalization Monte Carlo steps, total
number of steps, and the simulation temperature. Note that each parameter name has an
associated type, and parameters “sweeps” and “thermalization” are given default values
(0 and 10000, respectively); the other two parameters (“length” and “temperature”) do
not have default values and are required to be provided by the user. In addition, a
number of standard parameters used in every Monte Carlo simulation is defined by the
base class; the corresponding static method is called at line 12. Line 15 defines a number
of parameters common for many simulations.
Listing 3 : ising.cpp file: Implementation of the simulation class: Parameter definition
`#include` `"ising.hpp"` 1
`#include` `<alps/params/ convenience_params .hpp >` 2
3
`//` `Defines` `the` `parameters` `for` `the` `ising` `simulation` 4
`void` `ising_sim :: define_parameters ( parameters_type` `&` `parameters)` `{` 5
`//` `If` `the` `parameters` `are` `restored,` `they` `are` `already` `defined` 6
1The code presented here and in the following discussion is written with the focus on simplicity and
clarity rather than efficiency.
14
`if` `(parameters.is_restored ())` `{` 7
`return` `;` 8
`}` 9
10
`//` `Adds` `the` `parameters` `of` `the` `base` `class` 11
`alps :: mcbase :: define_parameters (parameters );` 12
`//` `Adds` `the` `convenience` `parameters` `(for` `save/load)` 13
`//` `followed` `by` `the` `ising` `specific` `parameters` 14
`alps :: define_convenience_parameters (parameters )` 15
`.description (` `"2D` `ising` `simulation "` `)` 16
`.define <` `int >(` `"length"` `,` `"size` `of` `the` `periodic` `box"` `)` 17
`.define <` `int >(` `"sweeps"` `,` `0,` `"maximum` `number` `of` `sweeps` `(0` `means` 18
```
indefinite)" )
```
`.define <` `int >(` `" thermalization "` `,` `10000,` `"number` `of` `sweeps` `for` 19
```
thermalization " )
```
`.define <` `double >(` `" temperature "` `,` `" temperature` `of` `the` `system"` `);` 20
`}` 21
The object constructor (Listing 4) initializes the internal state of the simulation in
lines 27–56. Additionally, lines 59–66 allocate named accumulators for the observables
to be collected during the simulation.
Listing 4 : ising.cpp file: Implementation of the simulation class: Constructor
`//` `Creates` `a` `new` `simulation.` 23
`//` `We` `always` `need` `the` `parameters` `and` `the` `seed` `as` `we` `need` `to` `pass` `it` `to` 24
`//` `the` `alps :: mcbase` `constructor .` `We` `also` `initialize` `our` `internal` `state,` 25
`//` `mainly` `using` `values` `from` `the` `parameters .` 26
`ising_sim :: ising_sim( parameters_type` `const` `&` `parms,` `std :: size_t` `seed_offset` 27
```
)
```
`:` `alps :: mcbase(parms,` `seed_offset )` 28
`,` `length(parameters[` `"length"` `])` 29
`,` `sweeps (0)` 30
`,` `thermalization_sweeps (` `int` `( parameters [` `" thermalization "` `]))` 31
`,` `total_sweeps (parameters[` `"sweeps"` `])` 32
`,` `beta (1.` `/` `parameters[` `" temperature "` `].as <` `double >())` 33
`,` `spins(length,length)` 34
`,` `current_energy (0)` 35
`,` `current_magnetization (0)` 36
`{` 37
38
`//` `Initializes` `the` `spins` 39
`for` `(` `int` `i=0;` `i<length;` `++i)` `{` 40
`for` `(` `int` `j=0;` `j<length;` `++j)` `{` 41
`spins(i,j)` `=` `(random ()` `<` `0.5` `?` `1` `:` `-1);` 42
`}` 43
`}` 44
45
`//` `Calculates` `initial` `magnetization` `and` `energy` 46
`for` `(` `int` `i=0;` `i<length;` `++i)` `{` 47
`for` `(` `int` `j=0;` `j<length;` `++j)` `{` 48
`current_magnetization` `+=` `spins(i,j);` 49
`int` `i_next =(i+1)%length;` 50
`int` `j_next =(j+1)%length;` 51
`current_energy` `+=` `-(spins(i,j)*spins(i,j_next)+` 52
`spins(i,j)*spins(i_next,j));` 53
54
`}` 55
`}` 56
57
`//` `Adds` `the` `measurements` 58
`measurements` 59
`<<` `alps :: accumulators :: FullBinningAccumulator <` `double >(` `"Energy"` `)` 60
`<<` `alps :: accumulators :: FullBinningAccumulator <` `double >(` `"` 61
```
Magnetization " )
```
`<<` `alps :: accumulators :: FullBinningAccumulator <` `double >(` `"` 62
```
AbsMagnetization " )
```
15
`<<` `alps :: accumulators :: FullBinningAccumulator <` `double >(` `"` 63
```
Magnetization ^2" )
```
`<<` `alps :: accumulators :: FullBinningAccumulator <` `double >(` `"` 64
```
Magnetization ^4" )
```
`;` 65
`}` 66
Implementation of the Monte Carlo step and the acceptance/rejection logic by the
method `update()` (Listing 5, lines 70–97) is straightforward.
Listing 5 : ising.cpp file: Implementation of the simulation class: Update method
`//` `Performs` `the` `calculation` `at` `each` `MC` `step;` 68
`//` `decides` `if` `the` `step` `is` `accepted.` 69
`void` `ising_sim :: update ()` `{` 70
`using` `std :: exp;` 71
`typedef` `unsigned` `int` `uint;` 72
`//` `Choose` `a` `spin` `to` `flip:` 73
`uint` `i` `=` `uint(length` `*` `random ());` 74
`uint` `j` `=` `uint(length` `*` `random ());` 75
`//` `Find` `neighbors` `indices,` `with` `wrap` `over` `box` `boundaries :` 76
`uint` `i1` `=` `(i+1)` `%` `length;` `//` `right` 77
`uint` `i2` `=` `(i-1+ length)` `%` `length;` `//` `left` 78
`uint` `j1` `=` `(j+1)` `%` `length;` `//` `up` 79
`uint` `j2` `=` `(j-1+ length)` `%` `length;` `//` `down` 80
`//` `Energy` `difference:` 81
`double` `delta =2.* spins(i,j)*` 82
`(spins(i1,j)+` `//` `right` 83
`spins(i2,j)+` `//` `left` 84
`spins(i,j1)+` `//` `up` 85
`spins(i,j2));` `//` `down` 86
87
`//` `Step` `acceptance:` 88
`if` `(delta <=0.` `||` `random ()` `<` `exp(-beta*delta))` `{` 89
`//` `update` `energy:` 90
`current_energy` `+=` `delta;` 91
`//` `update` `magnetization :` 92
`current_magnetization` `-=` `2* spins(i,j);` 93
`//` `flip` `the` `spin` 94
`spins(i,j)` `=` `-spins(i,j);` 95
`}` 96
`}` 97
The `measure()` method (Listing 6, lines 100–113) adds the observables of interest to
the corresponding named accumulators (lines 108–112).
Listing 6 : ising.cpp file: Implementation of the simulation class: Measurement method
`//` `Collects` `the` `measurements` `at` `each` `MC` `step.` 99
`void` `ising_sim :: measure ()` `{` 100
`++ sweeps;` 101
`if` `(sweeps < thermalization_sweeps )` `return` `;` 102
103
`const` `double` `n=length*length;` `//` `number` `of` `sites` 104
`double` `tmag` `=` `current_magnetization` `/` `n;` `//` `magnetization` 105
106
`//` `Accumulate` `the` `data` `(per` `site)` 107
`measurements [` `"Energy"` `]` `<<` `( current_energy` `/` `n);` 108
`measurements [` `" Magnetization "` `]` `<<` `tmag;` 109
`measurements [` `" AbsMagnetization "` `]` `<<` `fabs(tmag);` 110
`measurements [` `" Magnetization ^2"` `]` `<<` `tmag*tmag;` 111
`measurements [` `" Magnetization ^4"` `]` `<<` `tmag*tmag*tmag*tmag;` 112
`}` 113
The `fraction_completed()` method (Listing 7, lines 116–122) returns a `double`
value. This value indicates whether the simulation ran the intended number of steps:
16
the simulation stops when the value reaches 1 _._ 0. The termination criteria are discussed
in more details in Appendix B.6.
Listing 7 : ising.cpp file: Implementation of the simulation class: Report completed fraction
`//` `Returns` `a` `number` `between` `0.0` `and` `1.0` `with` `the` `completion` `percentage` 115
`double` `ising_sim :: fraction_completed ()` `const` `{` 116
`double` `f=0;` 117
`if` `(total_sweeps >0` `&&` `sweeps` `>=` `thermalization_sweeps )` `{` 118
`f=(sweeps - thermalization_sweeps )/` `double` `( total_sweeps );` 119
`}` 120
`return` `f;` 121
`}` 122
The implementation file `ising.cpp` also contains definitions of methods that are
necessary for checkpointing the simulation, as discussed in Appendix B.5.
_Appendix_ _B.4._ _Main_ _program_
We first describe the flow of the sequential implementation, postponing the discussion of the parallelization till subsection Appendix B.6. The sequential main program
( `main.cpp` ) is shown in Listings 8 and 9; a few essential points are discussed in this and
the following subsections.
Line 19 of Listing 8 constructs a parameter object from the command line arguments:
an optional name of a parameter file followed by an optional set of parameters in the
form of “ `--key=value` ”. The parameter values that are set in the command line override
the values set in the parameter file. The parameter names and types must be declared
before use, which is done at line 20 by a call to a static method `define_parameters()`
of the simulation class. Lines 22–25 check if the user requested help or missed a required
argument. The simulation is created at line 28, with the parameters passed to the
constructor. Line 41 starts the simulation.
Listing 8 : main.cpp file: Main program, sequential version: Starting the simulation
`#include` `"ising.hpp"` 1
`#include` `<iostream >` 2
`#include` `<alps/ accumulators .hpp >` 3
`#include` `<alps/mc/api.hpp >` 4
`#include` `<alps/mc/mcbase.hpp >` 5
`#include` `<alps/mc/ stop_callback .hpp >` 6
7
`int` `main(` `int` `argc,` `char` `*` `argv [])` 8
`{` 9
`//` `Define` `the` `type` `for` `the` `simulation` 10
`typedef` `ising_sim` `my_sim_type ;` 11
12
`try` `{` 13
14
`//` `Creates` `the` `parameters` `for` `the` `simulation` 15
`//` `If` `an` `hdf5` `file` `is` `supplied,` `reads` `the` `parameters` `there` 16
`std :: cout` `<<` `" Initializing` `parameters ..."` `<<` `std :: endl;` 17
18
`alps :: params` `parameters(argc,` `(` `const` `char **) argv);` 19
`my_sim_type :: define_parameters ( parameters );` 20
21
`if` `(parameters. help_requested (std :: cout)` `||` 22
`parameters.has_missing (std :: cout))` `{` 23
`return` `1;` 24
`}` 25
26
`std :: cout` `<<` `"Creating` `simulation"` `<<` `std :: endl;` 27
`my_sim_type` `sim(parameters );` 28
17
29
`//` `If` `needed,` `restore` `the` `last` `checkpoint` 30
`std :: string` `checkpoint_file` `=` `parameters [` `" checkpoint"` `].as <std ::` 31
```
string >();
```
32
`if` `(parameters.is_restored ())` `{` 33
`std :: cout` `<<` `"Restoring` `checkpoint` `from` `"` `<<` `checkpoint_file` 34
`<<` `std:: endl;` 35
`sim.load( checkpoint_file );` 36
`}` 37
38
`//` `Run` `the` `simulation` 39
`std :: cout` `<<` `"Running` `simulation "` `<<` `std :: endl;` 40
`sim.run(alps :: stop_callback (size_t(parameters [` `"timelimit"` `])));` 41
The results of the simulation (the accumulated observables) are retrieved at line 48
(Listing 9). The `results` object is streamed to standard output which prints out all
the accumulated results. Individual observables can be accessed by name, as shown by
lines 56–62. The observable is represented by an object of type `result_wrapper` from
namespace `alps::accumulators` ; each object has associated mean value, error bar and
autocorrelation length. It is possible to conduct arithmetic operations and compute
functions of the `result_wrapper` objects, as illustrated by line 65 computing Binder
cumulant (per equation (B.3)); the error bars of the operands are propagated when an
expression is evaluated. Finally, at lines 73–76 the simulation parameters and the results
are saved to a file in `HDF5` format; the name of the file is passed via input parameter
“outputfile” which is defined earlier in the simulation implementation file `ising.cpp` (by
the call at line 15 of Listing 3).
Listing 9 : main.cpp file: Main program, sequential version: Collecting the results
42
`//` `Checkpoint` `the` `simulation` 43
`std :: cout` `<<` `" Checkpointing` `simulation` `to` `"` `<<` `checkpoint_file` 44
`<<` `std:: endl;` 45
`sim.save( checkpoint_file );` 46
47
`alps :: results_type <my_sim_type >:: type` `results` `=` `alps ::` 48
```
collect_results (sim);
```
49
`//` `Print` `results` 50
`{` 51
`using` `alps :: accumulators :: result_wrapper ;` 52
`std :: cout` `<<` `"All` `measured` `results:"` `<<` `std :: endl;` 53
`std :: cout` `<<` `results` `<<` `std :: endl;` 54
55
`std :: cout` `<<` `"Simulation` `ran` `for` `"` 56
`<<` `results[` `"Energy"` `]. count ()` 57
`<<` `"` `steps."` `<<` `std :: endl;` 58
59
`//` `Assign` `individual` `results` `to` `variables.` 60
`const` `result_wrapper &` `mag4=results[` `" Magnetization ^4"` `];` 61
`const` `result_wrapper &` `mag2=results[` `" Magnetization ^2"` `];` 62
63
`//` `Derived` `result:` 64
`const` `result_wrapper &` `binder_cumulant =1-mag4 /(3* mag2*mag2);` 65
`std :: cout` `<<` `"Binder` `cumulant:` `"` `<<` `binder_cumulant` 66
`<<` `results[` `"Energy"` `]. count ()` 57
`<<` `"` `Relative` `error:` `"` 67
`<<` `fabs( binder_cumulant .error <` `double >()/` 68
`binder_cumulant .mean <` `double >())` 69
`<<` `std:: endl;` 70
`binder_cumulant .mean <` `double >())` 69
71
`//` `Saving` `to` `the` `output` `file` 72
`std :: string` `output_file` `=` `parameters [` `" outputfile "` `];` 73
`alps :: hdf5 :: archive` `ar(boost :: filesystem :: path( output_file ),` `"w` 74
```
" );
```
`ar[` `"/parameters"` `]` `<<` `parameters ;` 75
18
`ar[` `"/simulation/results"` `]` `<<` `results;` 76
`}` 77
`return` `0;` 78
`}` `catch` `(` `const` `std:: runtime_error &` `exc)` `{` 79
`std :: cout` `<<` `"Exception` `caught:` `"` `<<` `exc.what ()` `<<` `std :: endl;` 80
`return` `2;` 81
`}` `catch` `(...)` `{` 82
`std :: cout` `<<` `"Unknown` `exception` `caught."` `<<` `std :: endl;` 83
`return` `2;` 84
`}` 85
`}` 86
_Appendix_ _B.5._ _Checkpointing_
Listing 10 focuses on the part of the main program that is relevant for checkpointing.
Once the simulation is completed, at line 46 of the file `main.cpp` the state of the simulation object is saved to a file via a call to method `save()`, which takes the file name as
an argument. If the first argument to the program is a name of a file in `HDF5` format, the
parameter object constructor restores the parameters (including their associated types
and values) from the file (the values of individual parameters still can be overridden
from the command line). Lines 33–37 check if the parameters are read from an `HDF5` formatted file, and, if so, the simulation object is restored from the checkpoint file via
call to method `load()`, which, like `save()`, takes the file name as an argument. Both
`save()` and `load()` methods are provided by the base simulation class `alps::mcbase` .
Listing 10 : main.cpp file: Main program, sequential version: Checkpointing
`//` `If` `needed,` `restore` `the` `last` `checkpoint` 30
`std :: string` `checkpoint_file` `=` `parameters [` `" checkpoint"` `].as <std ::` 31
```
string >();
```
32
`if` `(parameters.is_restored ())` `{` 33
`std :: cout` `<<` `"Restoring` `checkpoint` `from` `"` `<<` `checkpoint_file` 34
`<<` `std:: endl;` 35
`sim.load( checkpoint_file );` 36
`}` 37
38
`//` `Run` `the` `simulation` 39
`std :: cout` `<<` `"Running` `simulation "` `<<` `std :: endl;` 40
`sim.run(alps :: stop_callback (size_t(parameters [` `"timelimit"` `])));` 41
42
`//` `Checkpoint` `the` `simulation` 43
`std :: cout` `<<` `" Checkpointing` `simulation` `to` `"` `<<` `checkpoint_file` 44
`<<` `std:: endl;` 45
`sim.save( checkpoint_file );` 46
However, to support checkpointing, user’s simulation class `ising_sim` must provide
`save()` and `load()` methods that take a reference to an object of `alps::hdf5::archive`
type. In our example code, those methods are defined in the simulation implementation
file `ising.cpp` (Listing 11), lines 125–136 ( `save()` ) and 139–155 ( `load()` ).
Listing 11 : ising.cpp file: Implementation of the simulation class: Checkpointing
`//` `Saves` `the` `state` `to` `the` `hdf5` `file` 124
`void` `ising_sim :: save(alps :: hdf5 :: archive` `&` `ar)` `const` `{` 125
`//` `Most` `of` `the` `save` `logic` `is` `already` `implemented` `in` `the` `base` `class` 126
`alps :: mcbase :: save(ar);` 127
128
`//` `We` `just` `need` `to` `add` `our` `own` `internal` `state` 129
`ar[` `"checkpoint/spins"` `]` `<<` `spins;` 130
`ar[` `"checkpoint/sweeps"` `]` `<<` `sweeps;` 131
`ar[` `"checkpoint/ current_energy "` `]` `<<` `current_energy ;` 132
19
`ar[` `"checkpoint/ current_magnetization "` `]` `<<` `current_magnetization ;` 133
134
`//` `The` `rest` `of` `the` `internal` `state` `is` `saved` `as` `part` `of` `the` `parameters` 135
`}` 136
137
`//` `Loads` `the` `state` `from` `the` `hdf5` `file` 138
`void` `ising_sim :: load(alps :: hdf5 :: archive` `&` `ar)` `{` 139
`//` `Most` `of` `the` `load` `logic` `is` `already` `implemented` `in` `the` `base` `class` 140
`alps :: mcbase :: load(ar);` 141
142
`//` `Restore` `the` `internal` `state` `that` `came` `from` `parameters` 143
`length` `=` `parameters[` `"length"` `];` 144
`thermalization_sweeps` `=` `parameters [` `" thermalization "` `];` 145
`//` `Note:` `‘total_sweeps ‘` `is` `not` `restored` `here!` 146
`beta` `=` `1.` `/` `parameters[` `" temperature "` `].as <` `double >();` 147
148
149
`//` `Restore` `the` `rest` `of` `the` `state` `from` `the` `hdf5` `file` 150
`ar[` `"checkpoint/spins"` `]` `>>` `spins;` 151
`ar[` `"checkpoint/sweeps"` `]` `>>` `sweeps;` 152
`ar[` `"checkpoint/ current_energy "` `]` `>>` `current_energy ;` 153
`ar[` `"checkpoint/ current_magnetization "` `]` `>>` `current_magnetization ;` 154
`}` 155
Most of the logic is implemented in the corresponding methods of the parent class;
the `save()` method saves only the part of the internal state that changed since construction of the object (lines 130–133), and the `load()` method both restores those variables (lines 151–154) and re-initializes the rest of the internal state from the parameters
(lines 144–147).
For all basic types and many common `C++` aggregate types (such as STL vectors,
vectors of STL vectors, and others) the saving to and loading from an `HDF5` archive
are supported via a simple streaming operators `<<` and `>>`, as shown in lines 131–133
and 152–154. However, to support archiving of the `spins` object (lines 130 and 151)
which is of the user-defined type `storage_type`, similar methods `save()` and `load()`
must be defined in the corresponding class, as discussed in subsection Appendix B.7.
_Appendix_ _B.6._ _Scheduling_ _and_ _parallelization_
Normally, the sequential simulation terminates once it has run to completion, as determined by the value returned by the method `fraction_completed()` of the simulation
class. However, the method `run()` of the simulation base class `alps::mcbase` accepts a
function object argument: the “stop callback”. This callback is called repeatedly during
the simulation and is expected to return a boolean value: `false` if the simulation can continue, `true` if the simulation must be stopped. The library provides convenience function
objects of class `alps::stop_callback` . The class constructor takes the maximum simulation time (in seconds) as an argument; the constructed function object returns `true` if
the maximum simulation time has elapsed since the moment of the object construction,
or if the program is interrupted by a signal. The use of the `alps::stop_callback` class
facilitates a “graceful” termination of the simulation in the case of timeout or interruption
by a user.
In order to parallelize the simulation, only minimal changes are required in the main
program, and no changes are needed in the simulation class. The parallel version of the
main program is given by Listing 12.
Listing 12 : main ~~m~~ pi.cpp file: Main program, parallel version
`#include` `"ising.hpp"` 1
20
`#include` `<iostream >` 2
`#include` `<alps/ accumulators .hpp >` 3
`#include` `<alps/mc/api.hpp >` 4
`#include` `<alps/mc/mcbase.hpp >` 5
`#include` `<alps/mc/ stop_callback .hpp >` 6
`#include` `<alps/mc/mpiadapter.hpp >` 7
8
`int` `main(` `int` `argc,` `char` `*` `argv [])` 9
`{` 10
`//` `Define` `the` `type` `for` `the` `simulation` 11
`typedef` `alps :: mcmpiadapter <ising_sim >` `my_sim_type ;` 12
13
`//` `Initialize` `the` `MPI` `environment,` `and` `obtain` `the` `WORLD` `communicator` 14
`alps :: mpi :: environment` `env(argc,` `argv);` 15
`alps :: mpi :: communicator` `comm;` 16
`const` `int` `rank=comm.rank ();` 17
`const` `bool` `is_master =( rank ==0);` 18
19
`try` `{` 20
`//` `Creates` `the` `parameters` `for` `the` `simulation` 21
`//` `If` `an` `hdf5` `file` `is` `supplied,` `reads` `the` `parameters` `there` 22
`if` `(is_master)` `std:: cout` `<<` `" Initializing` `parameters ..."` `<<` `std ::` 23
```
endl;
```
24
`//` `This` `constructor` `broadcasts` `to` `all` `processes` 25
`alps :: params` `parameters(argc,` `(` `const` `char **) argv,` `comm);` 26
`my_sim_type :: define_parameters ( parameters );` 27
28
`if` `(parameters. help_requested (std :: cout)` `||` 29
`parameters.has_missing (std :: cout))` `{` 30
`return` `1;` 31
`}` 32
33
`std :: cout` `<<` `"Creating` `simulation` `on` `rank` `"` `<<` `rank` `<<` `std :: endl;` 34
`my_sim_type` `sim(parameters,` `comm);` 35
36
`//` `If` `needed,` `restore` `the` `last` `checkpoint` 37
`std :: string` `checkpoint_file` `=` `parameters [` `" checkpoint"` `].as <std ::` 38
```
string >();
```
`if` `(! is_master)` `checkpoint_file +=` `"."` `+boost :: lexical_cast <std ::` 39
```
string >( rank);
```
40
`if` `(parameters.is_restored ())` `{` 41
`std :: cout` `<<` `"Restoring` `checkpoint` `from` `"` `<<` `checkpoint_file` 42
`<<` `"` `on` `rank` `"` `<<` `rank` `<<` `std :: endl;` 43
`sim.load( checkpoint_file );` 44
`}` 45
46
`//` `Run` `the` `simulation` 47
`std :: cout` `<<` `"Running` `simulation` `on` `rank` `"` `<<` `rank` `<<` `std :: endl;` 48
`sim.run(alps :: stop_callback (size_t(parameters [` `"timelimit"` `])));` 49
50
`//` `Checkpoint` `the` `simulation` 51
`std :: cout` `<<` `" Checkpointing` `simulation` `to` `"` `<<` `checkpoint_file` 52
`<<` `"` `on` `rank` `"` `<<` `rank` `<<` `std :: endl;` 53
`sim.save( checkpoint_file );` 54
55
`alps :: results_type <my_sim_type >:: type` `results` `=` `alps ::` 56
```
collect_results (sim);
```
57
`//` `Print` `results` 58
`if` `(is_master)` `{` 59
`using` `alps :: accumulators :: result_wrapper ;` 60
`std :: cout` `<<` `"All` `measured` `results:"` `<<` `std :: endl;` 61
`std :: cout` `<<` `results` `<<` `std :: endl;` 62
63
`std :: cout` `<<` `"Simulation` `ran` `for` `"` 64
`<<` `results[` `"Energy"` `]. count ()` 65
`<<` `"` `steps."` `<<` `std :: endl;` 66
67
`//` `Assign` `individual` `results` `to` `variables.` 68
`const` `result_wrapper &` `mag4=results[` `" Magnetization ^4"` `];` 69
21
`<<` `results[` `"Energy"` `]. count ()` 65
`const` `result_wrapper &` `mag2=results[` `" Magnetization ^2"` `];` 70
71
`//` `Derived` `result:` 72
`const` `result_wrapper &` `binder_cumulant =1-mag4 /(3* mag2*mag2);` 73
`std :: cout` `<<` `"Binder` `cumulant:` `"` `<<` `binder_cumulant` 74
`<<` `"` `Relative` `error:` `"` 75
`<<` `fabs( binder_cumulant .error <` `double >()/` 76
`binder_cumulant .mean <` `double >())` 77
`<<` `std:: endl;` 78
`binder_cumulant .mean <` `double >())` 77
79
`//` `Saving` `to` `the` `output` `file` 80
`std :: string` `output_file` `=` `parameters [` `" outputfile "` `];` 81
`alps :: hdf5 :: archive` `ar(boost :: filesystem :: path( output_file ),` `"w` 82
```
" );
```
`ar[` `"/parameters"` `]` `<<` `parameters ;` 83
`ar[` `"/simulation/results"` `]` `<<` `results;` 84
`}` 85
`return` `0;` 86
`}` `catch` `(` `const` `std:: runtime_error &` `exc)` `{` 87
`std :: cout` `<<` `"Exception` `caught:` `"` `<<` `exc.what ()` `<<` `std :: endl;` 88
`env.abort (2);` 89
`return` `2;` 90
`}` `catch` `(...)` `{` 91
`env.abort (2);` 89
`std :: cout` `<<` `"Unknown` `exception` `caught."` `<<` `std :: endl;` 92
`env.abort (2);` 93
`return` `2;` 94
`}` 95
`}` 96
At line 12, the `alps::mcmpiadapter` template parametrized by the user’s simulation
class (in our example, `ising_sim` ) is used as the simulation class. The `MPI` environment is initialized and an `MPI` communicator is obtained (lines 15–17). The parameters
object is created using a special broadcasting constructor (line 26) that takes the `MPI`
communicator as an argument. Likewise, the parallel simulation constructor takes the
communicator as its argument at line 35 (and ensures that each of the parallel simulation clones has its random number generator initialized with a different seed). Line 39
accounts for the fact that each of the parallel `MPI` processes now has its own checkpoint
file. The results are seamlessly retrieved at line 56 from all parallel processes; the master process is responsible for processing and printing the results, as checked at line 59.
Finally, if an exception is raised during the simulation, all `MPI` processes are aborted
(lines 89 and 93).
In the case of the parallel execution, the simulation is considered completed if the
_sum_ of values returned by `fraction_completed()` methods of all parallel instances of
the simulation class reaches 1, or if a termination requested by the “stop callback” in
any of the instances. However, to reduce unnecessary interprocess communications, the
completeness condition is checked at varying time intervals, within the limits specified
by input parameters “Tmin” and “Tmax”. It should be noted that the check of the
completeness condition is a collective operation: this must be taken into account if the
user code invokes `MPI` collective operations on its own. It is therefore recommended, to
avoid a possibility of a deadlock, that any collective operation initiated inside `update()`
or `measure()` method should be completed before the method returns.
_Appendix_ _B.7._ _Other_ _implementation_ _details_
The 2D-array storage type to keep values of spins is presented in Listing 13. For the
sake of clarity and simplicity, spins are stored as a vector of integer vectors. Note that
the class also defines method for saving to and loading from an `HDF5` file (lines 27–33).
22
Listing 13 : storage ~~t~~ ype.hpp header file: Implementation of a 2D-array
`#pragma` `once` 1
2
`#include` `<vector >` 3
`#include` `<alps/hdf5.hpp >` 4
5
`//` `Storage` `class` `for` `2D` `spin` `array.` 6
`//` `Implemented` `as` `vector` `of` `vectors` `for` `simplicity .` 7
`class` `storage_type` `{` 8
`private` `:` 9
`std ::vector <` `std ::vector <` `int >` `>` `data_;` 10
`public` `:` 11
`//` `Constructor` 12
`storage_type (` `int` `nrows,` `int` `ncols):` 13
`data_(nrows,` `std::vector <` `int >( ncols))` 14
`{}` 15
16
`//` `Read` `access` 17
`int` `operator ()(` `int` `i,` `int` `j)` `const` `{` 18
`return` `data_[i][j];` 19
`}` 20
`//` `Read/Write` `access` 21
`int` `&` `operator ()(` `int` `i,` `int` `j)` `{` 22
`return` `data_[i][j];` 23
`}` 24
25
`//` `Custom` `save` 26
`void` `save(alps :: hdf5 :: archive&` `ar)` `const` `{` 27
`ar[` `"2Darray"` `]` `<<` `data_;` 28
`}` 29
`//` `Custom` `load` 30
`void` `load(alps :: hdf5 :: archive&` `ar)` `{` 31
`return` `data_[i][j];` 19
`return` `data_[i][j];` 23
`ar[` `"2Darray"` `]` `<<` `data_;` 28
`ar[` `"2Darray"` `]` `>>` `data_;` 32
`}` 33
`};` 34
_Appendix_ _B.8._ _Sample_ _run_ _and_ _results_
For the sake of the example, some parameters for the run are provided via a parameter
file (see Listing 14).
Listing 14 : ising2 ~~m~~ c.ini parameter file
`#` `Size` `of` `the` `box:` 1
`length =4` 2
`#` `Time` `limit` 3
`timelimit` `=` `3600` 4
Running of the parallel version on 2 CPU cores with example input parameters produces
the following:
`$` `mpiexec` `-n` `2` `./ ising2_mc_mpi` `ising2_mc.ini` `--temperature =5` `--timelimit =60` 1
`Initializing` `parameters ...` 2
`Creating` `simulation` `on` `rank` `0` 3
`Running` `simulation` `on` `rank` `0` 4
`Creating` `simulation` `on` `rank` `1` 5
`Running` `simulation` `on` `rank` `1` 6
`Checkpointing` `simulation` `to` `ising2_mc.clone.h5.1` `on` `rank` `1` 7
`Checkpointing` `simulation` `to` `ising2_mc.clone.h5` `on` `rank` `0` 8
`All` `measured` `results:` 9
`AbsMagnetization :` `Mean` `+/- error` `(tau):` `0.342837` `+/ -0.000101316(12.6489)` 10
`Energy:` `Mean` `+/- error` `(tau):` `-0.456241` `+/ -0.000168541(10.7416)` 11
`Magnetization :` `Mean` `+/- error` `(tau):` `-0.000150723` `+/ -0.000275311(31.4836)` 12
`Magnetization ^2:` `Mean` `+/- error` `(tau):` `0.175277` `+/ -9.02575e -05(13.7491)` 13
`Magnetization ^4:` `Mean` `+/- error` `(tau):` `0.0730068` `+/ -6.40981e -05(12.6128)` 14
23
15
`Simulation` `ran` `for` `147922660` `steps.` 16
`Binder` `cumulant:` `Mean` `+/- error` `(tau):` `0.207852` `+/ -0.000218572(12.6128)` 17
```
Relative error: 0.00105158
```
and creates files `ising2_mc.out.h5`, `ising2_mc.clone.h5` and `ising2_mc.clone.h5.1`
in the current directory.
The program was run on a set of pre-generated parameter files with varying temperature and system size; the standard output was parsed and formatted for plotting by a
simple script. The results are presented in figure B.2.
L=4
L=8
L=16
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10
T
L=4
L=8
L=16
2.5 3 3.5 4 4.5 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10
T
L=4
L=8
L=16
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10
T
L=4
L=8
L=16
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10
T
(a)
(c)
-0.2
-0.4
-0.6
-0.8
-1
-1.2
-1.4
-1.6
-1.8
-2
1000
100
10
1
0.1
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
(b)
(d)
Figure B.2: The results of the 2D Ising model calculation implemented using ALPS core
libraries, with periodic box of sizes _L_ = 4, _L_ = 8 and _L_ = 16. The quantities plotted
against the temperature T are: (a) Mean energy _⟨E⟩_ per spin; (b) Absolute value of
magnetization _⟨|M_ _|⟩_ per spin; (c) Autocorrelation length, per spin (logarithmic scale) of
magnetization _M_ ; (d) Binder cumulant for magnetization distribution.
Appendix C. Example: Green’s Functions interface
Listing 15 illustrates working with Green’s functions.
Listing 15 : Working with Green’s Function demo
`#include` `<alps/gf/gf.hpp >` 1
`#include` `<alps/gf/tail.hpp >` 2
3
`#include` `<boost/array.hpp >` 4
5
`namespace` `g=alps ::gf;` 6
7
`//` `Generates` `points` `for` `momentum` `mesh` 8
24
`g:: momentum_index_mesh :: container_type` `generate_momentum_mesh ();` 9
10
`void` `Demo ()` `{` 11
`const` `int` `nspins =2;` 12
`const` `int` `nfreq =10;` 13
`const` `double` `beta =5;` 14
15
`//` `Construct` `the` `meshes:` 16
`g:: matsubara_positive_mesh` `m_mesh(beta,` `nfreq);` 17
`g:: momentum_index_mesh` `k_mesh( generate_momentum_mesh ());` 18
`g:: index_mesh` `s_mesh(nspins);` 19
20
`//` `construct` `a` `GF` `using` `a` `pre -defined` `convenience` `type` 21
`g:: omega_k_sigma_gf` `gf(m_mesh,` `k_mesh,` `s_mesh);` 22
`//` `initialize` `a` `GF` `to` `all -zeros` 23
`gf.initialize ();` 24
25
`//` `Make` `indices:` 26
`g:: matsubara_index` `omega;` 27
`omega =4;` 28
`g:: momentum_index` `ii(2);` 29
`g:: index` `sigma (0);` 30
31
`//` `Assign` `a` `GF` `element:` 32
`gf(omega,ii,sigma)=std :: complex <` `double >(3,4);` 33
34
`//` `Density` `matrix` `as` `a` `double -valued` `GF` 35
`//` `on` `momentum` `and` `integer -index` `space:` 36
`typedef` 37
`g:: two_index_gf <` `double,` `g:: momentum_index_mesh,` `g:: index_mesh >` 38
`density_matrix_type ;` 39
40
`//` `Construct` `the` `object:` 41
`density_matrix_type` `denmat= density_matrix_type (k_mesh,s_mesh);` 42
43
`//` `prepare` `diagonal` `matrix` 44
`const` `double` `U=3.0;` 45
`denmat.initialize ();` 46
`//` `loop` `over` `first` `mesh` `index:` 47
`for` `(g:: momentum_index` `i=g:: momentum_index (0);` 48
`i<denmat.mesh1 ().extent ();` `++i)` `{` 49
`denmat(i,g:: index (0))=0.5*U;` 50
`denmat(i,g:: index (1))=0.5*U;` 51
`}` 52
53
`//` `construct` `a` `tailed` `GF` `using` `predefined` `convenience` `type:` 54
`g:: omega_k_sigma_gf_with_tail` `gft(gf);` 55
`gft.set_tail (0,` `denmat);` `//` `set` `the` `tail` 56
57
`density_matrix_type` `gftail=gft.tail (0);` `//` `retrieve` `the` `tail` 58
59
`//` `access` `the` `tailed` `GF` `element` 60
`std :: complex <` `double >` `x=gft(omega,ii,sigma);` 61
`}` 62
63
`///` `Generates` `4` `2-D` `points` `k_1,..., k_4` `where` `each` `point` `k=(k_x,k_y)` 64
`g:: momentum_index_mesh :: container_type` `generate_momentum_mesh ()` `{` 65
`const` `boost ::array <` `int,2>` `dimensions ={{4,2}};` 66
`g:: momentum_index_mesh :: container_type` `mesh_points ( dimensions);` 67
`mesh_points [0][0]=0;` `mesh_points [0][1]=0;` `//` `(0,0)` 68
`mesh_points [1][0]= M_PI;` `mesh_points [1][1]= M_PI;` `//` `(pi,pi)` 69
`mesh_points [2][0]= M_PI;` `mesh_points [2][1]=0;` `//` `(pi,0)` 70
`mesh_points [3][0]=0;` `mesh_points [3][1]= M_PI;` `//` `(0,pi)` 71
`return` `mesh_points;` 72
`}` 73
At lines 17–19 three meshes are constructed: a Matsubara mesh, a mesh in momentum
space, and a general index mesh used here for the spin variable. Then, at line 22 a
predefined convenience type is used to create a Green’s function defined on a Cartesian
product of these three meshes. An element of the Green’s function can only be addressed
25
by a tuple of 3 indices each belonging to a corresponding mesh, as shown in the listing:
lines 27–30 define the indices and assign values to them, and line 33 accesses the Green’s
function element.
Lines 37–39 define a Green’s function type `density_matrix_type` explicitly as a
floating-point ( `C++` `double` ) valued function defined on a Cartesian product of two
meshes: the momentum mesh and the spin mesh. Here, a density matrix represented as
an object of this type. The loop over the momentum index (lines 48–52) illustrates the
use of inequality and increment operators on a mesh index to set values of the density
matrix.
At line 55 a Green’s function with a known tail is created from a regular Green’s
function. The tail encapsulates a high frequency expansion of a Green’s function as:
_G_ ( _iωn, x . . ._ ) = _c_ 0( _x . . ._ ) + <sup>_<u>c</u>_</sup> <sup><u>1(</u></sup> <sup>_<u>x . . .</u>_</sup> <sup><u>)</u></sup>
_iωn_
+ <sup>_<u>c</u>_</sup> <sup><u>2(</u></sup> <sup>_<u>x . . .</u>_</sup> <sup><u>)</u></sup> + _· · ·_ (C.1)
( _iωn_ ) <sup>2</sup>
where _ωn_ is Matsubara frequency, _cj_ ( _j_ = 0 _, . . ._ ) are tail coefficients of _j_ -th order, and
_x . . ._ represent all other arguments of a multi-dimensional Green’s function. Note that
the tail coefficients in this representation are themselves functions defined over ( _x . . ._ ).
At line 56 of the listing 15, the density matrix `denmat` is set as the 0-th order tail
coefficient.
Finally, lines 65–73 define the function used to generate the momentum space mesh:
the mesh contains 4 points, and each point ( _kx, ky_ ) lies in a 2-dimensional momentum
space.
26
섹션 본문
섹션 본문이 없습니다.
참고문헌
참고문헌 정보가 없습니다.