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

b’2021_Spring_Hw02_Part2.tar.gz’

CC=g++
CFLAGS= -O3
DEPS =
OBJ = hw2_part2_test.o
EXEC = hw2_part2_test
LIB = _hw2_part2
LIB_DIR = abc123_hw2_part2

%.o: %.cpp $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) -I. -I./$(LIB_DIR) $(EXEC): $(OBJ) module load gcc/7.3.1; \ cd $(LIB_DIR) && $(MAKE); module load gcc/7.3.1; \ $(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. DEPS=hw2_part2.hpp LIB=lib_%.a cpp_files=$(wildcard *.cpp) a_files=$(patsubst %.cpp,$(LIB),$(cpp_files)) %.o: %.cpp $(DEPS) $(CC) -c -o $@ $< $(CFLAGS); $(LIB): %.o ar rcs $@ $< all: $(a_files) .PHONY: clean clean: rm -f $(wildcard *.o) $(wildcard *.a) /** * This is a simple header file that declares the function in the library. */ void matrix_mult(double *A, double *B, double *C, int N); 2021_Spring_Hw02_Part2/abc123_hw2_part2/hw2_part2.cpp 2021_Spring_Hw02_Part2/abc123_hw2_part2/hw2_part2.cpp // complex algorithm for evaluation void matrix_mult(double *A, double *B, double *C, int N) {     for (int i = 0; i < N; i++)         for (int j = 0; j < N; j++)         {             C[i * N + j] = 0;                 for (int k = 0; k < N; k++)                 {                     C[i * N + j] += A[i * N + k] * B[k * N + j];                 }         } } hw2_part2.o #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 matrix_mult_orig(double *A, double *B, double *C, int N)
{
for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) { C[i * N + j] = 0; for (int k = 0; k < N; k++) { C[i * N + j] += A[i * N + k] * B[k * N + j]; } } } 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! (%i, %i) (%f, %f)\n", i, j, output1[i * length + j], output2[i * length + j]); return; } } printf("Output match, test passed!\n"); } int main(int argc, char *argv[]) { int N = 2000; double d_S, d_E; // some declarations double *A = new double[N * N]; double *B = new double[N * N]; double *C = new double[N * N]; double *orig_C = new double[N * N]; // populate memory with some random data for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { A[i * N + j] = i * i; B[i * N + j] = (double)j / (double) (i + 1); } } // run the original for functional verification matrix_mult_orig(A, B, orig_C, N); // start benchmark get_walltime(&d_S); // iterative test loop matrix_mult(A, B, C, N); // end benchmark get_walltime(&d_E); // check the two matrices compareOutputs(orig_C, C, N); // report results printf("Elapsed time: %f\n", d_E - d_S); // cleanup! delete[] A; delete[] B; delete[] C; delete[] orig_C; return 0; } 2021_Spring_Hw02_Part2/hw2_part2_test 2021_Spring_Hw02_Part2/Makefile 2021_Spring_Hw02_Part2/abc123_hw2_part2/Makefile 2021_Spring_Hw02_Part2/abc123_hw2_part2/hw2_part2.hpp 2021_Spring_Hw02_Part2/abc123_hw2_part2/hw2_part2.cpp 2021_Spring_Hw02_Part2/abc123_hw2_part2/lib_hw2_part2.a 2021_Spring_Hw02_Part2/hw2_part2_test.o 2021_Spring_Hw02_Part2/hw2_part2_test.cpp