diff --git a/newlib/examples/Makefile b/newlib/examples/Makefile index 38a21cc6..e1a373f9 100644 --- a/newlib/examples/Makefile +++ b/newlib/examples/Makefile @@ -3,6 +3,7 @@ NEWLIB = ../x86/i586-metalsvm-elf32 MAKE = make STRIP_DEBUG = --strip-debug KEEP_DEBUG = --only-keep-debug +LDFLAGS = # other implicit rules %.o : %.c @@ -10,7 +11,13 @@ KEEP_DEBUG = --only-keep-debug default: all -all: hello tests +all: hello tests jacobi + +jacobi: jacobi.o + $(CC_FOR_TARGET) -T link.ld -o $@ $(LDFLAGS) $< -lm + $(OBJCOPY_FOR_TARGET) $(KEEP_DEBUG) $@ $@.sym + $(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $@ + chmod a-x $@.sym tests: tests.o $(CC_FOR_TARGET) -T link.ld -o $@ $(LDFLAGS) $< diff --git a/newlib/examples/jacobi.c b/newlib/examples/jacobi.c new file mode 100644 index 00000000..a899d87e --- /dev/null +++ b/newlib/examples/jacobi.c @@ -0,0 +1,200 @@ +/* + * Copyright 2011 Stefan Lankes, Alexander Pilz, Maximilian Marx, Michael Ober, + * Chair for Operating Systems, RWTH Aachen University + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#undef errno +extern int errno; + +#define MATRIX_SIZE 256 +#define MAXVALUE 1337 +#define PAGE_SIZE 4096 +#define CACHE_SIZE (256*1024) +#define ALIGN(x,a) (((x)+(a)-1)&~((a)-1)) + +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) + return -2; /* Error */ + + (*A)[0] = (double*) malloc((N+1)*N*sizeof(double)); + + if (**A == NULL) + 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, norm_res, max = 0.0; + double** A=0; + double* X; + double* X_old, xi; + double start,stop; + + if (generate_empty_matrix(&A,MATRIX_SIZE) < 0) + { + printf("generate_empty_matrix() failed...\n"); + fflush(stdout); + exit(-1); + + } + + printf("generate_empty_matrix() done...\n"); + fflush(stdout); + + 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]); + } + 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: %f s\n", stop-start); + + free((void*) X_old); + free((void*) X); + + return 0; +}