Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Need advice for the HPC thing

  1. Dec 12, 2011 #1
    hello all!

    i will use super computer after 1 year from now to do some thing related to my experment

    and a friend told me to learn C++ and dont waist my time on the C

    is that right ...i am new to this ...i know only physics and matlab

    C or C++

    any good books for HPC
  2. jcsd
  3. Dec 12, 2011 #2
    In practice, the way people write C++ is often mostly indistinguishable from C.

    Also, usually the introductory stages of a C++ education mostly consist of learning C.

    I think you should go ahead and learn C++. You will have access to a slightly broader base of libraries if you are in C++, and using the advanced C++ features is totally optional if they are not useful to you.
  4. Dec 13, 2011 #3
    but, what is totally optional?
  5. Dec 13, 2011 #4
    Templates :P

    And you don't have to use the STL.

    What I mean is, C++ is basically a superset of C. So you can just put C into a C++ file and that will work fine.

    What a lot of C++ programmers seem to do is be writing basically "C with icing". They'll organize their code by putting methods into classes. But they won't really be taking advantage of classes in a truly OO way and usually won't be using templates or object polymorphism or crazy stuff like operator overloading. At this point you're nearly writing C, in C++ you'll be saying mywindow.resize(400,300); but this isn't really meaningfully different from if you were in C and saying window_resize(mywindow, 400, 300); (it's just a little more convenient to do it the C++ way).
  6. Dec 13, 2011 #5


    User Avatar
    Homework Helper

    Do you know what compiler is best optimized for the super computer you will be using? For some super computers, more effort has been put into optimizing and perhaps adding some computer specific extensions to Fortran instead of C or C++.
  7. Dec 13, 2011 #6


    User Avatar
    Science Advisor

    rcgldr has a really good point. Chances are you will be working with an architecture that maybe SIMD or MIMD which means that vectorized input will be optimized and the compiler might be given hints by setting flags, using compiler directives or through some other means.

    As a practical example, the Intel Compiler does these kinds of things by creating optimal code specifically for Intel Architectures, and it's quite likely that a custom built compiler will do the same thing for your platform.

    A way to check this out is to get an architecture manual as well as the instruction set manual in conjunction with the compiler documentation that will tell you if this is the case.

    You don't have to learn the machine codes or anything like that, but it would be wise to find out the basic processing model and what the compiler does to make use of it before you start to write any serious code.
  8. Dec 14, 2011 #7
    In addition to programming language, you should also consider the algorithms.
  9. Dec 20, 2011 #8
    every one told me this but the thing is that i dont know where should i start from ...fortran or C ... where should i start !
  10. Dec 20, 2011 #9
    C and Fortran are pretty similar languages. If you know one you almost know the other.

    Use whatever the people in your department use.
  11. Dec 20, 2011 #10


    User Avatar
    Science Advisor
    Homework Helper

    And in any case, "real programmers" can write Fortran in any programming language :smile:
  12. Dec 20, 2011 #11
  13. Dec 20, 2011 #12
    thank you all i have now a good understanding about where should i start ....i will start with C then fortran .....any why do i need to download any special Linux on my computer or do the code on my computer and then send it to mainframe ....meaning leave my slow win 7 without a change ...some saying that i should use ubunt ...but i cant find any connection between ubn and what i need
  14. Dec 20, 2011 #13
    You can do basic C and C++ on your Windows machine using Microsoft "Visual Studio Express". This is free.

    If you want the code and tools on your machine to be EXACTLY the same as they will be on the mainframe, you can download something called "cygwin". This is like a little fake linux sandbox that you install on your Windows machine. When you install Cygwin it will ask you what you want to install, make sure you install "gcc", "g++" and "g77" (g++ is the c++ compiler and g77 is the Fortran compiler). (Also "make" but I do not remember if Cygwin makes you ask for that specifically.) Note though that unless you already know how to use Linux, Cygwin may be a little bit hard to use.

    You should also on Windows install a source code management tool such as "TortoiseGit" or "TortoiseHg" and learn to use it. This will help protect your code from accidents and also make it easier for you to copy code to and from the mainframe.
  15. Dec 20, 2011 #14
    do i need intel complier too
  16. Dec 20, 2011 #15
    You can get a copy of the Intel compiler from Intel's website. However as far as I understand, if your code works with GCC (cygwin or mingw+msys) then you can expect it will work with ICC also. So you can probably test your code with GCC on your windows computer and then just send it to the mainframe and compile it with ICC there. Note I have not used ICC myself but this is my understanding from talking to people who do.
  17. Dec 20, 2011 #16
    thank you all .. i will download ubuntu ...for now

    by the way any advice aboot some books for starters
  18. Dec 21, 2011 #17
    no bookS...?
  19. Dec 21, 2011 #18


    User Avatar
    Science Advisor

    I would recommend reading the architecture manual for your platform. Also if your compiler has extensive documentation, read that as well.

    In terms of reading material for things like C and FORTRAN, theres going to be tonnes of books that pretty much cover exactly the same things.
  20. Dec 21, 2011 #19


    User Avatar
    Science Advisor
    Homework Helper

    It you want to learn C (and also learn how to program, in any language) you can't do much better than "The C Programmiing Language" by Kernighan and Ritchie - which everybody refers to as just "K&R".
  21. Dec 24, 2011 #20
    thank you ...about K&R i started with it ....i have a good back ground with C++ but didnt think that this knowledge will be usable in HPC environment
  22. Dec 24, 2011 #21
    do i need fortran books ..
  23. Apr 20, 2012 #22
    These days, you'll see a LOT more code written in C and C++ than in Fortran, so I recommend C/C++. Since C++ is mostly a superset of C, I'd recommend learning that.

    C++ has several features for doing elegantly and safely various things that must be done in ugly and bug-prone ways in plain C.

    For deallocating memory that is no longer needed, one can create an object that allocates some memory, and then deallocates it in its destructor. That will keep the allocated memory from leaking. Memory leaks often result from a pointer going out of scope without its pointed-to memory getting deallocated. The Standard Template Library's containers use that technique.

    One can do callbacks by defining virtual functions and then implementing them in subclasses.

    For constants, one can use the "const" keyword instead of the preprocessor. It will automatically be type-safe, since its definition gives it a type.
    #define UNLUCKY_NUMBER 13
    const int UNLUCKY_NUMBER = 13;

    Many functions defined with preprocessor macros can be expressed more safely with template functions.
    #define MAX(x,y) ((x) >= (y))
    template<class T> T &max(T &x, T &y) {return (x >= y) ? x : y;}

    Operator overloading is useful if you wish to define some object that you wish to make behave in a numberlike fashion or an arraylike fashion or whatever.

    If you wish to define a class of fractions, you can overload the familiar arithmetic and comparison operations to make one's fraction objects behave like integers and floats.

  24. Apr 20, 2012 #23
    On the other side, some fans of plain C think that C++ is needlessly complex. I recall someone once stating that "C++ is to C as lung cancer is to lung".
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook