Locate segfault for small N (population size = 0). Seed as additional run parameter...
authorDariusz Murakowski <murakdar@mit.edu>
Mon, 16 Sep 2013 15:43:15 +0000 (11:43 -0400)
committerDariusz Murakowski <murakdar@mit.edu>
Mon, 16 Sep 2013 15:43:15 +0000 (11:43 -0400)
Makefile
concat.sh [new file with mode: 0755]
population.cpp
wf.cpp

index e7f3816..8e208f9 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ LIBS = -lgsl -lgslcblas -lm
 ifeq ($(dbg),1)
        DBGFLAG = -g
 else
-       DBGFLAG = -O3
+       DBGFLAG = -O3 -combine
 endif
 
 # now the actual build rules, pretty general
@@ -26,6 +26,11 @@ all: $(EXECNAME)
 
 $(EXECNAME): $(SRCS)
        $(CXX) $(SRCS) $(CFLAGS) $(LIBDIR) $(INCLUDEDIR) -o $(EXECNAME) $(LIBS)
+
+# concatenate all the source files before compiling
+#      ./concat.sh $(EXECNAME) $(SRCS)
+#      $(CXX) -x c++ $(EXECNAME).combined $(CFLAGS) $(LIBDIR) $(INCLUDEDIR) -o $(EXECNAME) $(LIBS)
+
 #      $(CXX) $(SRCS) $(CFLAGS) $(LFLAGS) $(INCLUDES) $(LIBS) -o $(EXECNAME)
 #      $(CXX) $(CFLAGS) $(INCLUDES) -o $(EXECNAME) $(OBJS) $(LFLAGS) $(LIBS)
 
@@ -35,4 +40,5 @@ $(EXECNAME): $(SRCS)
 
 clean:
        $(RM) *.o $(EXECNAME)
+#      $(RM) *.o *.combined $(EXECNAME)
 
diff --git a/concat.sh b/concat.sh
new file mode 100755 (executable)
index 0000000..81d261c
--- /dev/null
+++ b/concat.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+output="$1"
+shift
+
+declare files=""
+while [ -n "$1" ]; do
+    files="$files $1"
+    shift
+done
+
+temp=$output.combined
+cat /dev/null > $temp
+
+for file in $files; do
+    echo "#line 1 \"$file\"" >> $temp
+    cat $file >> $temp
+done
+
index fed7284..7d0c7b3 100644 (file)
@@ -122,7 +122,7 @@ void Population::next_generation(const Hamiltonian &H, gsl_rng* r, bool useRelat
                
         }
         
-               pop[iter->first]++;
+               pop[iter->first]++;     // segfaults HERE when pop_size == 0 (i.e. none survive)
         
         new_Eavg += iter->first.energy;
         
diff --git a/wf.cpp b/wf.cpp
index 01e4362..6294977 100644 (file)
--- a/wf.cpp
+++ b/wf.cpp
@@ -36,7 +36,7 @@ static unsigned sim_random_seed() {
 
 // Run the program
 
-void run(RunParameters &r) {
+void run(RunParameters &r, unsigned seed) {
     
     // Initialize RNG and set initial state, if importing from file
     
@@ -44,7 +44,7 @@ void run(RunParameters &r) {
     
     //srand((unsigned)time(0));
     //gsl_rng_set(rnd,rand());
-    gsl_rng_set(rnd,sim_random_seed());
+    gsl_rng_set(rnd,seed);
     
     r.setFiles();
     FILE *popout=fopen(r.trajectoryOutfile.c_str(),"w");        // <outfile>.dat
@@ -70,6 +70,7 @@ void run(RunParameters &r) {
                 unsigned int i;
                 for (i=0; i<r.g; ++i) {
                 
+                    //printf("%d\t%d\n",n,i);
                     P.next_generation(H, rnd, r.useRelative, r.useVerbose);
                     P.write_two_site_population(popout,H,i+1);
 
@@ -278,6 +279,8 @@ void usage()
 int main(int argc, char *argv[]) {
     
     RunParameters r;
+
+    unsigned seed = sim_random_seed();
     
     // Process command line input
     
@@ -315,6 +318,7 @@ int main(int argc, char *argv[]) {
         else if (strcmp(argv[i],"-p01")==0) { if (++i==argc) break; else add_to_two_site_pop(r,false,true ,strtodouble(argv[i])); }
         else if (strcmp(argv[i],"-p11")==0) { if (++i==argc) break; else add_to_two_site_pop(r,true ,true ,strtodouble(argv[i])); }
 
+        else if (strcmp(argv[i],"-seed")==0) { if (++i==argc) break; else seed=(unsigned)strtodouble(argv[i]); }
 
         else if (strcmp(argv[i],"-h")==0)   { usage(); return 0;    }
         
@@ -322,7 +326,8 @@ int main(int argc, char *argv[]) {
                 
     }
     
-    run(r);
+    std::cout << "seed = " << seed << "\n";
+    run(r,seed);
     
     return 0;