Skip to content

Commit

Permalink
Now the project uses CMake for compiling, 3.8 required
Browse files Browse the repository at this point in the history
  • Loading branch information
RaulPPelaez committed Dec 4, 2018
1 parent 64b4e19 commit 519d7bb
Show file tree
Hide file tree
Showing 20 changed files with 204 additions and 117 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
*~
bin/
bin/rdf
build/
*.o
*.depend
*.depend
defines.h
gitversion.h
49 changes: 49 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
cmake_minimum_required (VERSION 3.8)
include(CheckLanguage)
include(CheckCXXCompilerFlag)
project (RadialDistributionFunction CXX)
#set( CMAKE_VERBOSE_MAKEFILE on )
set (RadialDistributionFunction_VERSION_MAJOR \"2\")
set (RadialDistributionFunction_VERSION_MINOR \"0\")

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS OFF)

#I want only std=c++11, not c++0x
#check_cxx_compiler_flag("-std=c++11" HAS_CXX11)
if(NOT HAS_CXX11)
message(FATAL_ERROR "C++ compiler needs to allow c++11 standard")
endif()

option(USE_BOOST "Use Boost-qi for reading, highly improves reading performance" OFF)
option(DONT_USE_CUDA "Dont compile in hybrid CPU/GPU mode, requires nvcc" ON)

if(NOT DONT_USE_CUDA)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
set(USE_CUDA ON)

set(CMAKE_CUDA_STANDARD 11)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
set(CMAKE_CUDA_SEPARABLE_COMPILATION OFF)

execute_process(COMMAND bash ${PROJECT_SOURCE_DIR}/cmake/listArchs.sh OUTPUT_VARIABLE ARCHS)
set(CMAKE_CUDA_FLAGS ${ARCHS} ${CMAKE_CUDA_FLAGS})
endif()
endif()


#set(CMAKE_CXX_FLAGS "-Wall -Wextra -fPIC" ${CMAKE_CXX_FLAGS})

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

include_directories(src/third_party)
add_subdirectory(src)

17 changes: 0 additions & 17 deletions Makefile

This file was deleted.

13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ rdf can compute in 4 modes:
rdf will choose a between GPU/CPU according to the number of particles (unless specified with -device) and will choose NBody/Neighbour list according to the number of particles and the factor L/rcut.
## COMPILE WITH

```bash
$ mkdir build; cd build; cmake ..; make
```
$ make
```
You may have to change the Makefile to adequate it to the CUDA target architechture, currently set to -arch=sm_35

Use:
You can specify some options in CMAKE, (use ccmake). For example, set DONT_USE_CUDA to ON to compile in CPU only mode (does not need nvcc).

You can run some test after compiling with:
```
$ make test
$ cd test; make test
```

To compile and run several test using random numbers, the resulting rdf will be compared between CPU and GPU implementations. Which should be numerically identical.
This will run several test using random numbers, the resulting rdf will be compared between CPU and GPU implementations. Which should be numerically identical.

## SYNOPSYS

Expand Down
1 change: 1 addition & 0 deletions cmake/gitversion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo \"$(git rev-parse HEAD)\"
10 changes: 10 additions & 0 deletions cmake/listArchs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

nvcc --help |
grep '\-\-gpu-code' -A1000 |
grep -Po 'compute_\K[0-9]+' |
sort |
uniq |
awk '{print "-gencode arch=compute_"$1",code=sm_"$1}' |
paste -sd" " | tr '\n' ' '


21 changes: 21 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required (VERSION 3.8)
add_executable(RadialDistributionFunction main.cpp)
if(NOT DONT_USE_CUDA)
SET_SOURCE_FILES_PROPERTIES(main.cpp PROPERTIES LANGUAGE CUDA)
endif()

set_target_properties(RadialDistributionFunction PROPERTIES OUTPUT_NAME "rdf")

install(TARGETS RadialDistributionFunction RUNTIME DESTINATION bin)

configure_file ( "defines.h.in" ${CMAKE_CURRENT_SOURCE_DIR}/defines.h )


find_package(Git)
if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(COMMAND bash ${PROJECT_SOURCE_DIR}/cmake/gitversion.sh OUTPUT_VARIABLE GITCOMMIT)
else()
SET(GITCOMMIT "unknown")
endif()

configure_file("gitversion.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/gitversion.h")
55 changes: 0 additions & 55 deletions src/Makefile

This file was deleted.

4 changes: 4 additions & 0 deletions src/NeighbourListCPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#ifndef NEIGHBOURLISTCPU_H
#define NEIGHBOURLISTCPU_H

#include"vector_algebra.cuh"
#include<vector>
#include"config.h"
#include"utils.cuh"
namespace gdr{
class NeighbourListCPU{
std::vector<int> head, list;
Expand Down
9 changes: 5 additions & 4 deletions src/NeighbourListGPU.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ TODO:
100- Make a better separation between neighbour list and transverse schemes in this file
100- Improve needsRebuild
*/
#ifndef CELLLIST_CUH
#define CELLLIST_CUH
#ifndef NEIGHBOURLISTGPU_CUH
#define NEIGHBOURLISTGPU_CUH


#include"ParticleSorter.cuh"
#include"vector_algebra.cuh"
#include"config.h"
#include"utils.cuh"

#include"ParticleSorter.cuh"
#include<thrust/device_vector.h>
#include<thrust/host_vector.h>
#include<third_party/cub/cub.cuh>
#include"third_party/cub/cub.cuh"

#include<limits>

Expand Down
2 changes: 1 addition & 1 deletion src/ParticleSorter.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ REFERENCES:
#include"utils.cuh"
#include<thrust/device_vector.h>
#include<thrust/host_vector.h>
#include<third_party/cub/cub.cuh>
#include"third_party/cub/cub.cuh"

namespace gdr{

Expand Down
12 changes: 8 additions & 4 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#include"vector_algebra.cuh"
#include<unistd.h>
#include<fstream>
#include"utils.cuh"
#include<string.h>
#include<iostream>
#include<memory>
#include"defines.h"
namespace gdr{

struct Configuration{
Expand Down Expand Up @@ -117,15 +122,14 @@ namespace gdr{

printf(" Raul P. Pelaez 2017.\n");
printf(" \n");
printf("RadialDistributionFunction v%s.%s\n",
RadialDistributionFunction_VERSION_MAJOR,
RadialDistributionFunction_VERSION_MINOR);
printf("Compiled from git commit: %s\n", GITVERSION);
printf("NAME \n");
printf("rdf - Computes the Radial Distribution Function (RDF) of a group of positions in a file,\n");
printf(" averages it for all snapshots in the file. \n");
printf(" \n");
printf("COMPILE WITH \n");
printf(" \n");
printf("$ nvcc -arch=sm_52 -std=c++11 -O3 rdf.cu \n");
printf(" \n");
printf("SYNOPSYS \n");
printf(" \n");
printf("rdf [OPTIONS]... [FILE]... \n");
Expand Down
10 changes: 10 additions & 0 deletions src/defines.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef RDFCONFIG_H
#define RDFCONFIG_H
#define RadialDistributionFunction_VERSION_MAJOR @RadialDistributionFunction_VERSION_MAJOR@
#define RadialDistributionFunction_VERSION_MINOR @RadialDistributionFunction_VERSION_MINOR@
#cmakedefine USE_BOOST
#cmakedefine USE_CUDA
#ifdef USE_CUDA
#define GPUMODE
#endif
#endif
4 changes: 4 additions & 0 deletions src/gitversion.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ifndef GITVERSION_H
#define GITVERSION_H
#define GITVERSION @GITCOMMIT@
#endif
23 changes: 13 additions & 10 deletions src/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,42 @@
#include<fstream>
#include<sstream>
#include<string>
#include<memory>
#include<iostream>

namespace gdr{
//Reads numbers from a file or standard input line by line
class InputParse{
shared_ptr<istream> input;
string currentLine;
std::shared_ptr<std::istream> input;
std::string currentLine;
public:
//Read from stdin by default
InputParse(){ }

//Take input from cin
bool open(){
//The lambda ensures cin is not deleted
input.reset(&cin, [](...){});
input.reset(&std::cin, [](...){});

if(!input->good()){
cerr<<"ERROR: Unable to read from stdin!"<<endl;
std::cerr<<"ERROR: Unable to read from stdin!"<<std::endl;
return false;
}
return true;
}
//Open and read from a file
bool open(string fileName){
input.reset(new ifstream(fileName.c_str()));
bool open(std::string fileName){
input.reset(new std::ifstream(fileName.c_str()));
if(!input->good()){
cerr<<"ERROR: Unable to open file!"<<endl;
std::cerr<<"ERROR: Unable to open file!"<<std::endl;
return false;
}
return true;
}

//Reads a line from input
string goToNextLine(){
if(!input) cerr<<"ERROR: No open file!"<<endl;
std::string goToNextLine(){
if(!input) std::cerr<<"ERROR: No open file!"<<std::endl;
getline(*input, currentLine);
return currentLine;
}
Expand All @@ -49,7 +52,7 @@ namespace gdr{
void parseNextLine(Iterator numbersInLine, int numberColumnsToRead){
this->goToNextLine();
//This could be faster
stringstream ss;
std::stringstream ss;
ss.str(currentLine);
for(int i=0; i<numberColumnsToRead; i++){
ss>>numbersInLine[i];
Expand Down
Loading

0 comments on commit 519d7bb

Please sign in to comment.