tAdded cmd-line arg processing - sphere - GPU-based 3D discrete element method algorithm with optional fluid coupling
(HTM) git clone git://src.adamsgaard.dk/sphere
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
(DIR) commit af2de06847aae3374f42f0ba99feeb25149ae8dc
(DIR) parent ae9ebb8f0258bc86ba0f8a1ad2942f5000e90d73
(HTM) Author: Anders Damsgaard <adc@geo.au.dk>
Date: Tue, 30 Oct 2012 15:14:55 +0100
Added cmd-line arg processing
Diffstat:
M python/sphere.py | 12 ++++++++----
M python/tests.py | 10 +++++-----
M src/device.cu | 22 +++++++++++++---------
M src/main.cpp | 98 +++++++++++++++++++++----------
M src/sphere.cpp | 3 ++-
M src/sphere.h | 3 ++-
6 files changed, 96 insertions(+), 52 deletions(-)
---
(DIR) diff --git a/python/sphere.py b/python/sphere.py
t@@ -1285,13 +1285,17 @@ def visualize(project, method = 'energy', savefig = True, outformat = 'png'):
else:
plt.show()
-def run(project):
+def run(project, verbose=True, hideinputfile=False):
""" Execute sphere with target project
"""
- subprocess.call("cd ..; ./sphere_*_X86_64 " + project, shell=True)
-
+ quiet = ""
+ stdout = ""
+ if (verbose == False):
+ quiet = "-q "
+ if (hideinputfile == True):
+ stdout = " > /dev/null"
+ subprocess.call("cd ..; ./sphere_*_X86_64 "+ quiet + project + stdout, shell=True)
-
def status(project):
""" Check the status.dat file for the target project,
and return the last file numer.
(DIR) diff --git a/python/tests.py b/python/tests.py
t@@ -3,9 +3,9 @@ from sphere import *
def compare(first, second, string):
if (first == second):
- print(string + ":\tPassed")
+ print(string + "\tPassed")
else:
- print(string + ":\tFailed")
+ print(string + "\tFailed")
#### Input/output tests ####
t@@ -28,12 +28,12 @@ orig.writebin("orig.bin", verbose=False)
# Test Python IO routines
py = Spherebin()
py.readbin("orig.bin", verbose=False)
-compare(orig, py, "Python IO")
+compare(orig, py, "Python IO:")
# Test C++ IO routines
-run("python/orig.bin")
+run("python/orig.bin", verbose=False, hideinputfile=True)
cpp = Spherebin()
cpp.readbin("../output/orig.output0.bin", verbose=False)
-compare(orig, cpp, "C++ IO ")
+compare(orig, cpp, "C++ IO: ")
(DIR) diff --git a/src/device.cu b/src/device.cu
t@@ -46,22 +46,26 @@ __host__ void DEM::initializeGPU(void)
std::cerr << "\nERROR: No CUDA-enabled devices availible. Bye.\n";
exit(EXIT_FAILURE);
} else if (devicecount == 1) {
- cout << "\nSystem contains 1 CUDA compatible device.\n";
+ if (verbose == 1)
+ cout << "\nSystem contains 1 CUDA compatible device.\n";
} else {
- cout << "\nSystem contains " << devicecount << " CUDA compatible devices.\n";
+ if (verbose == 1)
+ cout << "\nSystem contains " << devicecount << " CUDA compatible devices.\n";
}
cudaGetDeviceProperties(&prop, cudadevice);
cudaDriverGetVersion(&cudaDriverVersion);
cudaRuntimeGetVersion(&cudaRuntimeVersion);
- cout << "Using CUDA device ID: " << cudadevice << "\n";
- cout << " - Name: " << prop.name << ", compute capability: "
- << prop.major << "." << prop.minor << ".\n";
- cout << " - CUDA Driver version: " << cudaDriverVersion/1000
- << "." << cudaDriverVersion%100
- << ", runtime version " << cudaRuntimeVersion/1000 << "."
- << cudaRuntimeVersion%100 << "\n\n";
+ if (verbose == 1) {
+ cout << "Using CUDA device ID: " << cudadevice << "\n";
+ cout << " - Name: " << prop.name << ", compute capability: "
+ << prop.major << "." << prop.minor << ".\n";
+ cout << " - CUDA Driver version: " << cudaDriverVersion/1000
+ << "." << cudaDriverVersion%100
+ << ", runtime version " << cudaRuntimeVersion/1000 << "."
+ << cudaRuntimeVersion%100 << "\n\n";
+ }
// Comment following line when using a system only containing exclusive mode GPUs
cudaChooseDevice(&cudadevice, &prop);
(DIR) diff --git a/src/main.cpp b/src/main.cpp
t@@ -26,43 +26,77 @@
// successfully, and 1 if an error occured which caused the program to crash.
int main(const int argc, const char *argv[])
{
+ // Default values
+ int verbose = 1;
+ int checkConstantVals = 0;
+ int render = 0;
+ int nfiles = 0; // number of input files
- // LOCAL VARIABLE DECLARATIONS
- if(!argv[1] || argc != 2) {
- std::cerr << "Error: Specify input binary file, e.g. "
- << argv[0] << " input/test.bin" << std::endl;
- return 1; // Return unsuccessful exit status
- }
- //char *inputbin = argv[1]; // Input binary file read from command line argument
- std::string inputbin = argv[1];
+ // Process input parameters
+ int i;
+ for (i=1; i<argc; ++i) { // skip argv[0]
- int verbose = 1;
- int checkVals = 1;
-
- if (verbose == 1) {
- // Opening cerenomy with fancy ASCII art
- std::cout << ".-------------------------------------.\n"
- << "| _ Compiled for " << ND << "D |\n"
- << "| | | |\n"
- << "| ___ _ __ | |__ ___ _ __ ___ |\n"
- << "| / __| '_ \\| '_ \\ / _ \\ '__/ _ \\ |\n"
- << "| \\__ \\ |_) | | | | __/ | | __/ |\n"
- << "| |___/ .__/|_| |_|\\___|_| \\___| |\n"
- << "| | | |\n"
- << "| |_| Version: " << VERS << " |\n"
- << "`-------------------------------------´\n";
- }
+ std::string argvi = std::string(argv[i]);
+
+ // Display help if requested
+ if (argvi == "-h" || argvi == "--help") {
+ std::cout << argv[0] << ": particle dynamics simulator\n"
+ << "Usage: " << argv[0] << " [OPTION[S]]... [FILE1 ...]\nOptions:\n"
+ << "-h, --help\t\tprint help\n"
+ << "-V, --version\t\tprint version information and exit\n"
+ << "-q, --quiet\t\tsuppress status messages to stdout\n"
+ << "-r, --render\t\trender input files instead of simulating temporal evolution\n"
+ << "-cc, --check-constants\t\tcheck values in constant GPU memory" << std::endl;
+ return 0; // Exit with success
+ }
+
+ // Display version with fancy ASCII art
+ else if (argvi == "-V" || argvi == "--version") {
+ std::cout << ".-------------------------------------.\n"
+ << "| _ Compiled for " << ND << "D |\n"
+ << "| | | |\n"
+ << "| ___ _ __ | |__ ___ _ __ ___ |\n"
+ << "| / __| '_ \\| '_ \\ / _ \\ '__/ _ \\ |\n"
+ << "| \\__ \\ |_) | | | | __/ | | __/ |\n"
+ << "| |___/ .__/|_| |_|\\___|_| \\___| |\n"
+ << "| | | |\n"
+ << "| |_| Version: " << VERS << " |\n"
+ << "`-------------------------------------´\n";
+ return 0;
+ }
+
+ else if (argvi == "-q" || argvi == "--quiet")
+ verbose = 0;
- std::cout << "Input file: " << inputbin << std::endl;
-
- // Create DEM class, read data from input binary, check values
- DEM dem(inputbin, verbose, checkVals);
+ else if (argvi == "-r" || argvi == "--render")
+ render = 1;
- // Start iterating through time
- dem.startTime();
+ else if (argvi == "-cc" || argvi == "--check-constants")
+ checkConstantVals = 1;
+
+ // The rest of the values must be input binary files
+ else {
+ nfiles++;
+
+ std::cout << argv[0] << ": processing input file: " << argvi << std::endl;
+
+ // Create DEM class, read data from input binary, check values
+ DEM dem(argvi, verbose, checkConstantVals, render);
+
+ // Start iterating through time, unless user chose to render image
+ if (render != 0)
+ dem.startTime();
+ }
+ }
+
+ // Check whether there are input files specified
+ if (!argv[0] || argc == 1 || nfiles == 0) {
+ std::cerr << argv[0] << ": missing input binary file\n"
+ << "See `" << argv[0] << " --help` for more information"
+ << std::endl;
+ return 1; // Return unsuccessful exit status
+ }
- // Terminate execution
- std::cout << "\nBye!\n";
return 0; // Return successfull exit status
}
// END OF FILE
(DIR) diff --git a/src/sphere.cpp b/src/sphere.cpp
t@@ -12,7 +12,8 @@
// and reports the values
DEM::DEM(const std::string inputbin,
const int verbosity,
- const int checkVals)
+ const int checkVals,
+ const int render)
: verbose(verbosity)
{
using std::cout;
(DIR) diff --git a/src/sphere.h b/src/sphere.h
t@@ -78,7 +78,8 @@ class DEM {
// Constructor, some parameters with default values
DEM(std::string inputbin,
const int verbosity = 1,
- const int checkVals = 1);
+ const int checkVals = 1,
+ const int render = 0);
// Destructor
~DEM(void);