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

  • Thread starter Thread starter fluidistic
  • Start date Start date
  • Tags Tags
    Fortran Processor
Click For Summary
Fortran programs can utilize multiple processors for faster calculations, a significant advantage over C/C++. However, the ability to leverage multiple cores depends on the specific Fortran compiler being used. The gfortran compiler, mentioned in the discussion, may not support multi-core processing effectively. The challenge with C/C++ lies in the use of pointers, which complicates the compiler's ability to determine memory changes, making it difficult to automatically distribute tasks across multiple cores. In contrast, Fortran's structure allows for safer multi-threading by ensuring that different threads can operate on independent parts of an array. For more advanced parallel processing, tools like MPI can be employed, although they may be excessive for simple dual-core applications. Resources such as OpenMP documentation for gfortran and examples of multi-threaded C programs were also shared for further exploration.
fluidistic
Gold Member
Messages
3,931
Reaction score
281
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
Yes that's one of the main advantages of Fortran over C/C++
Wether your particular Fortran compiler can do it depends.
 
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?
 
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.
 
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.
 
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
 

Similar threads

Replies
8
Views
2K
  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
11
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
14
Views
2K
  • · Replies 9 ·
Replies
9
Views
7K
  • · Replies 8 ·
Replies
8
Views
4K
Replies
8
Views
6K
  • · Replies 2 ·
Replies
2
Views
3K