CSE 30331/34331

Data Structures

Programming environment

The programming examples and assignments in this course will all be in C++, and will sometimes make use of C++11 features. Officially, your assignments must compile and run on the machines student{00,01,02,03}.cse.nd.edu using GCC 4.9 (not the default version). To get the right version, use these two commands (assuming tcsh):

setenv PATH ~csesoft/new/bin:$PATH
setenv LD_LIBRARY_PATH ~csesoft/new/lib64:$LD_LIBRARY_PATH
If the second line gives you an error, then instead do:
setenv LD_LIBRARY_PATH ~csesoft/new/lib64
Then run g++ --version and you should see:
g++ (GCC) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Then to compile C++11 code, you need to use g++ -std=c++11.

To make these changes permanent, add the two setenv commands above to your ~/.cshrc file.

If you want to use your own computer for development, you should have the following software installed:

Debugging

For general debugging, use GDB. Compile with -g (and without -O3), then run gdb yourprogram.

If you're having problems with STL containers, try compiling with -D_GLIBCXX_DEBUG to enable debug mode.

If you're having problems with memory management and pointers (including segmentation faults), use Valgrind. Run valgrind yourprogram. If you're instructed to rerun using --leak-check, do so.

Profiling and optimization

Most programming assignments will ask you to measure the performance of your code. If your program is graded based on speed, be sure to compile with -O3 -DNDEBUG.

To measure the time or memory usage of a program, use measure. (The time command is fine for measuring time, but either doesn't measure memory or measures it incorrectly.) If you need to measure time or memory usage at a particular point in a program, call getrusage().

You can use a profiler like gprof to identify what parts of your program are taking the most time.

  1. Compile with -pg (and -O3 -DNDEBUG).
  2. Run your program. It silently produces a file gmon.out.
  3. Run gprof followed by the name of your program.