John Rieffel

Assistant Professor
Computer Science Department
Union College


 Resources 

On this page:

LaTeX Tips

3-D Modeling and Printing

Multithreading Genetic Algorithms

LaTeX Tips

3-D Modeling and Printing

OpenSCAD is a fantastic scriptable parametric CAD tool. Some of its best features are available at the command line. It isn't obvious how to use these features on the OS X version. It turns out that you can run the command-line features from the OS X-installed app if you know where to look:

            %/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD -o foo.stl foo.scad

More info on the command line format is available in the User Manual as well as this excellent Papa Geek Blog Post

Multithreading Genetic Algorithms

If you have written your own Genetic Algorithm code and you haven't adapted it to run in multiple threads on a multi-core processor, perhaps you didn't realize how easy it is using OpenMP! Presumably you have a line in your code which looks something like this:

          //some initialization
	  for (int i = 0; i < popsize; i++)
	       evaluate(pop[i]);

All you have to do to get the evaluation to run on multiple parallel threads is use the OpenMP pragma for directive (with some caveats):

          #include 
          //some initialization
	  #pragma omp parallel for
	  for (int i = 0; i < popsize; i++)
	       evaluate(pop[i]);

And then compile with the -fopenmp flag:

	      %gcc -o ga ga.c -fopenmp

and run your code normally!

Caveats:

  • By default all threads share access to all variables (with the exception of the loop iterator)
  • You should not have any loop-carried data dependencies (evaluating pop[i] cannot be predicated upon the evaluation of pop[i-1])
  • To learn more, visit openmp.org.