/* * Copyright (c) 2010-2011, Stefan Lankes, RWTH Aachen University * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #define MATRIX_SIZE 128 #define MAXVALUE 1337 #define PAGE_SIZE 4096 #define CACHE_SIZE (256*1024) #define ALIGN(x,a) (((x)+(a)-1)&~((a)-1)) double mysecond() { struct timeval tp; struct timezone tzp; int i; i = gettimeofday(&tp,&tzp); return ( (double) tp.tv_sec + (double) tp.tv_usec * 1.e-6 ); } static int generate_empty_matrix(double*** A , unsigned int N) { unsigned int iCnt; int i,j; *A = (double**) malloc((N+1)*sizeof(double*)); if (*A == NULL) { printf("*A is NULL...\n"); return -1; /* Error */ } (*A)[0] = (double*) malloc((N+1)*N*sizeof(double)); if (**A == NULL) { printf("**A is NULL...\n"); return -2; /* Error */ } for(iCnt=1; iCnt Sum |A[i][j]| with (i != j) */ (*A)[i][i] = sum + 2.0; (*A)[i][N] += sum + 2.0; } return 0; } int main(int argc, char **argv) { double* temp; unsigned int i, j, iter_start, iter_end; unsigned int iterations = 0; double error, norm, max = 0.0; double** A=0; double* X; double* X_old, xi; double start, end; if (generate_empty_matrix(&A,MATRIX_SIZE) < 0) { printf("generate_empty_matrix() failed...\n"); exit(-1); } printf("generate_empty_matrix() done...\n"); X = (double*) malloc(MATRIX_SIZE*sizeof(double)); X_old = (double*) malloc(MATRIX_SIZE*sizeof(double)); if(X == NULL || X_old == NULL) { printf("X or X_old is NULL...\n"); exit(-1); } for(i=0; i 0.01f) { printf("Result is on position %d wrong (%f != 1.0)\n", i, X[i]); exit(1); } } printf("maximal error is %f\n", max); printf("\nmatrix size: %d x %d\n", MATRIX_SIZE, MATRIX_SIZE); printf("number of iterations: %d\n", iterations); printf("calculation time: %lf s\n", end-start); free((void*) X_old); free((void*) X); return 0; }