b’2021_Spring_Exam01_Part2.tar.gz’
CC=g++
CFLAGS= -O3
DEPS =
OBJ = exam01_part2_test.o
EXEC = exam01_part2_test
LIB = _exam01_part2
LIB_DIR = abc123_exam01_part2
%.o: %.cpp $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) -I. -I./$(LIB_DIR)
$(EXEC): $(OBJ)
module load gcc; \
cd $(LIB_DIR) && $(MAKE);
module load gcc; \
$(CC) -o $@ $^ $(CFLAGS) -L./$(LIB_DIR)/ -l$(LIB) -L.
.PHONY: clean
clean:
cd $(LIB_DIR) && $(MAKE) clean
rm -f $(OBJ) $(EXEC)
CC=g++
CFLAGS= -I. -O3
DEPS= exam01_part2.hpp
OBJ= exam01_part2.o
LIB= lib_exam01_part2.a
%.o: %.cpp $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
$(LIB): $(OBJ)
ar rcs $@ $(OBJ)
.PHONY: clean
clean:
rm -f $(OBJ) $(LIB)
#include
#include
// complex algorithm for evaluation
double myPowerCalc(int16_t *ps_input, int32_t N)
{
double power = 0.0;
for (int i = 0; i < N; i++)
{
power += pow((double)ps_input[i], 2.0) / (double)N;
}
return (power);
}
double myPowerCalc(int16_t *ps_input, int32_t N);
#include
#include
#include
#include
#include
void get_walltime(double* wcTime) {
struct timeval tp;
gettimeofday(&tp, NULL);
*wcTime = (double)(tp.tv_sec + tp.tv_usec/1000000.0);
}
// complex algorithm for evaluation
double powerCalc(int16_t *ps_input, int32_t N)
{
double power = 0.0;
for (int i = 0; i < N; i++) { power += pow((double)ps_input[i], 2.0) / (double)N; } return (power); } int main(int argc, char *argv[]) { int N = 1000000000; double d_S, d_E; // some declarations int16_t *a = new int16_t[N]; double p, p2; // populate memory with some random data for (int i = 0; i < N; i++) { a[i] = i % 1024; } // run the original for functional verification p = powerCalc(a, N); // start benchmark get_walltime(&d_S); // iterative test loop p2 = myPowerCalc(a, N); // end benchmark get_walltime(&d_E); // check the two values if (p != p2) printf("Values do not match! %f, %f\n", p, p2); else printf("Values match! %f, %f\n", p, p2); // report results printf("Elapsed time: %f\n", d_E - d_S); return 0; } 2021_Spring_Exam01_Part2/Makefile 2021_Spring_Exam01_Part2/abc123_exam01_part2/Makefile 2021_Spring_Exam01_Part2/abc123_exam01_part2/exam01_part2.cpp 2021_Spring_Exam01_Part2/abc123_exam01_part2/exam01_part2.hpp 2021_Spring_Exam01_Part2/exam01_part2_test.cpp