Commit 3800bfb0 authored by Alexandru Dura's avatar Alexandru Dura

Experiment code around norm

parent 919f664a
CFLAGS = -fopenmp -O3 -march=native -Wall -std=c99
LDFLAGS = -lm
SOURCES = $(wildcard *.c)
TARGETS = $(patsubst %.c,%.run,$(SOURCES))
TARGETS := $(patsubst %.c,%.static.run,$(SOURCES)) $(TARGETS)
TARGETS := $(patsubst %.c,%.dynamic.run,$(SOURCES)) $(TARGETS)
TARGETS := $(patsubst %.c,%.static.nowait.run,$(SOURCES)) $(TARGETS)
TARGETS := $(patsubst %.c,%.dynamic.nowait.run,$(SOURCES)) $(TARGETS)
DEPS = $(wildcard *.h)
CC = gcc
all : $(TARGETS)
time : $(patsubst %.run,%.time,$(TARGETS))
%.static.run : %.c $(DEPS)
$(CC) $(CFLAGS) -DSCHEDULE=static -o $@ $< $(LDFLAGS)
%.dynamic.run : %.c $(DEPS)
$(CC) $(CFLAGS) -DSCHEDULE=dynamic -o $@ $< $(LDFLAGS)
%.static.nowait.run : %.c $(DEPS)
$(CC) $(CFLAGS) -DSCHEDULE=static -DNOWAIT=nowait -o $@ $< $(LDFLAGS)
%.dynamic.nowait.run : %.c $(DEPS)
$(CC) $(CFLAGS) -DSCHEDULE=dynamic -DNOWAIT=nowait -o $@ $< $(LDFLAGS)
%.time : %.run
@echo $<
@time -f "\t%e real" ./$< > /dev/null
clean :
rm -f *.o
rm -f *.run
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <limits.h>
#include <assert.h>
#include <stdint.h>
#include <float.h>
#include "common.h"
#ifdef _OPENMP
#include <omp.h>
#endif
#define STR(s) #s
#define XSTR(s) STR(s)
#ifndef NOWAIT
#define NOWAIT
#endif
#define N_RUNS 100
#define VEC_SIZE 50000000
#define NOINLINE __attribute__((noinline))
void NOINLINE initialize(double *d, int n, double val) {
#pragma omp for NOWAIT \
schedule(SCHEDULE)
for (int i = 0; i < n; ++i) {
d[i] = val;
}
}
double NOINLINE sqsum(const double *d, int n) {
double sum = 0.0;
#pragma omp for NOWAIT \
schedule(SCHEDULE)
for (int i = 0; i < n; ++i) {
double tmp = d[i] * d[i];
sum += tmp;
}
return sum;
}
double NOINLINE norm_experiment(double *d, int n) {
double s = 0.0;
#pragma omp parallel default(none) \
reduction(+:s) \
shared(d, n)
{
initialize(d, n, 1.0);
s = sqsum(d, n);
}
return sqrt(s);
}
int main(int argc, char **argv) {
double r;
double reported_time = DBL_MAX;
double *d = (double*) malloc(VEC_SIZE * sizeof(double));
for (int i = 0; i < N_RUNS; ++i) {
double elapsed_time;
TIME_REGION(elapsed_time,
r = norm_experiment(d, VEC_SIZE));
reported_time = MIN(reported_time, elapsed_time);
// reported_time += elapsed_time;
}
int n_threads;
#ifdef _OPENMP
#pragma omp parallel
{
n_threads = omp_get_num_threads();
}
#else
n_threads = 1;
#endif
printf ("%d," XSTR(SCHEDULE) "," XSTR(NOWAIT) ",%f,%f\n", n_threads, reported_time, r);
return 0;
}
......@@ -15,7 +15,6 @@
#define STR(s) #s
#define XSTR(s) STR(s)
#define SCHEDULE static
#define N_RUNS 100
#define VEC_SIZE 50000000
......@@ -48,14 +47,15 @@ double NOINLINE norm_experiment(double *d, int n) {
int main(int argc, char **argv) {
double r;
double min_time = DBL_MAX;
double reported_time = DBL_MAX;
double *d = (double*) malloc(VEC_SIZE * sizeof(double));
for (int i = 0; i < N_RUNS; ++i) {
double elapsed_time;
TIME_REGION(elapsed_time,
r = norm_experiment(d, VEC_SIZE));
min_time = MIN(min_time, elapsed_time);
// reported_time += elapsed_time;
reported_time = MIN(reported_time, elapsed_time);
}
int n_threads;
......@@ -68,7 +68,7 @@ int main(int argc, char **argv) {
n_threads = 1;
#endif
printf ("%d," XSTR(SCHEDULE) ",%f,%f\n", n_threads, min_time, r);
printf ("%d," XSTR(SCHEDULE) ",%f,%f\n", n_threads, reported_time, r);
return 0;
}
#!/bin/bash
#SBATCH -n 20
#SBATCH -N 1 # force all cores on one node
#SBATCH -t 00:20:00
#SBATCH -J series
#SBATCH -o series_%j.out
#SBATCH -e series_%j.err
#SBATCH -A computehpc
cat $0 # put the script in the output file
module purge
module load GCC/8.3.0
module list
ARGS=$@
FILENAME=results_20_${HOSTNAME}_${SLURM_JOB_ID}.csv
echo "" > $FILENAME
# bind threads to cores
export OMP_PLACES=cores
export OMP_PROC_BIND=TRUE
SCHEDULE="static dynamic"
for S in $SCHEDULE
do
./norm-orphan.$S.nowait.run | tee -a $FILENAME
./norm-orphan.$S.run | tee -a $FILENAME
./norm.$S.run | tee -a $FILENAME
./norm.$S.nowait.run | tea -a $FILENAME
done
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment