Thursday, February 19, 2004

Porting resp to MacOS X with plep Source

Last night I got an email from York University asking how to compile resp of AMBER software on their G5. Min, the person who sent the email, was using the MACHINE file I posted on my weblog. Min couldn't use my MACHINE file for compiling resp.

After a hour or so, I figured out some problems and their solutions.

Min's error log suggests that neither MACHINE file nor Compile script is working:

$ make
cd ../lib ; ./Makelist ../lib/mexit.o ../lib/amopen.o ../lib/lapack.o
make[1]: `mexit.o' is up to date.
make[1]: `amopen.o' is up to date.
./Compile L2 -P -DDPREC -o lapack.o lapack.f
csh: L2: Undefined variable.
make[1]: *** [lapack.o] Error 1
make: *** [libobj] Error 1
Unfortunately, I never used resp command nor ever tried to compile it before. Therefore I need to start from beginning in order to find out what happened. The clue is that Min was using the resp source in plep package of AMBER, which is kinda free in the InterNet. After a short google search, I found it's in the file repository of AMBER.

The hierarchy of this distribution of plep is from AMBER 5 but it only includes crucial files. The immediate trouble inside src/ is the directory Machine/, the script "Compile" requires a symbolic linked file call "MACHINE". If you are familiar with HFS+ that MacOS X uses, you probably already know the filesystem is not case-sensitive. Because "MACHINE" is equal to "Machine", we need to rename "Machine/" to "Machines/". Of course, you need to check the "Compile" script and the "MACHINE" files later we'll mention to see if you need to rename the fixed variable.

Then I copy the "Machines/Machine.bsd" file to my customized file, say, "Machines/Machine.macosx" and modify the "Machine.macosx" file. One of the things you need to check is that the C preprocessor is located at "/usr/bin/cpp", not "/lib/cpp" as the old setting suggested. After then, you might need to change f77 to g77 because the c-shell script "Compile" seems to be not recognizing the f77 aliases you might have for your tcsh. Oh, don't forget running this "ln -s Machines/Macine.macosx ./MACHINE".

Another thing that maybe very important is that G5 is a big-endian machine, the related issues is addressed in the "mksrc" file, although we don't need it to compile resp. So you can enter the "resp" directory, and run "make bigsource" command. In this case, the command only generates a file called "resp_all.for" without actually compiling it. You might want to modify the "Makefile" file adding some rules. But right now, you can just use "g77 -O2 resp_all.for -o resp" to create the resp program.

If any of my reader of this blog entry has questions about compiler "g77" or "XLF/XLC", don't ask me, do ask the technical support of Apple or IBM.

Supplemental Materials:
1. diff file between Machine.bsd and Machine.macosx
2. My result:
[mjhsieh:plep/src/resp] mjhsieh% make bigsource
SYSDIR=`../sysdir dir` ; cd $SYSDIR ; make sys.f
make[1]: `sys.f' is up to date.
SYSSRC=`../sysdir src` ; ../Compile CPPONLY -o resp_all.f
                 resp.f ../lib/mexit.f ../lib/amopen.f ../lib/lapack.f $SYSSRC ;
                 ../Compile L1 -P resp_all.f ;
                ../Compile LOAD -o resp resp_all.o
Making source: machine is Generic BSD Unix
cat resp.f | /usr/bin/cpp -P -I/mjhsieh/plep/src/lib
     -DBSD -DISTAR2 -DREGNML -DEWALD   >>  resp_all.f
cat ../lib/mexit.f | /usr/bin/cpp -P -I/mjhsieh/plep/src/lib
     -DBSD -DISTAR2 -DREGNML -DEWALD   >>  resp_all.f
cat ../lib/amopen.f | /usr/bin/cpp -P -I/mjhsieh/plep/src/lib
     -DBSD -DISTAR2 -DREGNML -DEWALD   >>  resp_all.f
cat ../lib/lapack.f | /usr/bin/cpp -P -I/mjhsieh/plep/src/lib
     -DBSD -DISTAR2 -DREGNML -DEWALD   >>  resp_all.f
cat /mjhsieh/plep/src/Machines/bsd/sys.f | /usr/bin/cpp -P -I/mjhsieh/plep/src/lib
     -DBSD -DISTAR2 -DREGNML -DEWALD   >>  resp_all.f
Made source for machine: Generic BSD Unix
cat resp_all.f | /usr/bin/cpp -I/mjhsieh/plep/src/lib -P
     -DBSD -DISTAR2 -DREGNML -DEWALD   > _resp_all_.f
g77 -c _resp_all_.f
g77 -o resp resp_all.o
[mjhsieh:plep/src/resp] mjhsieh% ls 
0README     files.h     resp*       resp_all.f
Makefile    readit.f    resp.f      resp_all.o