1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Best computer programming for particle astrophysics major?

  1. May 18, 2014 #1
    I am not taking any courses this summer and was wondering what computer programming would be ideal to learn for someone focusing on a particle astrophysics major?
     
  2. jcsd
  3. May 18, 2014 #2
    I've been programming for the last almost 18 years, and here's my thoughts:

    Low level languages, like Assembly, don't have built in functions for complex math, so you would have to write them from scratch. Almost every language you run into, you'll have to write custom complex math functions. If CPU speed isn't an issue, something like Visual Basic, Visual Basic .NET would be fine, and if you do, C++, C#, or C would be more than enough.

    If you need explicit cycles from the CPU, then you'll want to go ASM, but even poorly coded ASM will run slow.

    It also depends if you're planning on writing software for custom hardware, which, you'll most likely need to know ASM, or C at the very least.

    Of course, if you need something that requires a super computer, you'd most likely need to be able to learn custom programming and/or very, very efficient with ASM.

    It really all depends on the platform and limitations/restrictions set by the task at hand.

    Hope that helps a little!
     
  4. May 18, 2014 #3
    A very good fraction of numerical radiative transfer code written for astrophysical applications is written in Fortran and perhaps an equally large fraction is done in C. If you do research in this field you will inevitably encounter both, but most likely a whole lot more Fortran.

    Take your pick, either is a good first language and builds a good foundation. Fortran was my first real language so I am partial to it, I find it is very easy and intuitive to read. I also don't like using {} a whole lot so that biases me against C. :P

    I wouldn't go any lower level than that unless you really want to work with and design hardware... in that case, C is what is used to program/automate a lot of what goes on in the MAGIC Cerenkov telescope on the Canary Islands for example, and FPGA programming is what is used in cutting edge adaptive optics in optical/IR/far IR ground-based telescopes (you need super-fast motors to deform the primary mirror in almost real-time to correct for atmospheric effects).

    Also learn to use a common algebra package like matlab, mathematica, or even better (and free): the Enthought Python distribution (goes by the name Canopy nowadays). You'll get do data analysis and professional looking plots in this last one faster than with anything else with anything else I've tried (except gnuplot for graphing stuff, but it is limited in comparison), the learning curve is very flat. This is a good first language too (python), great place to learn the basics of loops and data types and such, it is a lot more forgiving than Fortran.
     
    Last edited: May 18, 2014
  5. May 18, 2014 #4
    I hear Fortran is very efficient for math functions, and C is excellent as well. I really should learn Fortran to add to my arsenal :P
     
  6. May 18, 2014 #5
    Thanks for the feedback. I guess I should have specified in the beginning, but I am going for theory. Not sure if that makes much of any difference compared to experimental, but the C, C++, and Fortran are the 3 I seem to hear the most about regardless of sub-field. I will have to see what is available with OCW and take it from there. I appreciate the info.
     
  7. May 18, 2014 #6
    To me, the theory of programming is very easy - it's applying your knowledge to useful applications that's the difficult part.

    Remember - every programming language is very similar, you just need to learn the keywords and know how to apply logic. For example, to increment an integer:

    ASM (lowest level you'll likely ever experience):

    inc ax ; adds +1 to ax register (or memory location if you specify)

    in BASIC:
    ax% = ax% + 1 ' variable ax%, note difference from a register

    in C/C++ (as well as javascript, PHP, higher levels of BASIC like VB.NET)

    ax++;

    (semi colon would error out in a BASIC compiler)


    I know it's pretty rudimentary on how to add +1 to a variable, or register, but this should give you an example on how simple syntax is used in various languages.

    Also, if you don't use a commercial compiler, or a compiler that doesn't follow explicit notation, there will be differences, quite possibly on custom compilers that is based off of another common (or more industry ready) compiler.

    One of the few languages I use on the Motorolla 68000 processor uses BASIC for the language. Of all the BASIC compilers I know, this is one of the only compilers I know (aside from VB.NET) to use C/C++ syntax for math operations (a%++, for example, to increment by 1).

    As with anything else, the more practice you get with programming, the better and more efficient you will become with programming over all. All logic and theory will apply to all languages, and depending on how critical timing is, or how quickly every operation needs to be, will come in time.

    Also, learn low level theory. By that, I mean how to work with bits, bit shifting, etc. Learn what your signed and unsigned integers are, floats, precisions, etc., and any function by a compiler uses that is faster than "traditional" methods.

    An example would be division or multiplication:

    (using the simplest to understand):

    a = a * 2 ' using just a simple multiplication routine

    Now, instead of doing a "simple" multiplication operand, you could do a bit shift:

    a = a<<1

    Bit shifting takes the current value in binary format, and shifts it over to the left or right (in the above example, by 1):

    Consider this:
    1100 in binary is 12. Want to double that? a = 12, a = a << 1: this makes the binary value 1100 to become 11000 (most integers are 16 bits or more these days, so don't focus on the 4 bits).

    This would become 24: 11000 in binary = (16+8+0+0) = 24

    And for division: 0110 = 6 in binary
    a = a>>1 = (0110->0011) = 3

    (bit shifting is native to ASM, for what it's worth)

    I think I went a bit far in depth with the simplicity of things and may have over complicated a good portion (if not all) of this post, but I hope it gives some idea behind the theory and relations between languages. If not, I apologize!

    Also, if you need any help with understanding anything with programming, I'd be more than happy to help assist (either with learning, or just understanding).

    I'm very comfortable, and efficient, in Motorolla 68000 ASM (and some higher languages), Visual Basic/ASP, VB.NET/ASP.NET, C++, Perl, PHP, JavaScript, and SQL (MySQL, Microsoft SQL, Oracle SQL, or TSQL in general).

    (I'm also Microsoft Certified in Microsoft: MCITP SQL DBA 2008 and MCIPT Visual Studios 2012)

    My suggestion - find an application you like to use often, and try to create your own version of it. Get used to programming and learning the features and functions of the compiler. After exposure to 2+ language, you should be able to figure out how to use any language :)
     
  8. May 18, 2014 #7
    I think you'll reap the most benefits from C because it has carryover into something you will sooner or later have to learn to use: linux operating systems (the terminals csh and bash borrow/steal the syntax from C).

    But for something lighter paced and more fun but no less useful (for learning the basics, doing plots, calculating stuff with arrays of data in any given format with a lot more flexibility than excel, and lightweight numerical simulations), pick up Python/Canopy. It is way more accessible for a first time language and more useful during your undergrad (for your projects, labs, homework, etc.).
     
  9. May 19, 2014 #8
    I am no particle guy, but Matlab and Python are really practical languages. C and Fortran are hard to use, but are powerful and fast.
     
  10. May 19, 2014 #9

    ZombieFeynman

    User Avatar
    Gold Member

    I did a little Particle Astrophysics as an undergrad. The two languages most commonly used were C++ and Fortran.

    I think that few people in physics code in Basic or ASM these days.

    For what it's worth, I am a part of a fairly numerically intensive Computational Condensed Matter group and we use C++, Python, and Mathematica almost exclusively.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook