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

Output build info #63

Merged
merged 2 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion Make.Emu
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,48 @@ include $(Ppack)

DEFINES += -DNUM_FLAVORS=$(NUM_FLAVORS) -DSHAPE_FACTOR_ORDER=$(SHAPE_FACTOR_ORDER)

all: generate $(executable)
all: generate $(objEXETempDir)/AMReX_buildInfo.o $(executable)
@echo SUCCESS

generate:
python3 $(EMU_HOME)/Scripts/symbolic_hermitians/generate_code.py $(NUM_FLAVORS) --emu_home $(EMU_HOME)

#------------------------------------------------------------------------------
# build info (from Castro/Exec/Make.auto_source)
#------------------------------------------------------------------------------
CEXE_headers += $(AMREX_HOME)/Tools/C_scripts/AMReX_buildInfo.H
INCLUDE_LOCATIONS += $(AMREX_HOME)/Tools/C_scripts

# we make AMReX_buildInfo.cpp as we make the .o file, so we can delete
# it immediately. this way if the build is interrupted, we are
# guaranteed to remake it

objForExecs += $(objEXETempDir)/AMReX_buildInfo.o

.FORCE:
.PHONE: .FORCE

# set BUILD_GIT_NAME and BUILD_GIT_DIR if you are building in a
# git-controlled dir not under Castro/
EXTRA_BUILD_INFO :=
ifdef BUILD_GIT_NAME
EXTRA_BUILD_INFO := --build_git_name "$(BUILD_GIT_NAME)" \
--build_git_dir "$(BUILD_GIT_DIR)"
endif

$(objEXETempDir)/AMReX_buildInfo.o: .FORCE
echo $(objEXETempDir)
$(AMREX_HOME)/Tools/C_scripts/makebuildinfo_C.py \
--amrex_home "$(AMREX_HOME)" \
--COMP "$(COMP)" --COMP_VERSION "$(COMP_VERSION)" \
--CXX_comp_name "$(CXX)" --CXX_flags "$(CXXFLAGS) $(CPPFLAGS) $(includes)" \
--F_comp_name "$(F90)" --F_flags "$(F90FLAGS)" \
--link_flags "$(LDFLAGS)" --libraries "$(libraries)" \
--MODULES "$(MNAMES)" $(EXTRA_BUILD_INFO) \
--GIT "$(TOP) $(AMREX_HOME) $(MICROPHYSICS_HOME)"
$(SILENT) $(CCACHE) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(CXXEXEFLAGS) AMReX_buildInfo.cpp -o $(objEXETempDir)/AMReX_buildInfo.o
$(SILENT) $(RM) AMReX_buildInfo.cpp



include $(AMREX_HOME)/Tools/GNUMake/Make.rules
6 changes: 6 additions & 0 deletions Source/IO.H
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ RecoverParticles (const std::string& dir,
FlavoredNeutrinoContainer& neutrinos,
amrex::Real& time, int& step);

void
writeBuildInfo ();

void
writeJobInfo (const std::string& dir, const amrex::Geometry& geom);

#endif
267 changes: 267 additions & 0 deletions Source/IO.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <AMReX_MultiFabUtil.H>
#include <AMReX_PlotFileUtil.H>
#include <AMReX_buildInfo.H>

#include "FlavoredNeutrinoContainer.H"
#include "IO.H"
Expand Down Expand Up @@ -31,6 +32,9 @@ WritePlotFile (const amrex::MultiFab& state,
auto neutrino_varnames = neutrinos.get_attribute_names();
neutrinos.Checkpoint(plotfilename, "neutrinos", true, neutrino_varnames);
}

// write job information
writeJobInfo (plotfilename, geom);
}

void
Expand All @@ -57,3 +61,266 @@ RecoverParticles (const std::string& dir,
// print the step/time for the restart
amrex::Print() << "Restarting after time step: " << step-1 << " t = " << time << " s. ct = " << PhysConst::c * time << " cm" << std::endl;
}


// writeBuildInfo and writeJobInfo are copied from Castro/Source/driver/Castro_io.cpp
// and modified by Sherwood Richers
/*
SOURCE CODE LICENSE AGREEMENT
Castro, Copyright (c) 2015,
The Regents of the University of California,
through Lawrence Berkeley National Laboratory
(subject to receipt of any required approvals from the U.S.
Dept. of Energy). All rights reserved."

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

(1) Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

(2) Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

(3) Neither the name of the University of California, Lawrence
Berkeley National Laboratory, U.S. Dept. of Energy nor the names of
its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

You are under no obligation whatsoever to provide any bug fixes,
patches, or upgrades to the features, functionality or performance of
the source code ("Enhancements") to anyone; however, if you choose to
make your Enhancements available either publicly, or directly to
Lawrence Berkeley National Laboratory, without imposing a separate
written license agreement for such Enhancements, then you hereby grant
the following license: a non-exclusive, royalty-free perpetual
license to install, use, modify, prepare derivative works, incorporate
into other computer software, distribute, and sublicense such
enhancements or derivative works thereof, in binary and source code
form.
*/
void
writeBuildInfo (){
std::string PrettyLine = std::string(78, '=') + "\n";
std::string OtherLine = std::string(78, '-') + "\n";
std::string SkipSpace = std::string(8, ' ');

// build information
std::cout << PrettyLine;
std::cout << " Emu Build Information\n";
std::cout << PrettyLine;

std::cout << "build date: " << buildInfoGetBuildDate() << "\n";
std::cout << "build machine: " << buildInfoGetBuildMachine() << "\n";
std::cout << "build dir: " << buildInfoGetBuildDir() << "\n";
std::cout << "AMReX dir: " << buildInfoGetAMReXDir() << "\n";

std::cout << "\n";

std::cout << "COMP: " << buildInfoGetComp() << "\n";
std::cout << "COMP version: " << buildInfoGetCompVersion() << "\n";

std::cout << "\n";

std::cout << "C++ compiler: " << buildInfoGetCXXName() << "\n";
std::cout << "C++ flags: " << buildInfoGetCXXFlags() << "\n";

std::cout << "\n";

std::cout << "Link flags: " << buildInfoGetLinkFlags() << "\n";
std::cout << "Libraries: " << buildInfoGetLibraries() << "\n";

std::cout << "\n";

for (int n = 1; n <= buildInfoGetNumModules(); n++) {
std::cout << buildInfoGetModuleName(n) << ": " << buildInfoGetModuleVal(n) << "\n";
}

std::cout << "\n";

const char* githash1 = buildInfoGetGitHash(1);
const char* githash2 = buildInfoGetGitHash(2);
if (strlen(githash1) > 0) {
std::cout << "Emu git describe: " << githash1 << "\n";
}
if (strlen(githash2) > 0) {
std::cout << "AMReX git describe: " << githash2 << "\n";
}

const char* buildgithash = buildInfoGetBuildGitHash();
const char* buildgitname = buildInfoGetBuildGitName();
if (strlen(buildgithash) > 0){
std::cout << buildgitname << " git describe: " << buildgithash << "\n";
}

std::cout << "\n"<<PrettyLine<<"\n";
}


void
writeJobInfo (const std::string& dir, const amrex::Geometry& geom)
{

// job_info file with details about the run
std::ofstream jobInfoFile;
std::string FullPathJobInfoFile = dir;
FullPathJobInfoFile += "/job_info";
jobInfoFile.open(FullPathJobInfoFile.c_str(), std::ios::out);

std::string PrettyLine = std::string(78, '=') + "\n";
std::string OtherLine = std::string(78, '-') + "\n";
std::string SkipSpace = std::string(8, ' ');

// job information
jobInfoFile << PrettyLine;
jobInfoFile << " Emu Job Information\n";
jobInfoFile << PrettyLine;

jobInfoFile << "number of MPI processes: " << ParallelDescriptor::NProcs() << "\n";
#ifdef _OPENMP
jobInfoFile << "number of threads: " << omp_get_max_threads() << "\n";
#endif

jobInfoFile << "\n\n";

// plotfile information
jobInfoFile << PrettyLine;
jobInfoFile << " Plotfile Information\n";
jobInfoFile << PrettyLine;

time_t now = time(0);

// Convert now to tm struct for local timezone
tm* localtm = localtime(&now);
jobInfoFile << "output date / time: " << asctime(localtm);

#ifdef AMREX_USE_GPU
// This output assumes for simplicity that every rank uses the
// same type of GPU.

jobInfoFile << PrettyLine;
jobInfoFile << "GPU Information: " << "\n";
jobInfoFile << PrettyLine;

jobInfoFile << "GPU model name: " << Gpu::Device::deviceName() << "\n";
jobInfoFile << "Number of GPUs used: " << Gpu::Device::numDevicesUsed() << "\n";

jobInfoFile << "\n\n";
#endif
jobInfoFile << "\n\n";


// build information
jobInfoFile << PrettyLine;
jobInfoFile << " Build Information\n";
jobInfoFile << PrettyLine;

jobInfoFile << "build date: " << buildInfoGetBuildDate() << "\n";
jobInfoFile << "build machine: " << buildInfoGetBuildMachine() << "\n";
jobInfoFile << "build dir: " << buildInfoGetBuildDir() << "\n";
jobInfoFile << "AMReX dir: " << buildInfoGetAMReXDir() << "\n";

jobInfoFile << "\n";

jobInfoFile << "COMP: " << buildInfoGetComp() << "\n";
jobInfoFile << "COMP version: " << buildInfoGetCompVersion() << "\n";

jobInfoFile << "\n";

jobInfoFile << "C++ compiler: " << buildInfoGetCXXName() << "\n";
jobInfoFile << "C++ flags: " << buildInfoGetCXXFlags() << "\n";

jobInfoFile << "\n";

jobInfoFile << "Fortran comp: " << buildInfoGetFName() << "\n";
jobInfoFile << "Fortran flags: " << buildInfoGetFFlags() << "\n";

jobInfoFile << "\n";

jobInfoFile << "Link flags: " << buildInfoGetLinkFlags() << "\n";
jobInfoFile << "Libraries: " << buildInfoGetLibraries() << "\n";

jobInfoFile << "\n";

for (int n = 1; n <= buildInfoGetNumModules(); n++) {
jobInfoFile << buildInfoGetModuleName(n) << ": " << buildInfoGetModuleVal(n) << "\n";
}

jobInfoFile << "\n";

const char* githash1 = buildInfoGetGitHash(1);
const char* githash2 = buildInfoGetGitHash(2);
if (strlen(githash1) > 0) {
jobInfoFile << "Emu git describe: " << githash1 << "\n";
}
if (strlen(githash2) > 0) {
jobInfoFile << "AMReX git describe: " << githash2 << "\n";
}

const char* buildgithash = buildInfoGetBuildGitHash();
const char* buildgitname = buildInfoGetBuildGitName();
if (strlen(buildgithash) > 0){
jobInfoFile << buildgitname << " git describe: " << buildgithash << "\n";
}

jobInfoFile << "\n\n";


// grid information
jobInfoFile << PrettyLine;
jobInfoFile << " Grid Information\n";
jobInfoFile << PrettyLine;

jobInfoFile << "geometry.is_periodic: ";
for (int idir = 0; idir < AMREX_SPACEDIM; idir++) {
jobInfoFile << geom.isPeriodic(idir) << " ";
}
jobInfoFile << "\n";

jobInfoFile << "geometry.coord_sys: " << geom.Coord() << "\n";

jobInfoFile << "geometry.prob_lo: ";
for (int idir = 0; idir < AMREX_SPACEDIM; idir++) {
jobInfoFile << geom.ProbLo(idir) << " ";
}
jobInfoFile << "\n";

jobInfoFile << "geometry.prob_hi: ";
for (int idir = 0; idir < AMREX_SPACEDIM; idir++) {
jobInfoFile << geom.ProbHi(idir) << " ";
}
jobInfoFile << "\n";

jobInfoFile << "amr.n_cell: ";
const int* domain_lo = geom.Domain().loVect();
const int* domain_hi = geom.Domain().hiVect();
for (int idir = 0; idir < AMREX_SPACEDIM; idir++) {
jobInfoFile << domain_hi[idir] - domain_lo[idir] + 1 << " ";
}
jobInfoFile << "\n\n";

jobInfoFile.close();

// now the external parameters
const int jobinfo_file_length = FullPathJobInfoFile.length();
Vector<int> jobinfo_file_name(jobinfo_file_length);

for (int i = 0; i < jobinfo_file_length; i++) {
jobinfo_file_name[i] = FullPathJobInfoFile[i];
}

}
5 changes: 5 additions & 0 deletions Source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ int main(int argc, char* argv[])
{
amrex::Initialize(argc,argv);

// write build information to screen
if (ParallelDescriptor::IOProcessor()) {
writeBuildInfo();
}

// by default amrex initializes rng deterministically
// this uses the time for a different run each time
amrex::InitRandom(ParallelDescriptor::MyProc()+time(NULL), ParallelDescriptor::NProcs());
Expand Down