Commit 2cf2a813 authored by Pillai, Himanshu's avatar Pillai, Himanshu
Browse files

Changed rule of make . You can either do make test for trace comparison or...

 Changed rule of make . You can either do make test for trace comparison or make compute for mpi executable generation
parent 1b8a59c6
......@@ -12,8 +12,10 @@
#include <fstream>
#include <algorithm>
#include <assert.h>
//#include <mpi.h>
#include <chrono>
#ifdef MPICOMP
#include <mpi.h>
#endif
#include "utils.hh"
#include "readers.hh"
......@@ -43,13 +45,16 @@ int main(int argc, char ** argv)
using ELM::Utils::n_pfts;
using ELM::Utils::n_grid_cells;
using ELM::Utils::n_max_times;
// int myrank, numprocs;
// double mytime, maxtime, mintime, avgtime;
// MPI_Init(&argc,&argv);
// MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
// MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
// MPI_Barrier(MPI_COMM_WORLD);
#ifdef MPICOMP
int myrank, numprocs;
double mytime, maxtime, mintime, avgtime;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
MPI_Barrier(MPI_COMM_WORLD);
#endif
// fixed magic parameters for now
const int ctype = 1;
......@@ -95,6 +100,8 @@ int main(int argc, char ** argv)
// output state by the pft
auto h2o_can = ELM::Utils::MatrixState(); h2o_can = 0.;
#ifdef TRACE
std::ofstream soln_file;
soln_file.open("test_CanopyHydrology_kern1_multiple.soln");
......@@ -106,8 +113,13 @@ int main(int argc, char ** argv)
<< "\t" << *min_max.first
<< "\t" << *min_max.second << std::endl;
}
#endif
auto start = high_resolution_clock::now();
// mytime = MPI_Wtime();
#ifdef MPICOMP
mytime = MPI_Wtime();
#endif
// main loop
// -- the timestep loop cannot/should not be parallelized
for (size_t t = 0; t != n_times; ++t) {
......@@ -133,7 +145,8 @@ int main(int argc, char ** argv)
//printf("%i %i %16.8g %16.8g %16.8g %16.8g %16.8g %16.8g\n", g, p, forc_rain(t,g), forc_snow(t,g), elai(g,p), esai(g,p), h2o_can(g,p), qflx_prec_intr[g]);
}
}
#ifdef TRACE
{
auto min_max = std::minmax_element(h2o_can.begin(), h2o_can.end());
soln_file << std::setprecision(16)
......@@ -141,21 +154,26 @@ int main(int argc, char ** argv)
<< "\t" << *min_max.first
<< "\t" << *min_max.second << std::endl;
}
#endif
}
// mytime = MPI_Wtime() - mytime;
auto stop = high_resolution_clock::now();
// std::cout <<"Timing from node "<< myrank << " is "<< mytime << "seconds." << std::endl;
// MPI_Reduce(&mytime, &maxtime, 1, MPI_DOUBLE,MPI_MAX, 0, MPI_COMM_WORLD);
// MPI_Reduce(&mytime, &mintime, 1, MPI_DOUBLE, MPI_MIN, 0,MPI_COMM_WORLD);
// MPI_Reduce(&mytime, &avgtime, 1, MPI_DOUBLE, MPI_SUM, 0,MPI_COMM_WORLD);
// if (myrank == 0) {
// avgtime /= numprocs;
// std::cout << "Min: "<< mintime << ", Max: " << maxtime << ", Avg: " <<avgtime << std::endl;
// }
#ifdef MPICOMP
mytime = MPI_Wtime() - mytime;
std::cout <<"Timing from node "<< myrank << " is "<< mytime << "seconds." << std::endl;
MPI_Reduce(&mytime, &maxtime, 1, MPI_DOUBLE,MPI_MAX, 0, MPI_COMM_WORLD);
MPI_Reduce(&mytime, &mintime, 1, MPI_DOUBLE, MPI_MIN, 0,MPI_COMM_WORLD);
MPI_Reduce(&mytime, &avgtime, 1, MPI_DOUBLE, MPI_SUM, 0,MPI_COMM_WORLD);
if (myrank == 0) {
avgtime /= numprocs;
std::cout << "Min: "<< mintime << ", Max: " << maxtime << ", Avg: " <<avgtime << std::endl;
}
MPI_Finalize();
#endif
auto duration = duration_cast<microseconds>(stop - start);
std::cout << "Time taken by function: "<< duration.count() << " microseconds" << std::endl;
// MPI_Finalize();
return 0;
}
......@@ -11,8 +11,10 @@
#include <iomanip>
#include <fstream>
#include <assert.h>
//#include <mpi.h>
#include <chrono>
#ifdef MPICOMP
#include <mpi.h>
#endif
#include "utils.hh"
#include "readers.hh"
......@@ -35,13 +37,16 @@ using MatrixForc = MatrixStatic<n_max_times,1>;
int main(int argc, char ** argv)
{
// int myrank, numprocs;
// double mytime, maxtime, mintime, avgtime;
// MPI_Init(&argc,&argv);
// MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
// MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
// MPI_Barrier(MPI_COMM_WORLD);
#ifdef MPICOMP
int myrank, numprocs;
double mytime, maxtime, mintime, avgtime;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
MPI_Barrier(MPI_COMM_WORLD);
#endif
// dimensions
const int n_months = 12;
const int n_pfts = 17;
......@@ -80,12 +85,16 @@ int main(int argc, char ** argv)
double qflx_snow_grnd_patch = 0.;
double qflx_rain_grnd = 0.;
#ifdef TRACE
std::ofstream soln_file;
soln_file.open("test_CanopyHydrology_kern1_single.soln");
soln_file << "Timestep, forc_rain, h2ocan, qflx_prec_grnd, qflx_prec_intr" << std::endl;
#endif
auto start = high_resolution_clock::now();
// mytime = MPI_Wtime();
#ifdef MPICOMP
mytime = MPI_Wtime();
#endif
for(size_t itime = 0; itime < n_times; itime += 1) {
// note this call puts all precip as rain for testing
......@@ -97,26 +106,29 @@ int main(int argc, char ** argv)
qflx_prec_intr, qflx_irrig, qflx_prec_grnd,
qflx_snwcp_liq, qflx_snwcp_ice,
qflx_snow_grnd_patch, qflx_rain_grnd);
#ifdef TRACE
soln_file << std::setprecision(16) << itime+1 << "\t" << total_precip << "\t" << h2ocan<< "\t" << qflx_prec_grnd << "\t" << qflx_prec_intr << std::endl;
#endif
}
// mytime = MPI_Wtime() - mytime;
auto stop = high_resolution_clock::now();
// std::cout <<"Timing from node "<< myrank << " is "<< mytime << "seconds." << std::endl;
#ifdef MPICOMP
mytime = MPI_Wtime() - mytime;
std::cout <<"Timing from node "<< myrank << " is "<< mytime << "seconds." << std::endl;
// /*compute max, min, and average timing statistics*/
// MPI_Reduce(&mytime, &maxtime, 1, MPI_DOUBLE,MPI_MAX, 0, MPI_COMM_WORLD);
// MPI_Reduce(&mytime, &mintime, 1, MPI_DOUBLE, MPI_MIN, 0,MPI_COMM_WORLD);
// MPI_Reduce(&mytime, &avgtime, 1, MPI_DOUBLE, MPI_SUM, 0,MPI_COMM_WORLD);
// if (myrank == 0) {
// avgtime /= numprocs;
// std::cout << "Min: "<< mintime << ", Max: " << maxtime << ", Avg: " <<avgtime << std::endl;
// }
MPI_Reduce(&mytime, &maxtime, 1, MPI_DOUBLE,MPI_MAX, 0, MPI_COMM_WORLD);
MPI_Reduce(&mytime, &mintime, 1, MPI_DOUBLE, MPI_MIN, 0,MPI_COMM_WORLD);
MPI_Reduce(&mytime, &avgtime, 1, MPI_DOUBLE, MPI_SUM, 0,MPI_COMM_WORLD);
if (myrank == 0) {
avgtime /= numprocs;
std::cout << "Min: "<< mintime << ", Max: " << maxtime << ", Avg: " <<avgtime << std::endl;
}
MPI_Finalize();
#endif
auto duration = duration_cast<microseconds>(stop - start);
std::cout << "Time taken by function: "<< duration.count() << " microseconds" << std::endl;
// MPI_Finalize();
return 0;
}
......@@ -12,7 +12,9 @@
#include <algorithm>
#include <assert.h>
#include <fstream>
//#include <mpi.h>
#ifdef MPICOMP
#include <mpi.h>
#endif
#include <chrono>
#include "utils.hh"
#include "readers.hh"
......@@ -49,13 +51,14 @@ int main(int argc, char ** argv)
using ELM::Utils::n_pfts;
using ELM::Utils::n_grid_cells;
using ELM::Utils::n_max_times;
// int myrank, numprocs;
// double mytime, maxtime, mintime, avgtime;
// MPI_Init(&argc,&argv);
// MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
// MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
// MPI_Barrier(MPI_COMM_WORLD);
#ifdef MPICOMP
int myrank, numprocs;
double mytime, maxtime, mintime, avgtime;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
MPI_Barrier(MPI_COMM_WORLD);
#endif
// fixed magic parameters for now
const int ctype = 1;
......@@ -137,26 +140,30 @@ int main(int argc, char ** argv)
auto frac_sno_eff = ELM::Utils::VectorColumn();
auto frac_sno = ELM::Utils::VectorColumn();
std::ofstream soln_file;
soln_file.open("test_CanopyHydrology_module.soln");
{
soln_file << "Time\t Total Canopy Water\t Min Water\t Max Water\t Total Snow\t Min Snow\t Max Snow\t Avg Frac Sfc\t Min Frac Sfc\t Max Frac Sfc" << std::endl;
auto min_max_water = std::minmax_element(h2ocan.begin(), h2ocan.end());
auto sum_water = std::accumulate(h2ocan.begin(), h2ocan.end(), 0.);
auto min_max_snow = std::minmax_element(h2osno.begin(), h2osno.end());
auto sum_snow = std::accumulate(h2osno.begin(), h2osno.end(), 0.);
auto min_max_frac_sfc = std::minmax_element(frac_h2osfc.begin(), frac_h2osfc.end());
auto avg_frac_sfc = std::accumulate(frac_h2osfc.begin(), frac_h2osfc.end(), 0.) / (frac_h2osfc.end() - frac_h2osfc.begin());
soln_file << std::setprecision(16)
<< 0 << "\t" << sum_water << "\t" << *min_max_water.first << "\t" << *min_max_water.second
<< "\t" << sum_snow << "\t" << *min_max_snow.first << "\t" << *min_max_snow.second
<< "\t" << avg_frac_sfc << "\t" << *min_max_frac_sfc.first << "\t" << *min_max_frac_sfc.second << std::endl;
}
#ifdef TRACE
std::ofstream soln_file;
soln_file.open("test_CanopyHydrology_module.soln");
{
soln_file << "Time\t Total Canopy Water\t Min Water\t Max Water\t Total Snow\t Min Snow\t Max Snow\t Avg Frac Sfc\t Min Frac Sfc\t Max Frac Sfc" << std::endl;
auto min_max_water = std::minmax_element(h2ocan.begin(), h2ocan.end());
auto sum_water = std::accumulate(h2ocan.begin(), h2ocan.end(), 0.);
auto min_max_snow = std::minmax_element(h2osno.begin(), h2osno.end());
auto sum_snow = std::accumulate(h2osno.begin(), h2osno.end(), 0.);
auto min_max_frac_sfc = std::minmax_element(frac_h2osfc.begin(), frac_h2osfc.end());
auto avg_frac_sfc = std::accumulate(frac_h2osfc.begin(), frac_h2osfc.end(), 0.) / (frac_h2osfc.end() - frac_h2osfc.begin());
soln_file << std::setprecision(16)
<< 0 << "\t" << sum_water << "\t" << *min_max_water.first << "\t" << *min_max_water.second
<< "\t" << sum_snow << "\t" << *min_max_snow.first << "\t" << *min_max_snow.second
<< "\t" << avg_frac_sfc << "\t" << *min_max_frac_sfc.first << "\t" << *min_max_frac_sfc.second << std::endl;
}
#endif
auto start = high_resolution_clock::now();
// mytime = MPI_Wtime();
#ifdef MPICOMP
mytime = MPI_Wtime();
#endif
// main loop
// -- the timestep loop cannot/should not be parallelized
for (size_t t = 0; t != n_times; ++t) {
......@@ -223,7 +230,7 @@ int main(int argc, char ** argv)
qflx_h2osfc2topsoi[g], frac_h2osfc[g]);
} // end grid cell loop
#ifdef TRACE
auto min_max_water = std::minmax_element(h2ocan.begin(), h2ocan.end());
auto sum_water = std::accumulate(h2ocan.begin(), h2ocan.end(), 0.);
......@@ -237,21 +244,24 @@ int main(int argc, char ** argv)
<< t+1 << "\t" << sum_water << "\t" << *min_max_water.first << "\t" << *min_max_water.second
<< "\t" << sum_snow << "\t" << *min_max_snow.first << "\t" << *min_max_snow.second
<< "\t" << avg_frac_sfc << "\t" << *min_max_frac_sfc.first << "\t" << *min_max_frac_sfc.second << std::endl;
#endif
} // end timestep loop
// mytime = MPI_Wtime() - mytime;
auto stop = high_resolution_clock::now();
// std::cout <<"Timing from node "<< myrank << " is "<< mytime << "seconds." << std::endl;
// MPI_Reduce(&mytime, &maxtime, 1, MPI_DOUBLE,MPI_MAX, 0, MPI_COMM_WORLD);
// MPI_Reduce(&mytime, &mintime, 1, MPI_DOUBLE, MPI_MIN, 0,MPI_COMM_WORLD);
// MPI_Reduce(&mytime, &avgtime, 1, MPI_DOUBLE, MPI_SUM, 0,MPI_COMM_WORLD);
// if (myrank == 0) {
// avgtime /= numprocs;
// std::cout << "Min: "<< mintime << ", Max: " << maxtime << ", Avg: " <<avgtime << std::endl;
// }
#ifdef MPICOMP
mytime = MPI_Wtime() - mytime;
std::cout <<"Timing from node "<< myrank << " is "<< mytime << "seconds." << std::endl;
MPI_Reduce(&mytime, &maxtime, 1, MPI_DOUBLE,MPI_MAX, 0, MPI_COMM_WORLD);
MPI_Reduce(&mytime, &mintime, 1, MPI_DOUBLE, MPI_MIN, 0,MPI_COMM_WORLD);
MPI_Reduce(&mytime, &avgtime, 1, MPI_DOUBLE, MPI_SUM, 0,MPI_COMM_WORLD);
if (myrank == 0) {
avgtime /= numprocs;
std::cout << "Min: "<< mintime << ", Max: " << maxtime << ", Avg: " <<avgtime << std::endl;
}
MPI_Finalize();
#endif
auto duration = duration_cast<microseconds>(stop - start);
std::cout << "Time taken by function: "<< duration.count() << " microseconds" << std::endl;
// MPI_Finalize();
return 0;
}
......@@ -2,9 +2,6 @@ ELM_BASE = ../../src
KERNEL_FOLDER = cc
ELM_ROOT = $(ELM_BASE)/$(KERNEL_FOLDER)
CXXFLAGS = -std=c++11 -g
include $(ELM_BASE)/config/Makefile.config
include $(ELM_BASE)/config/Makefile.rules
......@@ -12,22 +9,25 @@ TESTS = test_CanopyHydrology_kern1_single \
test_CanopyHydrology_kern1_multiple \
test_CanopyHydrology_module
TEST1 = mpi_CanopyHydrology_kern1_single \
mpi_CanopyHydrology_kern1_multiple \
mpi_CanopyHydrology_module
EXEC_TESTS = CanopyHydrology_kern1_single \
CanopyHydrology_kern1_multiple \
CanopyHydrology_module
.PHONY: links library test
.PHONY: links library test compute
default: all
#default: all
include $(ELM_BASE)/config/Makefile.logo
all: logo links library $(TESTS)
#all: logo links library $(TESTS)
test: $(EXEC_TESTS)
test: logo links library $(TESTS) $(EXEC_TESTS)
python ../compare_to_gold.py $(TESTS)
CanopyHydrology_kern1_single: test_CanopyHydrology_kern1_single
./test_CanopyHydrology_kern1_single > test_CanopyHydrology_kern1_single.stdout
......@@ -38,12 +38,17 @@ CanopyHydrology_module: test_CanopyHydrology_module
./test_CanopyHydrology_module > test_CanopyHydrology_module.stdout
test_%: %.cpp.o readers.hh utils.hh
$(CXX) -o $@ $< $(NETCDF_FLAGS)
test_%: %.cpp.o readers.hh utils.hh
$(CXX) -DTRACE -o $@ $< $(NETCDF_FLAGS)
compute: logo links library $(TEST1)
mpi_%: %.cpp.o readers.hh utils.hh
$(MPICXX) -DMPICOMP -o $@ $< $(NETCDF_FLAGS) $(MPI_INC_FLAGS) -L$(MPI_LIB_ROOT)/lib -lmpi
clean:
$(RM) test_* *.o
$(RM) test_* mpi_* *.o
allclean: clean
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment