What language is best for HPC: C or C++?

  • Thread starter hagopbul
  • Start date
  • Tags
    Need advice
In summary: Then you just type "make" and the code will be compiled and ready to run.Some people also recommend using "Ubuntu Linux". This is a free, Linux-based operating system that is very popular in scientific computing. Ubuntu has a built-in compiler called "GCC".
  • #1
hagopbul
357
36
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 don't 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
 
Technology news on Phys.org
  • #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.
 
  • #3
but, what is totally optional?
 
  • #4
Xitami said:
but, what is totally optional?
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).
 
  • #5
hagopbul said:
I will use super computer after 1 year from now to do some thing related to my experment.
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++.
 
  • #6
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.
 
  • #7
In addition to programming language, you should also consider the algorithms.
 
  • #8
every one told me this but the thing is that i don't know where should i start from ...fortran or C ... where should i start !
 
  • #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.
 
  • #10
Coin said:
C and Fortran are pretty similar languages. If you know one you almost know the other.

And in any case, "real programmers" can write Fortran in any programming language :smile:
 
  • #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 can't find any connection between ubn and what i need
 
  • #13
hagopbul said:
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 can't find any connection between ubn and what i need

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.
 
  • #14
do i need intel complier too
 
  • #15
hagopbul said:
do i need intel complier too

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.
 
  • #16
thank you all .. i will download ubuntu ...for now

by the way any advice aboot some books for starters
 
  • #17
no bookS...?
 
  • #18
hagopbul said:
no bookS...?

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, there's going to be tonnes of books that pretty much cover exactly the same things.
 
  • #19
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".
 
  • #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
 
  • #21
do i need fortran books ..
 
  • #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.

Etc.
 
  • #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".
 

1. What is HPC?

HPC stands for High Performance Computing and refers to the use of powerful computers and parallel processing techniques to solve complex computational problems.

2. How can HPC benefit my research or work?

HPC can significantly speed up the processing and analysis of large amounts of data, allowing for quicker and more accurate results. It can also enable the handling and simulation of complex models and simulations that would not be possible on a regular computer.

3. Do I need specialized training or knowledge to use HPC?

While some level of technical knowledge is necessary to use HPC, there are user-friendly interfaces and software that can make it accessible to those without extensive computer science backgrounds. However, it may be beneficial to receive some training or work with a specialist to fully utilize the capabilities of HPC.

4. How much does HPC cost?

The cost of HPC can vary depending on factors such as the type of hardware and software used, the extent of usage, and any necessary support or maintenance. It is important to carefully consider your needs and budget when considering implementing HPC in your research or work.

5. Is HPC only useful for scientific research?

No, HPC can be applied to a variety of industries such as finance, engineering, and healthcare, to name a few. Any field that deals with large amounts of data and complex calculations can benefit from HPC.

Similar threads

  • Programming and Computer Science
Replies
25
Views
2K
  • Programming and Computer Science
Replies
8
Views
873
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
2
Replies
54
Views
3K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
10
Views
2K
  • Programming and Computer Science
Replies
6
Views
1K
Replies
6
Views
1K
  • Programming and Computer Science
Replies
16
Views
1K
Back
Top