Skip to content

Commit

Permalink
Merge branch 'feature_adaptive'
Browse files Browse the repository at this point in the history
  • Loading branch information
DamynChipman committed Apr 20, 2022
2 parents 4d52e12 + 25de742 commit db1451c
Show file tree
Hide file tree
Showing 40 changed files with 803 additions and 1,839 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ set(CMAKE_CXX_STANDARD 11)
add_subdirectory(external)

# -- source files
add_subdirectory(src)
add_subdirectory(src)

# -- examples
add_subdirectory(examples)
10 changes: 5 additions & 5 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ endif()
# ----------------------------------
# HPS library and examples
# ----------------------------------
if(TARGET FORESTCLAW::HPS)
# if(TARGET FORESTCLAW::HPS)

# Hello world program
add_subdirectory(hello)
# add_subdirectory(hello)

# Simple
add_subdirectory(simple)

# Poisson's equation (timing and error testing)
add_subdirectory(poisson)
# Adaptive Testing
# add_subdirectory(adaptive_testing)

endif()
# endif()

8 changes: 5 additions & 3 deletions examples/simple/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ add_executable(simple
)

target_include_directories(simple PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
)

target_link_libraries(simple PRIVATE
FORESTCLAW::HPS
forestclaw clawpatch hps
)

configure_file(fclaw_options.ini fclaw_options.ini)
configure_file(scripts/run_timing.py run_timing.py)
configure_file(scripts/run_timing.py run_timing.py)
configure_file(scripts/hps_simple_analysis.py hps_simple_analysis.py)
2 changes: 1 addition & 1 deletion examples/simple/fclaw2d_clawpatch_user_exceeds_th.f90
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ integer function user_exceeds_th(blockno,&
integer :: refine

refine = 0
if (xc .gt. 0 .and. yc .gt. 0) then
if (xc .gt. 0) then
refine = 1
endif

Expand Down
12 changes: 9 additions & 3 deletions examples/simple/fclaw_options.ini
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
rhs-fields = 1
interp_stencil_width = 3
ghost_patch_pack_aux = true
refinement-criteria = value
refinement-criteria = user
[hps]
boundary_conditions = 1 1 1 1
ascii-out = true
Expand All @@ -91,8 +91,8 @@
[user]
example = 0
alpha = 20
x0 = 0.5
y0 = 0.5
x0 = 0
y0 = 0
a = 2
b = 2
eps-disk = 0.015625
Expand All @@ -102,6 +102,12 @@
r0-polar = 0.25
r1-polar = 0.35
n-polar = 4
# m-polar = 4
# x0-polar = -0.4 0.4 -0.6 0.5
# y0-polar = -0.4 0.4 0.6 -0.7
# r0-polar = 0.2 0.35 0.425 0.25
# r1-polar = 0.2 0.45 0.3 0.6
# n-polar = 4 6 5 8
[Arguments]
count = 1
0 = fclaw_options.ini
32 changes: 3 additions & 29 deletions examples/simple/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,6 @@ fclaw2d_domain_t* create_domain(sc_MPI_Comm mpicomm, fclaw_options_t* fclaw_opt)
return domain;
}

double init_fn(p4est_t* p4est, void* user) {
return 1.0;
}

void merge_fn(double& p, double& c0, double& c1, double& c2, double& c3) {
p = c0 + c1 + c2 + c3;
}

void split_fn(double& p, double& c0, double& c1, double& c2, double& c3) {
c0 = p / 4;
c1 = p / 4;
c2 = p / 4;
c3 = p / 4;
}

void visit_print(double& d) {
printf("node data: d = %f\n", d);
}

static
void run_program(fclaw2d_global_t* glob)
{
Expand Down Expand Up @@ -99,28 +80,21 @@ void run_program(fclaw2d_global_t* glob)

/* Compute sum of RHS; reset error accumulators */
int init_flag = 1;
// fclaw2d_diagnostics_gather(glob,init_flag);
fclaw2d_diagnostics_gather(glob,init_flag);
init_flag = 0;

/* Output rhs */
int Frame = 0;
// fclaw2d_output_frame(glob,Frame);
fclaw2d_output_frame(glob,Frame);

/* Solve the elliptic problem */
fclaw2d_elliptic_solve(glob);

/* Compute error, compute conservation */
fclaw2d_diagnostics_gather(glob, init_flag);

/* Reset to time FISHPACK */
// init_flag = 1;
// fclaw2d_diagnostics_gather(glob, init_flag);

/* Run FISHPACK */


/* Output solution */
Frame = 0;
Frame = 1;
fclaw2d_output_frame(glob,Frame);

/* ---------------------------------------------------------------
Expand Down
181 changes: 181 additions & 0 deletions examples/simple/scripts/hps_simple_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@

# Imports
import sys
import shutil
import os
import subprocess

import numpy as np

import matplotlib as mpl
import matplotlib.pyplot as plt

class SimpleResults:
def __init__(self):
self.solver = 'HPS'
self.L1Error = 0
self.L2Error = 0
self.LIError = 0
self.setupTime = 0
self.buildTime = 0
self.upwardsTime = 0
self.solveTime = 0
self.ellipticTime = 0
self.nLevels = 0
self.nCells = 0

def runSimple(nCellsSide, minLevel, maxLevel, iExample, outputFilename, runFISHPACK='F'):
commands = [
'./simple',
'fclaw_options.ini',
'--report-timing', 'T',
'--report-timing-verbosity', 'all',
'--minlevel', str(minLevel),
'--maxlevel', str(maxLevel),
'--clawpatch:mx', str(nCellsSide),
'--clawpatch:my', str(nCellsSide),
'--clawpatch:refinement-criteria=value',
'--user:example', str(iExample),
'--hps:only_patch_solver={}'.format(runFISHPACK)
]
with open(outputFilename, 'w') as out_file:
subprocess.run(commands, stdout=out_file)

return

def extractResults(outputFilename):

results = SimpleResults()

# Open output
with open(outputFilename, 'r') as in_file:

# Read lines to get line number for useful info
lines = in_file.readlines()
for line_number, line in enumerate(lines):
if '[fclaw] error[0] =' in line:
error_line_number = line_number
if '[libsc] Statistics for ELLIPTIC_SOLVE' in line:
elliptic_line_number = line_number + 2
if '[libsc] Statistics for EXTRA1' in line:
setup_time_line_number = line_number + 2
if '[libsc] Statistics for EXTRA2' in line:
build_time_line_number = line_number + 2
if '[libsc] Statistics for EXTRA3' in line:
upwards_time_line_number = line_number + 2
if '[libsc] Statistics for EXTRA4' in line:
solve_time_line_number = line_number + 2

# Extract results
results.L1Error = float(lines[error_line_number].split()[3])
results.L2Error = float(lines[error_line_number].split()[4])
results.LIError = float(lines[error_line_number].split()[5])
results.setupTime = float(lines[setup_time_line_number].split()[5])
results.buildTime = float(lines[build_time_line_number].split()[5])
results.upwardsTime = float(lines[upwards_time_line_number].split()[5])
results.solveTime = float(lines[solve_time_line_number].split()[5])
results.ellipticTime = float(lines[elliptic_line_number].split()[5])

return results

def writeResults(results, file):

line = ''
line += '{},'.format(results.solver)
line += '{},'.format(results.nLevels)
line += '{},'.format(results.nCells)
line += '{},'.format(results.L1Error)
line += '{},'.format(results.L2Error)
line += '{},'.format(results.LIError)
line += '{},'.format(results.setupTime)
line += '{},'.format(results.buildTime)
line += '{},'.format(results.upwardsTime)
line += '{},'.format(results.solveTime)
line += '{},'.format(results.ellipticTime)
line += '\n'

file.write(line)

# Main function
def main(args):

nCellsSideArray = 2**np.arange(4, 9)
nLevelsRefinementArray = np.arange(0, 6)
iExample = 4

nRuns = len(nCellsSideArray) * len(nLevelsRefinementArray)

resultsFileName = 'adaptive_hps_timing_and_error.csv'
columnNames = [
'solver',
'nLevels',
'nCells',
'L1Error',
'L2Error',
'LIError',
'setupTime',
'buildTime',
'upwardsTime',
'solveTime',
'ellipticTime'
]

try:
os.remove(resultsFileName)
except FileNotFoundError:
pass

print('Begin HPS runs...')
runCounter = 1
for n in nCellsSideArray:
for l in nLevelsRefinementArray:

print('Running `simple` - run {} of {}: n = {}, l = {}'.format(runCounter, nRuns, n, l))

# Run simple
outputFileName = 'simple_n{}_l{}_e{}.txt'.format(n, l, iExample)
runSimple(n, 1, l, iExample, outputFileName)

# Extract necessary data
results = extractResults(outputFileName)
results.nCells = n
results.nLevels = l
results.solver = 'HPS'

with open(resultsFileName, 'a') as file:
if runCounter == 1:
[file.write('{},'.format(c)) for c in columnNames]
file.write('\n')
writeResults(results, file)

runCounter += 1
print('Done!')

print('Begin FISHPACK runs...')
runCounter = 1
for n in nCellsSideArray:
for l in nLevelsRefinementArray:

print('Running `FISHPACK` - run {} of {}: n = {}, l = {}'.format(runCounter, nRuns, n, l))

# Run simple
nCellsFISHPACK = n * 2**(l)
outputFileName = 'FISHPACK_n{}_l{}_e{}.txt'.format(n, l, iExample)
runSimple(nCellsFISHPACK, 0, 0, iExample, outputFileName, runFISHPACK='T')

# Extract necessary data
results = extractResults(outputFileName)
results.nCells = nCellsFISHPACK
results.nLevels = 1
results.solver = 'FISHPACK'

with open(resultsFileName, 'a') as file:
writeResults(results, file)

runCounter += 1
print('Done!')

# Run main
if __name__ == '__main__':

main(sys.argv)
2 changes: 1 addition & 1 deletion examples/simple/simple_user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void simple_link_solvers(fclaw2d_global_t *glob)
/* HPS virtual table : Initialize RHS */
fc2d_hps_vtable_t* hps_vt = fc2d_hps_vt();
hps_vt->fort_rhs = &SIMPLE_FORT_RHS;
// hps_vt->fort_qexact = &SIMPLE_FORT_QEXACT_COMPLETE; // why does this give linker errors?
hps_vt->fort_qexact = &SIMPLE_FORT_QEXACT_COMPLETE; // why does this give linker errors?

/* Clawpatch : Compute the error */
fclaw2d_clawpatch_vtable_t *clawpatch_vt = fclaw2d_clawpatch_vt();
Expand Down
8 changes: 4 additions & 4 deletions examples/simple/simple_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void simple_link_solvers(fclaw2d_global_t *glob);

void SETPROB();

#define SIMPLE_FORT_QEXACT_COMPLETE FCLAW_F77_FUNC(simple_fort_qexact_rhs,SIMPLE_FORT_QEXACT_COMPLETE)
#define SIMPLE_FORT_QEXACT_COMPLETE FCLAW_F77_FUNC(simple_qexact_complete,SIMPLE_FORT_QEXACT_COMPLETE)

void SIMPLE_FORT_QEXACT_COMPLETE(const int* example,
const double* x, const double* y,
Expand All @@ -89,9 +89,9 @@ void SIMPLE_FORT_RHS(const int* blockno, const int* mbc, const int* mx,

#define SIMPLE_COMPUTE_ERROR FCLAW_F77_FUNC(simple_compute_error,SIMPLE_COMPUTE_ERROR)

void SIMPLE_COMPUTE_ERROR(const int* blockno, const int *mx, const int *my, const int* mbc, const int* mfields,
const double *dx, const double *dy, const double *xlower,
const double *ylower, const double *t, double q[],
void SIMPLE_COMPUTE_ERROR(int* blockno, int *mx, int *my, int* mbc, int* mfields,
double *dx, double *dy, double *xlower,
double *ylower, double *t, double q[],
double error[], double soln[]);


Expand Down
25 changes: 0 additions & 25 deletions include/HPS/fc2d_hps.hpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,3 @@
/*
Copyright (c) 2019-2021 Carsten Burstedde, Donna Calhoun, Damyn Chipman
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* 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.
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 HOLDER 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.
*/

#ifndef FC2D_HPS_H
#define FC2D_HPS_H

Expand Down
Loading

0 comments on commit db1451c

Please sign in to comment.