# Makefile for the QR optimizer $Revision: 1.12 $

#
# Simple architecture detection.
#

ARCH=$(strip $(shell uname -s))

#
# These definitions are for IBM RS/6000 Power2
# architecture using the standard IBM compilers.
#

ifeq ($(ARCH),AIX)
CC = xlc
FC = xlf 
CCFLAGS = -qtune=pwr2 -O3
FCFLAGS = -qtune=pwr2 -qhot -O3
LFLAGS = -lm
endif

#
# These definitions are for GNU/Linux on Intel PPro/PII
# architecture, using the EGCS or PGCC compilers.
#

ifeq ($(ARCH),Linux)
CC = gcc
FC = g77 
CCFLAGS = -mcpu=i686 -Wall -malign-double -O6
FCFLAGS = -mcpu=i686 -Wall -malign-double -O6
#CCFLAGS = -Wall -g -mcpu=i686 -O0 -pg
#LFLAGS = -lm -g -lefence -pg
LFLAGS = -lm
endif

#
# The heuristic requires a way to have some set of
# rows in the system ordered, so that they form a
# valid system, that is, one with a non-zero diagonal.
#
# Two ways of ordering rows is implemented.  Since
# there usually is a large number of ways to order the
# rows, and we would be best off by examining all possible
# orderings (in order to find the ordering that minimizes
# the estimated cost of elimination) one method that does
# exactly this is provided.  This is the recursive ordering
# algorithm.  To use it, uncomment the ROWORDER_RECORDER define
# below.
#
# Since it can take very long time to examine all possible
# orderings, another method is also provided.  This is the 
# bipartite ordering method. To use it, uncomment the ROWORDER_BIPORDER
# define below.
#
# If the system is largar than 40x40, or has more non-zeros than 10-12%,
# the recursive ordering will probably be to slow, and the bipartite ordering
# algorithm should be used.
# However, the recursive ordering algorithm will often give better results, 
# and if the system is small enough to be optimized using that ordering, it
# definitely should be.
#

#ROWORDER_RECORDER=1
ROWORDER_BIPORDER=1

#
# The rest of the makefile is rather uninteresting.
#

OBJS = optimqr.o loadsys.o printsys.o systools.o \
       dmh.o bb.o heuristic.o  seqout.o


ifdef ROWORDER_RECORDER
OBJS += recorder.o
CCFLAGS += -DROWORDER_RECORDER=1
endif

ifdef ROWORDER_BIPORDER
OBJS += biporder.o
CCFLAGS += -DROWORDER_BIPORDER=1
endif


RGOBJS = regress.o fastqr.o

SLUCS = sluperf.c
SLUCFLAGS = -O6 -mcpu=i686 -Wall -lm

# Targets

.PHONY: all

all: optimqr sluperf regress

optimqr: Makefile $(OBJS)
	$(CC) -o optimqr $(OBJS) $(LFLAGS)

sluperf: Makefile $(SLUCS)
	$(CC) -o sluperf $(SLUCS) $(SLUCFLAGS) SuperLU/superlu_linux.a SuperLU/blas_linux.a \
	-ISuperLU/SRC

%.o: %.c Makefile optimqr.h
	$(CC) $(CCFLAGS) -c $< -o $@ 

regress: Makefile $(RGOBJS) 
	$(FC) -o regress $(RGOBJS) $(LFLAGS)

%.o: %.f Makefile 
	$(FC) $(FCFLAGS) -c $< -o $@

coffee:
	@echo You wish

clean:
	rm -f core optimqr $(OBJS) *~

