10 int main(
int argc,
char **argv){
15 float migration_rate = 0.005;
16 run_migration_equilibrium_simulation(a,migration_rate);
21 std::ofstream outfile;
22 outfile.open(
"bfile.dat");
27 std::cout<<std::endl<<
"mutations in first time sample: " << b.num_mutations_time_sample(0) <<std::endl<<
"mutations in final time sample: " << b.maximal_num_mutations() << std::endl;
30 std::cout<<std::endl<<
"mutations from burn-in simulation\n";
31 int mutation_range_begin = 0;
int mutation_range_end = mutation_range_begin+10;
32 std::cout<<
"ID\tstart frequency pop 1\tstart frequency pop 2\tfinal frequency pop 1\tfinal frequency pop 2"<<std::endl;
33 for(
int i = mutation_range_begin; i < mutation_range_end; i++){ std::cout<<b.mutation_ID(i)<<
"\t"<<b.frequency(0,0,i)<<
"\t"<<b.frequency(0,1,i)<<
"\t"<<b.frequency(1,0,i)<<
"\t"<<b.frequency(1,1,i)<<std::endl; }
36 std::cout<<std::endl<<
"mutations from scenario simulation\n";
37 mutation_range_begin = b.num_mutations_time_sample(0); mutation_range_end = mutation_range_begin+10;
38 std::cout<<
"ID\tstart frequency pop 1\tstart frequency pop 2\tfinal frequency pop 1\tfinal frequency pop 2"<<std::endl;
39 for(
int i = mutation_range_begin; i < mutation_range_end; i++){ std::cout<<b.mutation_ID(i)<<
"\t"<<b.frequency(0,0,i)<<
"\t"<<b.frequency(0,1,i)<<
"\t"<<b.frequency(1,0,i)<<
"\t"<<b.frequency(1,1,i)<<std::endl; }
int seed2
random number seed 2 of 2
control and output data structure for GO_Fish simulation
void reset()
deletes all memory held by allele_trajectories, resets constants to default
int num_time_samples()
returns number of time samples taken during simulation run
int seed1
random number seed 1 of 2
sim_constants sim_input_constants
constants for initializing the next simulation
The simulation starts off blank, running a burn-in simulation until equilibrium is reached, then running the scenario of interest.
31 run_sim(a,mutation,demography,migration,deleterious,inbreeding,dominance,dont_preserve,dont_sample);
41 run_sim(a,mutation,demography,migration,selection_model,inbreeding,dominance,dont_preserve,sample_strategy,a);
functor: models selection coefficient s as a constant across populations and over time ...
int prev_sim_sample
time sample of previous simulation to use for initializing current simulation
functor: turns sampling and preserving off (for every generation except the final one which is always...
control and output data structure for GO_Fish simulation
int compact_interval
how often to compact the simulation and remove fixed or lost mutations
functor: single, constant population size (N individuals) across populations and over time ...
functor: one population, pop, has a different, selection function, s_pop, all other have function s ...
Namespace of functions for controlling GO_Fish simulations.
int num_populations
number of populations in simulation
functor: models parameter p as a constant across populations and over time
functor: migration flows at rate m from pop i to pop j =/= i and 1-(num_pop-1)*m for i == j ...
functor: turns sampling and preserving on (for every generation except the final one which is always ...
GO Fish Simulation API (contains namespaces GO_Fish and Sim_Model)
__host__ void run_sim(allele_trajectories &all_results, const Functor_mutation mu_rate, const Functor_demography demography, const Functor_migration mig_prop, const Functor_selection sel_coeff, const Functor_inbreeding FI, const Functor_dominance dominance, const Functor_preserve preserve_mutations, const Functor_timesample take_sample)
runs a single-locus Wright-Fisher simulation specified by the given simulation functions and sim_cons...
float num_sites
number of sites in simulation
bool init_mse
true: initialize simulation in mutation_selection_equilibrium; false: initialize blank simulation or ...
Namespace for single-locus, forward, Monte-Carlo Wright-Fisher simulation and output data structures...
sim_constants sim_input_constants
constants for initializing the next simulation
functor: returns the result of function f_default except at generation pulse returns the result of fu...
int num_generations
number of generations in simulation
1 # Description of Mac/Linux/Unix Makefile for example_compilation.
2 # makefile_nvcc is useful when combining GPU-accelerated code into an existing C++ project and using NVCC to compile all files and link objects into executable.
3 # makefile_gpp is useful when combining GPU-accelerated code into an existing C++ project and user wants to keep non-CUDA code compiled by a different compiler (e.g. g++).
5 #############################
6 # build_path := Where to build program and put executable (note: folder must already exist)
7 # EXEC_FILE := Name of executable
9 # cpp_object_names := CPP objects required for executable
10 # cpp_objects := Prepends build path to object names
12 # cuda_object_names := CUDA objects required for executable
13 # cuda_objects := Prepends build path to object names
15 # nvcc := Command 'make' or 'make nvcc' calls the makefile makefile_nvcc
17 # gpp := Command 'make gpp' calls the makefile makefile_gpp
19 # .PHONY := Defines 'nvvc', 'gpp', and 'clean' as not true targets (i.e. don't remake executable if can't find files called 'all' or 'clean')
21 # clean := Action to perform for command 'make clean'
22 # Remove all objects and EXEC_FILE from build_path
23 #############################
25 build_path = ../example_compilation
28 cpp_object_names = main.o
29 cpp_objects = $(addprefix $(build_path)/,$(cpp_object_names))
31 cuda_object_names = run.o shared.o go_fish_impl.o
32 cuda_objects = $(addprefix $(build_path)/,$(cuda_object_names))
39 .PHONY: nvcc gpp clean
42 rm -f $(cuda_objects) $(cpp_objects) $(build_path)/gpuCode.o $(build_path)/$(EXEC_FILE)
1 # Description of Mac/Linux/Unix Makefile for example_compilation.
2 # NVCC compiles C++ and CUDA code and links all objects into an exectuable.
4 #############################
5 # build_path := Where to build program and put executable (note: folder must already exist)
6 # api_path_source := Location of API source folder
7 # api_path_include := Location of API include folder
8 # EXEC_FILE := Name of executable
10 # NVCC := Compiler path, in this case nvcc is in $PATH
11 # CFLAGS_CUDA := Compiler Flags for CUDA (*.cu) Files: optimize most, fast math, add API include folder to include search path, equivalent to --relocatable-device-code=true --compile
12 # CFLAGS_CPP := Compiler Flags for CPP (main.cpp) Files: optimize most, add API include folder to include search path, compile
13 # CODE := GPU types for which to build explicitly (I have a NVIDIA GTX 780M and 980) https://developer.nvidia.com/cuda-gpus, creates machine code for code=sm_30 (780) and code=sm_52 (980) and virtual architectures for all other generations which can be compiled JIT - code=compute_30 for generations between (3.0,5.0) and code=compute_50 for generations (5.0 and up) http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#options-for-steering-gpu-code-generation
15 # cpp_object_names := CPP objects required for executable
16 # cpp_objects := Prepends build path to object names
18 # cuda_object_names := CUDA objects required for executable
19 # cuda_objects := Prepends build path to object names
21 # all := Command 'make' or 'make all' builds executable file $(EXEC_FILE) in location $(build_path)/
23 # ##### Object Dependencies Lists #####
24 # If one of the files on the right hand side of the : changes, the corresponding object must be recompiled.
25 # This is a users makefile - it assumes there will be no changes to the GOFish API files, so does not include
26 # all the non-*.cu (non source file) dependencies except those that the user created (i.e. run.h). If changes
27 # to the API .h or .cuh files are expected see Object Dependencies Lists in example_dadi or run 'make clean'
28 # before each 'make all'.
29 # ##### End Object Dependencies Lists #####
31 # $(cpp_objects) := Make target all objects
32 # Compile CPP source code into objects, $< := dependencies from Object Dependencies Lists, $@ := object in $(objects)
34 # $(cuda_objects) := Make target all objects
35 # Compile CUDA source code into objects, $< := dependencies from Object Dependencies Lists, $@ := object in $(objects)
37 # $(build_path)/$(EXEC_FILE) := Make target executable EXEC_FILE which depends on all objects
38 # Link CUDA/CPP objects into executable EXEC_FILE, $@ := $(build_path)/$(EXEC_FILE)
40 # .PHONY := Defines 'all' as not a true target (i.e. don't remake executable if can't find a file called 'all')
41 #############################
43 build_path = ../example_compilation
44 api_path_source = ../../3P/_internal
45 api_path_include = ../../3P
49 CFLAGS_CUDA = -O3 --use_fast_math -I $(api_path_include)/ -dc
50 CFLAGS_CPP = -O3 -I $(api_path_include)/ -c
51 CODE = --generate-code arch=compute_30,code=sm_30 --generate-code arch=compute_52,code=sm_52 --generate-code arch=compute_30,code=compute_30 --generate-code arch=compute_52,code=compute_52
53 cpp_object_names = main.o
54 cpp_objects = $(addprefix $(build_path)/,$(cpp_object_names))
56 cuda_object_names = run.o shared.o go_fish_impl.o
57 cuda_objects = $(addprefix $(build_path)/,$(cuda_object_names))
59 all: $(build_path)/$(EXEC_FILE)
61 ##### OBJECT DEPENDENCIES #####
62 $(build_path)/main.o: main.cpp run.h
63 $(build_path)/run.o: run.cu run.h
64 $(build_path)/shared.o: $(api_path_source)/shared.cu
65 $(build_path)/go_fish_impl.o: $(api_path_source)/go_fish_impl.cu
66 ##### END OBJECT DEPENDENCIES #####
69 $(NVCC) $(CFLAGS_CPP) $< -o $@
72 $(NVCC) $(CODE) $(CFLAGS_CUDA) $< -o $@
74 $(build_path)/$(EXEC_FILE): $(cpp_objects) $(cuda_objects)
76 $(NVCC) $(CODE) $(cpp_objects) $(cuda_objects) -o $@
1 # Description of Mac/Linux/Unix Makefile for example_compilation using g++ to compile the C++ code and link objects into executable.
2 # NVCC compiles CUDA code and links device (GPU) code into an object that can be understood by g++ with the help of the CUDA Runtime Library.
4 #############################
5 # build_path := Where to build program and put executable (note: folder must already exist)
6 # api_path_source := Location of API source folder
7 # api_path_include := Location of API include folder
8 # EXEC_FILE := Name of executable
10 # CC := Compiler, in this case g++
11 # NVCC := Compiler path, in this case nvcc is in $PATH
12 # CFLAGS_CUDA := Compiler Flags for CUDA (*.cu) Files: optimize most, fast math, add API include folder to include search path, equivalent to --relocatable-device-code=true --compile
13 # CFLAGS_CPP := Compiler Flags for CPP (main.cpp) Files: optimize most, add API include folder to include search path, compile
14 # CODE := GPU types for which to build explicitly (I have a NVIDIA GTX 780M and 980) https://developer.nvidia.com/cuda-gpus, creates machine code for code=sm_30 (780) and code=sm_52 (980) and virtual architectures for all other generations which can be compiled JIT - code=compute_30 for generations between (3.0,5.0) and code=compute_50 for generations (5.0 and up) http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#options-for-steering-gpu-code-generation
15 # LIB_CUDART := Location of the CUDA Runtime API
17 # cpp_object_names := CPP objects required for executable
18 # cpp_objects := Prepends build path to object names
20 # cuda_object_names := CUDA objects required for executable
21 # cuda_objects := Prepends build path to object names
23 # all := Command 'make' or 'make all' builds executable file $(EXEC_FILE) in location $(build_path)/
25 # ##### Object Dependencies Lists #####
26 # If one of the files on the right hand side of the : changes, the corresponding object must be recompiled.
27 # This is a users makefile - it assumes there will be no changes to the GOFish API files, so does not include
28 # all the non-*.cu (non source file) dependencies except those that the user created (i.e. run.h). If changes
29 # to the API .h or .cuh files are expected see Object Dependencies Lists in example_dadi or run 'make clean'
30 # before each 'make all'.
31 # ##### End Object Dependencies Lists #####
33 # $(cpp_objects) := Make target all objects
34 # Use g++ to compile CPP source code into objects, $< := dependencies from Object Dependencies Lists, $@ := object in $(objects)
36 # $(cuda_objects) := Make target all objects
37 # Use nvcc to compile CUDA source code into objects, $< := dependencies from Object Dependencies Lists, $@ := object in $(objects)
39 # $(build_path)/gpuCode.o := Make target CUDA object which depends on cuda objects
40 # Use nvcc to link device code from CUDA objects into object gpuCode.o, $@ := $(build_path)/gpuCode.o
42 # $(build_path)/$(EXEC_FILE) := Make target executable EXEC_FILE which depends on all objects
43 # Use g++ to link CUDA/CPP objects into executable EXEC_FILE reintegrating device code using gpuCode.o and the CUDA runtime library, $@ := $(build_path)/$(EXEC_FILE)
45 # .PHONY := Defines 'all' as not a true target (i.e. don't remake executable if can't find a file called 'all')
46 #############################
48 build_path = ../example_compilation
49 api_path_source = ../../3P/_internal
50 api_path_include = ../../3P
55 CFLAGS_CUDA = -O3 --use_fast_math -I $(api_path_include)/ -dc
56 CFLAGS_CPP = -O3 -I $(api_path_include)/ -c
57 CODE = --generate-code arch=compute_30,code=sm_30 --generate-code arch=compute_52,code=sm_52 --generate-code arch=compute_30,code=compute_30 --generate-code arch=compute_52,code=compute_52
58 LIB_CUDART = -L/usr/local/cuda/lib -lcudart
60 cpp_object_names = main.o
61 cpp_objects = $(addprefix $(build_path)/,$(cpp_object_names))
63 cuda_object_names = run.o shared.o go_fish_impl.o
64 cuda_objects = $(addprefix $(build_path)/,$(cuda_object_names))
66 all: $(build_path)/$(EXEC_FILE)
68 ##### OBJECT DEPENDENCIES #####
69 $(build_path)/main.o: main.cpp run.h
70 $(build_path)/run.o: run.cu run.h
71 $(build_path)/shared.o: $(api_path_source)/shared.cu
72 $(build_path)/go_fish_impl.o: $(api_path_source)/go_fish_impl.cu
73 ##### END OBJECT DEPENDENCIES #####
76 $(CC) $(CFLAGS_CPP) $< -o $@
79 $(NVCC) $(CODE) $(CFLAGS_CUDA) $< -o $@
81 $(build_path)/gpuCode.o: $(cuda_objects)
82 $(NVCC) $(CODE) -dlink $(cuda_objects) -o $@
84 $(build_path)/$(EXEC_FILE): $(cpp_objects) $(cuda_objects) $(build_path)/gpuCode.o
86 $(CC) $(cpp_objects) $(build_path)/gpuCode.o $(cuda_objects) $(LIB_CUDART) -o $@