View Full Version : Is it possible to take advantage of a multicore processor for fortran?
fluidistic
Oct13-09, 10:52 AM
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?
mgb_phys
Oct13-09, 10:54 AM
Yes thats one of the main advantages of Fortran over C/C++
Wether your particular Fortran compiler can do it depends.
fluidistic
Oct13-09, 11:13 AM
Yes thats 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?
mgb_phys
Oct13-09, 12:08 PM
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.
fluidistic
Oct13-09, 12:17 PM
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.
rdnck76
Oct13-09, 12:54 PM
Check out the OpenMP page on gfortran's website on specific compiler directives.
http://gcc.gnu.org/onlinedocs/gfortran/OpenMP.html
Jeff Reid
Oct13-09, 07:49 PM
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
vBulletin® v3.7.6, Copyright ©2000-2009, Jelsoft Enterprises Ltd.