CS计算机代考程序代写 algorithm b’2021_Spring_Exam01_Part1.tar.gz’

b’2021_Spring_Exam01_Part1.tar.gz’

CC=g++
CFLAGS= -O3
DEPS =
OBJ = exam01_part1_test.o
EXEC = exam01_part1_test
LIB = _exam01_part1
LIB_DIR = abc123_exam01_part1

%.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) #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
void myfunc_orig(double *a, double *b, int I, int J)
{
for (int j = 1; j < J-1; j++) for (int i = 1; i < I-1; i++) { b[i * J + j] = 0.0; for (int k = -1; k <= 1; k++) for (int m = -1; m <= 1; m++) b[i * J + j] += pow(a[(i+k) * J + (j+m)], 2.0); } } void compareOutputs(double *output1, double *output2, int length) { for (int i = 0; i < length; i++) for (int j = 0; j < length; j++) { if (output1[i * length + j] != output2[i * length + j]) { printf("Outputs do not match! (%f, %f)\n", output1[i * length + j], output2[i * length + j]); return; } } printf("Output match, test passed!\n"); } int main(int argc, char *argv[]) { int N = 10000; double d_S, d_E; // some declarations double *a = new double[N * N]; double *b = new double[N * N]; double *b2 = new double[N * N]; // populate memory with some random data for (int i = 0; i < N * N; i++) { a[i] = i; } // run the original for functional verification myfunc_orig(a, b, N, N); // start benchmark get_walltime(&d_S); // iterative test loop myfunc(a, b2, N, N); // end benchmark get_walltime(&d_E); // check the two matrices compareOutputs(b, b2, N); // report results printf("Elapsed time: %f\n", d_E - d_S); return 0; } CC=g++ CFLAGS= -I. -O3 DEPS = exam01_part1.hpp OBJ = exam01_part1.o LIB = lib_exam01_part1.a %.o: %.cpp $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) $(LIB): $(OBJ) ar rcs $@ $(OBJ) .PHONY: clean clean: rm -f $(OBJ) $(LIB) #include

// complex algorithm for evaluation
void myfunc(double *a, double *b, int I, int J)
{

for (int j = 1; j < J-1; j++) for (int i = 1; i < I-1; i++) { b[i * J + j] = 0.0; for (int k = -1; k <= 1; k++) for (int m = -1; m <= 1; m++) b[i * J + j] += pow(a[(i+k) * J + (j+m)], 2.0); } } void myfunc(double *a, double *b, int I, int J); 2021_Spring_Exam01_Part1/Makefile 2021_Spring_Exam01_Part1/exam01_part1_test.cpp 2021_Spring_Exam01_Part1/abc123_exam01_part1/Makefile 2021_Spring_Exam01_Part1/abc123_exam01_part1/exam01_part1.cpp 2021_Spring_Exam01_Part1/abc123_exam01_part1/exam01_part1.hpp