Fortran Programming on Mac

Discussion in 'Mac Programming' started by Ron D, Mar 2, 2009.

  1. macrumors newbie

    Joined:
    Mar 1, 2009
    Location:
    Buffalo NY area
    #1
    I am searching for programming language S/W (for use on a Power Mac G4) that will enable me to create and run ads-hoc scientific/engineering calculations that are computationally intensive. Written programs would not be too complex but would involve trig function availability, capability for large number of iterations, logic statement capabilities, access to library functions such as random number generator, etc.

    FORTRAN comes to mind, as I am very familiar with it. I've heard of g77, g95, gfortan, but cannot discern which is simplest to implement (install) and stable (problem free) to operate.

    Any advise?
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    I have the most experience with g95, though not on OS X. You can download binaries here:
    http://ftp.g95.org/g95-powerpc-osx.tgz

    I have found it pretty easy to work with, but your mileage may vary.

    -Lee
     
  3. thread starter macrumors newbie

    Joined:
    Mar 1, 2009
    Location:
    Buffalo NY area
    #3
    Thanks for the quick reply. I'm ruinning OSX Version 10.4.9 which I'm guessing would be no problem.

    Some general website info suggested that g95 is not that mature (i.e., problem free), so I'm glad to hear that users (you) do not have problems with g95.

    Also heard that g77 will not be supported in the future, which would not necessarily be a problem . . . I'm not anticipating need for improvements/upgrades over something that works.

    Is it true that latest Xcode from Apple Developer tools is needed? Anything else??
     
  4. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #4
    It's probably best to just install the developer tools, because they contain a lot more than just XCode.

    I would recommend g95 over g77 only because of support for a lot of language enhancements that g77 doesn't have. I have had to patch a few things in the g95 runtime myself, but overall it has worked out pretty well for me. The only time i've seen compiler crashes were with trying to cheat with some new language features for C interoperability, so I wasn't too surprised by that. If you don't want any of the new language features (though i believe you do), g77 is certainly more mature.

    -Lee
     
  5. macrumors regular

    jtibbitt

    Joined:
    Jan 3, 2009
    #5
    Take a look at the GNU FORTRAN compiler gfortran. It is the well established FORTRAN compiler for GCC (GNU Compiler Collection). It may come with the latest XCODEs already, but I'm not sure with the powerpc. I'm pretty sure you need XCODE, but maybe not if you install GCC separately. I always used to install XCODE, then the latest GCC (even though it already comes with XCODE), then both g77, gfortran and g95. At times, trying different compilers helped me out during debugging. You can find GCC, g77 and gfortran all here (they also have a link to the g95 site):

    http://hpc.sourceforge.net/
     
  6. oz1
    macrumors member

    Joined:
    Mar 11, 2009
    #6
    I have been trying out a range of FORTRAN 64 bit compilers on the MAC Pro 2008 octocore.

    Just about everything I've looked at seems to be focussed on UNIX platforms with MAC OS functionality added as an afterthought. The result is that the install documentation varies in quality but leaves much unsaid if you are a MAC OS newbie (but not a FORTRAN newbie) like me.

    I haven't had much luck getting FORTRAN & XCODE running together (my inexperience with XCODE?) happily so have usually ended up using command line compilation via a terminal window. Of the various FORTRANs, ABSOFT has it's own IDE which ran pretty smoothly & was fairly easy to use.

    So far, I've tried out Intel, PG, Absoft, G95, & NAG FORTRAN generating 64 bit code. AFAIK, I've turned off the usual things like array bounds checking, etc & tried to compile programs for speed. Run times vary a lot with my test programs, Intel being the fastest but with some of the other compilers producing run times twice as long. Maybe I didn't set the compiler flags right but i didn't really have time to wade through all the documentation. Also, I haven't got the NAG compiler running yet so haven't been able to test it speed.

    One thing did surprise me. FORTRAN under MAC OS is a lot slower than under WINDOWS. My test program ran faster using an old 32 bit LAHEY compiler under a 32 bit WIN XP virtual machine on the MAC (13:32 mins compared with 16:30 mins from the Intel compiler which was the fastest MAC OS run). It was even faster using the 64 bit Intel compiler on a WIN XP Pro 64 bit edition virtual machine (9:54 mins).

    My testing was not very scientific as I just wanted ballpark figures but it suggests that MAC OS is not the best place to run FORTRAN.
     
  7. thread starter macrumors newbie

    Joined:
    Mar 1, 2009
    Location:
    Buffalo NY area
    #7
    Fortran Programming on Mac

    Well, I've downloaded Xcode from Apple (Version 2.4.1, as appropriate for my version of OS X), and I've downloaded g95 via Lee1210's link. More help is needed. Specifics are typed in upper case below.

    Regarding the latter, double clicking on the downloaded .tgz file resulted in a folder entitled "g95-Install" within which there were four items: (1) "G95Manual.pdf", (2) Folder "bin" containing "powerpc-apple-darwin6.8-g95", (3) Folder "lib" containing 8 files (e.g., "cc1", "crt2.0", "f951", etc.) none of which can be opened directly, and (4) a TextEdit file "Read_Install".

    The "Read_Install" file gives two instructions for installing g95:
    (1) Unpack the downloaded tarball (e.g., g95-x86-linux.tgz) in a directory of choice: tar -zxvf g95-x86-linux.tgz. DID MY DOUBLE CLICK ACCOMPLISH THE TARBALL UNPACK, OR DO I NEED TO ENTER THIS INSTRUCTION SOMEWHERE ELSE? IF SO, WHERE DO I ENTER THE INSTRUCTION and IS THE INSTRUCTION LITERALLY CORRECT?
    (2) You can create another symbolic link from a directory in your $PATH (e.g., ~/bin) to the executable: ln -s $PWD/g95-install/bin/*g95* ~/bin/g95. Sorry for being totally unfamiliar with the terminology but I have no idea of what "a directory in my $PATH" means. IS THE "SYMBOLIC LINK" JUST AN ICON ON MY DESKTOP (OR ELSEWHERE)? ANY HELP HERE WOULD BE APPRECIATED. DO I EVEN NEED TO DO THIS STEP?
    Following these 2 instructions is the statement: "You should now be able to run g95 and create executables". This is my goal. Sounds simple, assuming I can get through (1) and (2) above.

    Finally, thanks to all who added to this thread. I think I'm generally ok with the Xcode and g95 downloadeds. Compilation and run time test info is good, but execution time is not as high a priority (for now) as getting computational results to engineering problems that Fortran is good at: high numbers in iterations, logic controls, subroutine sub-prograsms, etc. Again thanks to all. I await more on this. ....Ron
     
  8. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #8
    Double clicking accomplished the untar.

    If you are on powerpc this seems good. If not there might be a different package that's compiled for intel. In any event, if this is right all you need to do is run:
    powerpc-apple-darwin6.8-g95

    The symlink is just to make your life easier. It's just to make the name g95 run powerpc-apple-darwin6.8-g95.

    -Lee
     
  9. macrumors 603

    mobilehaathi

    Joined:
    Aug 19, 2008
    Location:
    The Anthropocene
    #9
    When I installed the developer tools it installed gfortran as well as gcc, g++, and make. This should work for ya. FWIW, I do my scientific number crunching in C/C++ and make use of the GNU GSL libraries.
     
  10. macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
    #10
    The above directions are aimed at someone familiar with Unix. In this context "Symbolic Link" is what Apple calls (in the finder's menus) an "alias". You can do "make alias" in finder but better to use the "ln" command from the terminal. Read about "ln" first by typing "man ln" at the terminal prompt.

    The way this works is the you have (say) FooBar-3.2.1 in the bin directory but your users want to type just "foobar" so you make a link by typing
    Code:
    ln -s FooBar-3.2.1 foobar
    and now one file was two names.

    The GNU gcc compiler does C, C++, Objective C, Java, FORTRAN and Ada. It is a pretty good compiler and it supports all those llanguages on every platform on Earth. (Sun SPARC, Intel, PPC, Arm, MIPS and more) But it can not compete with sppecialized compilers that do just one language on one platform. Like for example Intel,s FORTRAN compiler.
     
  11. thread starter macrumors newbie

    Joined:
    Mar 1, 2009
    Location:
    Buffalo NY area
    #11
    Fortran Programming on Mac

    I do have a powerpc... so says "About This Mac" on my machine. So, it should work if I run: "powerpc-apple-darwin6.8-g95". So, how do I access this Unix executable file? What application do I use?
     
  12. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #12
    I am not sure I understand the question.
    powerpc-apple-darwin6.8-g95
    is the executable file. You can run it like:
    powerpc-apple-darwin6.8-g95 -o myProg myProg.F95
    where myProg.F95 is in the same directory as the binary, and myProg will be the resulting executable.

    -Lee
     
  13. thread starter macrumors newbie

    Joined:
    Mar 1, 2009
    Location:
    Buffalo NY area
    #13
    Fortran Programming on Mac

    Lee: I'm uncertain about what needs to be done to run "powerpc-apple-darwin6.8-g95". This file, a Unix executable, resides on my desktop within a folder named "bin"... a result of the download/install. Double clicking on the file results in a window that states: There is no default application specified to open the document "powerpc-apple....". It asks to choose an application.

    Is this where Xcode comes in? ...Ron
     
  14. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #14
    This is where the terminal comes in. Welcome to Unix. =)

    Under /Applications/Utilities, or wherever you have the Applications folder stashed on your machine, there is an app called terminal. When you run it, you'll be presented with the command prompt. This is where your adventure begins.

    Type:
    cd bin
    ./powerpc-apple-darwin6.8-g95

    You won't get much, but this will run the compiler. It will likely give you a message about how to use it.

    If you are not interested in knowing what's going on behind the curtain, i believe there are plugins to use other fortran compilers with XCode. Here is one:
    http://macresearch.org/new-gfortran-builds-available

    I only recommend g95 because i am familiar with it, but i do not use it with an IDE, only from the command line.

    -Lee
     
  15. thread starter macrumors newbie

    Joined:
    Mar 1, 2009
    Location:
    Buffalo NY area
    #15
    Fortran Programming on Mac

    Lee, Progress is being made, even though one small step at a time.

    I successfully got through the “cd bin” step on Terminal (see April 30 reply). After entering ” ./powerpc-apple-darwin6.8-g95 “, I received the message: “ powerpc-apple-darwin6.8-g95: No Input File “. I assume that “powerpc…..” is working in that it anticipates a Fortran code to compile. Is this correct? If so, what do I access to write the code?

    …Ron
     
  16. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #16
    You can write code in any text editor that you'd like. i am partial to the terminal-based editor vim, that you can access from the terminal by typing vim or vi. If you'd like a graphical editor, there are many that people here recommend such as TextWrangler, Smultron, etc. Once you've written a file, say:
    Code:
    program helloWorld
      implicit none
      write(6,'("Hello, World!")')
    end program
    
    and saved it as helloWorld.F95 (for simplicity, we'll assume you saved it in the same directory as the compiler for now, though you should either add the compiler's directory to your PATH by editing .bash_profile under your home directory, or adding a symbolic link to the compiler in a place that's already in your path as directed under the setup documents), you would then run:
    ./powerpc-apple-darwin6.8-g95 -o helloWorld helloWorld.F95
    This will produce an executable file called helloWorld in the same directory, which could be run with:
    ./helloWorld
    Which should produce the output:
    Hello,World!

    If you want to use an Integrated Development Environment that includes an editor, compiles things for you using a button instead of typing a command, etc. you might have to go with one of the options detailed above.

    -Lee
     
  17. thread starter macrumors newbie

    Joined:
    Mar 1, 2009
    Location:
    Buffalo NY area
    #17
    Fortran Programming on Mac

    It has been a while since I last communicated on this thread. Just thought that I'd "close the loop" and report that I'm up and running with Fortran on my G4. Vim and MacVim work great. Anyone wanting to set up Fortran on their Mac should closely follow the guidance provided through this thread.

    Thanks to all who helped me acquire this computational capability. Lee: your help is especially appreciated.
     

Share This Page