Is it possible to take advantage of a multicore processor for fortran?

In summary, Fortran has the advantage of being able to use multiple processors for faster calculations compared to C/C++. However, this depends on the specific Fortran compiler being used. In C, the use of pointers makes it difficult for the compiler to automatically split calculations across multiple CPUs/Cores. Fortran, on the other hand, allows for this and also has the option of using something like MPI to split calculations across multiple CPUs/machines. Gfortran, a popular compiler, has information on specific compiler directives for multi-threading on their website.
  • #1
fluidistic
Gold Member
3,923
261
I have a dual core processor (intel) but I think that fortran programs only uses 1 processor. Can Fortran use both processors to calculate faster?
 
Technology news on Phys.org
  • #2
Yes that's one of the main advantages of Fortran over C/C++
Wether your particular Fortran compiler can do it depends.
 
  • #3
mgb_phys said:
Yes that's one of the main advantages of Fortran over C/C++
Wether your particular Fortran compiler can do it depends.

Thanks for the reply.
So it all depends on the compiler? Strange that we can't write a compiler that does the same for C/C++.

By the way, it seems that gfortran (my compiler) doesn't use more than 1 core. Do you know if I'm right?
 
  • #4
The difficulty in c is that because you have pointers you can't know what memory a function will change without running it - so the compiler can't automatically split say the update of different parts of an array to different CPUs/Cores because they might not be independant. With Fortran you know they are and so can safely run multiple threads each using their own part of an array.

Sorry I don't know g95.
You can always use something like MPI to split a calculation across multiple CPUs/machines - but it might be overkill for just a dual core.
 
  • #5
mgb_phys said:
The difficulty in c is that because you have pointers you can't know what memory a function will change without running it - so the compiler can't automatically split say the update of different parts of an array to different CPUs/Cores because they might not be independant. With Fortran you know they are and so can safely run multiple threads each using their own part of an array.

Sorry I don't know g95.
You can always use something like MPI to split a calculation across multiple CPUs/machines - but it might be overkill for just a dual core.

Thanks a lot for the info.
 
  • #7
Example mutli-threaded C prograrm (use visual studio to build). It just copies a file, but the basics required for multi-threading, including code for fifo "message" queues is included.

http://jeffareid.net/misc/mtcopy.zip
 

1. Can Fortran programs be parallelized to utilize the multiple cores of a processor?

Yes, Fortran programs can be parallelized using various techniques such as OpenMP and MPI to take advantage of the multiple cores of a processor.

2. How many cores can a Fortran program utilize?

This depends on the specific implementation and parallelization method used. Some Fortran compilers may support up to thousands of cores, while others may have limitations.

3. Will parallelizing my Fortran program improve its performance?

In most cases, yes. Parallelizing a Fortran program can lead to significant improvements in performance, especially for programs that require heavy computation or data processing.

4. Are there any limitations to using a multicore processor with Fortran?

While multicore processors can greatly improve the performance of Fortran programs, there may be limitations depending on the specific program and the parallelization techniques used. It is important to carefully consider the design and implementation of parallelization to avoid potential issues.

5. How do I know if my Fortran program is utilizing all available cores?

There are various tools and methods for monitoring the usage of cores by a Fortran program, such as performance profilers and specialized libraries. It is important to properly test and benchmark your program to ensure it is making the most of the available cores.

Similar threads

Replies
8
Views
1K
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
11
Views
2K
  • Programming and Computer Science
Replies
14
Views
1K
  • Programming and Computer Science
Replies
6
Views
3K
  • Programming and Computer Science
Replies
8
Views
1K
  • Differential Equations
Replies
1
Views
714
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
9
Views
1K
Back
Top