RGB, Thanks for the references.  Oh btw, the link to the C projects seems broken.<br><br>Nathan <br><br><div class="gmail_quote">On Nov 20, 2007 2:23 PM, Robert G. Brown <<a href="mailto:rgb@phy.duke.edu">rgb@phy.duke.edu
</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="Ih2E3d">On Tue, 20 Nov 2007, Nathan Moore wrote:<br><br>> After reflection though, I've started to wonder about the wisdom of my
<br>> choice.  Specifically (like RGB), I love the GSL library, and extending GSL<br>> to fortran in an intro class is non-trivial.  Additionally, most vendors<br>> supply "fast" hardware libraries in C (I may be ignorant, but if a student
<br>> wants to call an AMD ACML fast-math function(<br>> <a href="http://developer.amd.com/acml.jsp" target="_blank">http://developer.amd.com/acml.jsp</a>), or write a linear algebra function to<br>> run on a graphics card(
<a href="http://developer.nvidia.com/object/cuda.html" target="_blank">http://developer.nvidia.com/object/cuda.html</a>), the<br>> vendors seem to assume that you'll write the code in C).<br>><br>> Also, and more relevant, I assume that most employers word-associate
<br>> "Fortran is to backwards as C is to competence".<br>><br>> So, I'm thinking about reworking the class to favor C, and fearing 3 weeks<br>> of pointer and addressing hell.  For those of you who teach scientific
<br>> computation (and also those of you who hire undergrads), I'd be grateful for<br>> your thoughts.  One specific question I have is what text covers scientific<br>> programming and touches on MPI using the C language.
<br><br></div>Ah, grasshopper, you have finally managed to snatch the stone.  (Or is it<br>drink the kool-ade, I never can remember...;-)<br><br>Let's see.  There are some truly excellent books that have helped my<br>
independent study students on programming (most of whom are trained in<br>Java only these days, God help us all:-( learn C.  There are also two<br>free online C reference manuals, three if you count Gnu's (which<br>unfortunately is by far the worst of them).  I will endeavor to provide
<br>you with a short shopping list, as I keep pretty much a complete C<br>programmer's reference toolkit on my laptop at all times including the<br>two aforementioned C textbook/manuals, various other free/online<br>manuals, and of course the man pages.  Even though I write a LOT of C I
<br>still have to look things up -- what programmer doesn't?  When I'm<br>online I have even more access to free resources as GIYF.<br><br>To my mind, the most difficult aspect of programming in linux for a<br>newbie isn't the compiler, it is the programming environment and
<br>learning how to create a project directory, put it under subversion (or<br>possibly CVS) control, pick a text editor (not a WYSIWYG WP, an editor,<br>ideally one that groks compilation and make), and write that first hello
<br>world program.  The second longest thing is teaching them a sane way of<br>getting variables off of the command line and into a program, especially<br>when some of the kids have never really used a command line at all in
<br>the past.  Drop the mice, guys -- fingers on those home keys!  That's<br>where you type, after all...<br><br>This process is greatly sped up if you provide them with a "standard<br>program template" like the one here:
<br><br>   <a href="http://www.phy.duke.edu/%7Ergb/General/project.php" target="_blank">http://www.phy.duke.edu/~rgb/General/project.php</a><br><br>which can create a work directory for you by running a little script and<br>
prepopulate it with a functional Makefile and a set of hello-world<br>sources complete with a routine that parses the command line and can<br>fairly easily be hacked to add new CL arguments.  Note that this<br>template is always changing and you'll like have to modify it and test
<br>it to meet the needs of your students, but it will TREMENDOUSLY improve<br>your ability to grade projects as they can "make tgz" and ship you a<br>project tarball, ready to unpack, build, test.<br><br>I personally like the jove (Jonathan's Own Version of Emacs) for all
<br>text editing because emacs is maddeningly complex, crufted, overladen<br>with features, and hence all but unlearnable.  jove installs easy, there<br>is a teachjove tutorial that will walk students through all they need to
<br>know to use jove as a semi-IDE, and you're done.  I've got jove<br>tarball/rpm's, or it is in debian ready to roll from what I've heard<br>(what isn't?:-).<br><br>One of the two C books I'd recommend is here:
<br><br>   <a href="http://www.phy.duke.edu/%7Ergb/General/c_book.php" target="_blank">http://www.phy.duke.edu/~rgb/General/c_book.php</a><br><br>which is a legal mirror of the original book.  Note well the license is<br>
a "beer" license.  You have to buy the authors beer if the opportunity<br>to do so presents itself.  This may present problems for your students<br>if they are underage, but I imagine the authors of the book will be down
<br>with that.  So each student can mirror my mirror, or they can find the<br>original online with google or otherwise and mirror that.  That way they<br>can have an entire, quite readable book on C, replete with cut-n-paste
<br>examples, free, installed on their personal computers where it is always<br>handy and useful.<br><br>This is a "beginner" level book -- complete enough for simple code, but<br>not really up to snuff on things like threads or advanced data
<br>structures.  For the SERIOUS student, or the student working on an<br>advanced project where forking, threads, and so on are necessary, I'd<br>recommend that they use Dave Marshall's book:<br><br>   <a href="http://www.cs.cf.ac.uk/Dave/C/CE.html" target="_blank">
http://www.cs.cf.ac.uk/Dave/C/CE.html</a><br><br>This is a GREAT book.  A full out, pro-grade book on C including some<br>very advanced stuff.  Parts are a tiny bit dated -- the first chapter of<br>the book deals with CDE on Solaris -- but it is a killer reference.
<br>Online access is free, and if you contact Dave regarding redistribution<br>of the book to a class full of students in PDF format (which he has, and<br>for that matter so do I) he might be open to it.  He sent one to me
<br>willingly enough when I asked him about it, so I've got it on my laptop<br>for eternity, network or not.  He was going to look into a Gnu OPL for<br>it when last we communicated.  At this point I'd suggest (to him)
<br>throwing it up onto Lulu for cheap download in PDF or paper print with a<br>reasonable markup -- he'd make money and students would get a generally<br>lovely book in whatever form(s) they prefer.<br><br>Then there are a variety of algorithm books or programming environment
<br>books I like to recommend to students I'm teaching:<br><br>  * King Abel and Graham Glass's book.<br><br><a href="http://www.amazon.com/Linux-Programmers-Users-Graham-Glass/dp/0131857487" target="_blank">http://www.amazon.com/Linux-Programmers-Users-Graham-Glass/dp/0131857487
</a><br><br>I've used this book since it was just glass and Unix instead of Linux.<br>A classic.  Way too EXPENSIVE a classic at $84, but a classic.<br><br>  * Mastering Algorithms in C (O'Reilly Seahorse IIRC).  Excellent
<br>reference for stock-in-trade stuff like data structures, linked lists,<br>sorting, numerical methods (to a point).<br><br>  * Kernighan and Pike's The Practice of Programming.  I'd actually make<br>this a requirement for any new C programmer.  It covers things like
<br>INDENT YOUR GODDAMN CODE AND I REALLY MEAN IT, and IF YOU DON'T COMMENT<br>YOUR CODE YOU WON'T UNDERSTAND IT YOURSELF TWO WEEKS FROM NOW, and WHAT<br>THE HELL IS aRp IN YOUR CODE?  DOES THAT MEAN SOMETHING TO YOU ASIDE
<br>BESIDES "BARF"?  so that you don't have to yell QUITE so much at your<br>students and has lots of other wisdom as well.<br><br>  * Optionally Kernighan and Pike's The Unix Programming Environment<br>
isn't quite as good as Abel and Glass, but it is still damn good and and<br>excellent reference.<br><br>For numerical methods per se, well, there is STILL Numerical Recipes in<br>C, but I no longer use it in any code because it sucks in so many ways.
<br>It is encumbered, with a code-reuse license out of the dark ages, I mean<br>a really, really, really bad one (in spite of the fact that some of the<br>code they are trying to encumber comes right out of the literature).  I
<br>personally think that all they need is the GSL itself and the GSL's<br>manual, online or otherwise.  At this point anything you're at all<br>likely to have beginners doing is well-supported there, with<br>documentation and code examples, with a list to ask difficult questions
<br>on.  And yes, they can buy a paper copy of this from Amazon (and help<br>support the project at the same time).  And it is even cheap.<br><br>My actual favorite numerical methods book is alas in fortran --<br>Forsythe, Malcom and Moler -- but all that they really need from any
<br>such textbook is a two lecture discussion on discretization error and<br>bad ways of doing what appear to be straightforward tasks because<br>computers do discrete arithmetic.  If the course were going to FOCUS on<br>
numerical methods, e.g. derive a 4th-5th order RK ODE solver and code<br>it, you'd likely need t textbook to help, but to USE an RK ODE solver --<br>just the GSL, just the GSL.<br><br>The last reference I like to recommend is (of course) Knuth's TAOP.
<br>'Nuff said.  Expensive as hell for the full set, but it IS the only<br>reference you'll ever need, unless you plan to do network programming in<br>which case you'll likely need one or more of Stevens' excellent books,
<br>or plan to do systems programming at the kernel level, in which case<br>you'll need several books I'm not going to list here, or MPI or PVM, in<br>which case you'll need -- what?  Well there are a few excellent books
<br>from IIRC MIT press on them, but they may be dated at this point.  There<br>are the many superb articles on www.clustermonkey.new and in the Linux<br>Magazine archives.  Again, having a good template goes a long way --
<br>there is a PVM template on my website but I don't use MPI (or PVM, much,<br>anymore) so you'll have to get them from other folks.<br><br>I've found that some subset of the *'d references and free references
<br>above can take a student that can program in ANY language already and<br>make a credible C programmer out of them in a semester.<br><br>And jeeze, man.  Pointers rock.  If you want students to actually learn<br>how computers work so that they can UNDERSTAND what they are doing they
<br>are peerless (if painful) instruments of learning.  Want a block of<br>memory?  Go get it, lay it out, access it, all with fairly high level<br>commands.  Want to overlay a secondary addressing scheme on top of it?<br>
Sure, why not.  Allocate a vector, pack its addressing into a ***pointer<br>to make a matrix[][][] that you can still pass to an ODE solver that<br>wants vectors only, while addressing it in a completely natural way in<br>
the deriv evaluator.  You can do things in C easily that you can't do AT<br>ALL in other languages, all because of pointers and the ability to<br>recast variables.  Sure, you can break a program more horribly than you
<br>ever could in Fortran (although I've managed to break fortran pretty<br>horribly).  That's why you get them K&P and make them read it FIRST, and<br>why you teach them about adding<br><br><br>#define MYDEBUG(b)  if ( (verbose == b) || (verbose == D_ALL) )
<br><br>  typedef enum {<br>    D_QUIET,<br>    D_ALL,<br>    D_V_2,<br>    D_V_3,<br>    D_V_3,<br>    N_DEBUG };<br><br>into their primary program header and sticking:<br><br>x = 1.0;<br>MYDEBUG(D_V_1){<br>  fprintf(stderr,"# This is my subroutine 1, and variable x = %f\n",x);
<br>}<br><br>chunklets all over their damn code as they write it.  Run the program as<br><br>   $myprog -v 2<br><br>and out spews:<br><br># This is my subroutine 1, and variable x = 1.000000<br><br>Run it as<br><br>   $myprog
<br><br>and it doesn't.  I instrument my code so that at any instant I can get a<br>completely verbose picture of everything it is doing as it goes along,<br>or "zoom in" on just one subroutine.  It is tricks like this that make C
<br>programming robust and doable.  One should do it in any language, of<br>course, but in C it is ESSENTIAL to make sure that the program is doing<br>what it is supposed to be doing, not overwriting array boundaries, and
<br>so on.  In fortran you are lulled into a false sense of security because<br>you THINK the compiler or runtime engine will catch errors for you when<br>in fact there are lots of errors they will miss, and then you are REALLY
<br>dead.<br><br>HTH,<br><br>    rgb<br><br>> regards,<br>><br>> Nathan Moore<br>><br>><br>><br><font color="#888888"><br>--<br>Robert G. Brown<br>Duke University Dept. of Physics, Box 90305<br>Durham, N.C
. 27708-0305<br>Phone(cell): 1-919-280-8443<br>Web: <a href="http://www.phy.duke.edu/%7Ergb" target="_blank">http://www.phy.duke.edu/~rgb</a><br>Lulu Bookstore: <a href="http://stores.lulu.com/store.php?fAcctID=877977" target="_blank">
http://stores.lulu.com/store.php?fAcctID=877977</a><br></font></blockquote></div><br><br clear="all"><br>-- <br>- - - - - - -   - - - - - - -   - - - - - - - <br>Nathan Moore<br>Assistant Professor, Physics<br>Winona State University
<br>AIM: nmoorewsu <br>- - - - - - -   - - - - - - -   - - - - - - -