commtechs bench: add calc_mat calculation lib

* Add a matrice calculation as one of the possible calculation
* Modify the makefile to permit calculation lib compilation
* Reorganize the makefile to be able to execute the default target
This commit is contained in:
Thomas Preud'homme 2009-06-19 20:53:34 +02:00 committed by Thomas Preud'homme
parent f9128c0348
commit f4b3904541
2 changed files with 88 additions and 32 deletions

View File

@ -1,61 +1,67 @@
# Directories
OBJDIR=obj
BINDIR=bin
SRCDIR=src
INCDIR=include
LIBDIR=lib
LOGDIR=logs
LOCALDIR=$(HOME)/local
PAPIHIGHLEVELLIBDIR=lib
PAPIHIGHLEVELINCDIR=include
OBJDIR:=obj
BINDIR:=bin
SRCDIR:=src
INCDIR:=include
LIBDIR:=lib
LOGDIR:=logs
LOCALDIR:=$(HOME)/local
PAPIHIGHLEVELLIBDIR:=lib
PAPIHIGHLEVELINCDIR:=include
CALCDIR:=calculation
# Compilation flags
# I know -finline-functions and -finline-functions-called-once are enabled by
# -O3 but I did this in case gcc behaviour change one day
CFLAGS=-g -O3 -finline-functions -finline-functions-called-once -Wall -Werror
LDFLAGS=-L$(LIBDIR) -L$(LOCALDIR)/$(PAPIHIGHLEVELLIBDIR) -Wl,-rpath-link,$(HOME)/local/lib -lpthread -lpapihighlevel -ldl
CFLAGS:=-g -O3 -finline-functions -finline-functions-called-once -Wall -Werror
LDFLAGS:=-L$(LIBDIR) -L$(LOCALDIR)/$(PAPIHIGHLEVELLIBDIR) -Wl,-rpath-link,$(HOME)/local/lib -lpthread -lpapihighlevel -ldl
# Executables
CC=gcc
# Files
BINNAMES=asm_cache_comm c_cache_comm pipe_comm shared_mem_comm shared_mem_opt_comm jikes_barrier_comm fake_comm
BINS=$(patsubst %, $(BINDIR)/%, $(BINNAMES))
MAIN_OBJS=main.o common.o
COMMON_LIB_OBJS=common.o
BINNAMES:=asm_cache_comm c_cache_comm pipe_comm shared_mem_comm shared_mem_opt_comm jikes_barrier_comm fake_comm
CALCLIBSNAMES:=calc_mat
BINS:=$(patsubst %,$(BINDIR)/%,$(BINNAMES))
CALCLIBS:=$(patsubst %,$(LIBDIR)/lib%.so.1,$(CALCLIBSNAMES))
MAIN_OBJS:=main.o common.o
COMMON_LIB_OBJS:=common.o
.PHONY: all tidy clean distclean symlink
.PHONY: all tidy clean distclean
.SECONDARY:
.SUFFIXES: .c .o
default: $(BINS)
ifneq (,$(findstring $(MAKECMDGOALS),$(BINS)))
BASE_TARGET=$(patsubst $(BINDIR)/%_comm,%,$(MAKECMDGOALS))
default: $(BINS) $(CALCLIBS)
# Compilation of binary
$(BINDIR)/$(BASE_TARGET)_comm: $(patsubst %,$(OBJDIR)/$(BASE_TARGET)_%,$(MAIN_OBJS)) $(LIBDIR)/lib$(BASE_TARGET).a
$(BINDIR)/%_comm: $(patsubst %,$(OBJDIR)/\%/%,$(MAIN_OBJS)) $(LIBDIR)/lib%.a
if [ ! -d $(BINDIR) ] ; then mkdir $(BINDIR) ; fi
$(CC) -o $@ $^ $(LDFLAGS)
# Compilation of library
$(LIBDIR)/lib$(BASE_TARGET).a: $(OBJDIR)/$(BASE_TARGET).o $(patsubst %,$(OBJDIR)/$(BASE_TARGET)_%,$(COMMON_LIB_OBJS))
# Creation of comm library
$(LIBDIR)/lib%.a: $(OBJDIR)/%.o $(patsubst %,$(OBJDIR)/\%/%,$(COMMON_LIB_OBJS))
if [ ! -d $(LIBDIR) ] ; then mkdir $(LIBDIR) ; fi
$(AR) -rcus $@ $^
# Compile common source files
$(OBJDIR)/$(BASE_TARGET)_%.o: $(SRCDIR)/%.c symlink
if [ ! -d $(OBJDIR) ] ; then mkdir $(OBJDIR) ; fi
$(CC) $(CFLAGS) -I$(INCDIR) -I$(LOCALDIR)/$(PAPIHIGHLEVELINCDIR) -c $< -o $@
endif
# Creation of calc library
$(LIBDIR)/libcalc_%.so.1: $(OBJDIR)/$(CALCDIR)/calc_%.o
if [ ! -d $(LIBDIR) ] ; then mkdir $(LIBDIR) ; fi
$(CC) $(LDFLAGS) -shared -Wl,-soname,libcalc_$*.so.1 -o $@ $<
# Compile non common source files
$(OBJDIR)/%.o: $(SRCDIR)/%.c symlink
# Compile lib specific source files
$(OBJDIR)/%.o: $(SRCDIR)/%.c $(INCDIR)/%_comm.h $(INCDIR)/commtech.h
if [ ! -d $(OBJDIR) ] ; then mkdir $(OBJDIR) ; fi
cd $(INCDIR) ; ln -sfT $*_comm.h specific_comm.h
$(CC) $(CFLAGS) -I$(INCDIR) -c $< -o $@
symlink:
ln -sfT $(BASE_TARGET)_comm.h $(INCDIR)/specific_comm.h
# Rule for compiling common source files using libcomm is at the end of
# this file, after the .SECONDEXPANSION target
# Compile source files not using libcomm
$(OBJDIR)/$(CALCDIR)/%.o: $(SRCDIR)/$(CALCDIR)/%.c
if [ ! -d $(OBJDIR) ] ; then mkdir $(OBJDIR) ; fi
if [ ! -d $(OBJDIR)/$(CALCDIR) ] ; then mkdir $(OBJDIR)/$(CALCDIR) ; fi
$(CC) $(CFLAGS) -I$(INCDIR) -c $< -o $@
#.%.d: %.c
# gcc $(CFLAGS) -MM $^ | sed -e 's/\([^:]*\):\(.*\)/\1 $@: \2 Makefile/' > $@
@ -82,3 +88,13 @@ distclean: clean
#endif
#endif
#endif
.SECONDEXPANSION:
# Compile common source files using libcomm
$(OBJDIR)/%.o: $(SRCDIR)/$$(*F).c $(INCDIR)/$$(*D)_comm.h $(INCDIR)/commtech.h
if [ ! -d $(OBJDIR) ] ; then mkdir $(OBJDIR) ; fi
if [ ! -d $(OBJDIR)/$(*D) ] ; then mkdir $(OBJDIR)/$(*D) ; fi
cd $(INCDIR) ; ln -sfT $(*D)_comm.h specific_comm.h
$(CC) $(CFLAGS) -I$(INCDIR) -I$(LOCALDIR)/$(PAPIHIGHLEVELINCDIR) -c $< -o $@

View File

@ -0,0 +1,40 @@
#include <stdlib.h>
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
static int *mat, *vect;
static int li;
static int n = 16, m = 16; /* Size of the matrice: n lines, m columns */
void init_calc(void)
{
int i;
srand(42);
mat = (int *) malloc(n * m * sizeof(int));
vect = (int *) malloc(m * sizeof(int));
for (i = 0; i < n * m; i++)
mat[i] = rand();
li = 0;
}
void *do_calc(void)
{
int co, p = 0;
for (co = 0; co < m; co++)
p += mat[li * m + co] * vect[li];
mat[li * m] = p;
if (unlikely(++li >= n))
li = 0;
return &mat[li * m];
}
void end_calc(void)
{
free(mat);
free(vect);
}