/* matmult.c * Test program to do matrix multiplication on large arrays. * * Intended to stress virtual memory system. * * Ideally, we could read the matrices off of the file system, * and store the result back to the file system! * * ----------------------------------------------------- * This file is part of the Nachos-RiscV distribution * Copyright (c) 2022 University of Rennes 1. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details * (see see ). * ----------------------------------------------------- */ #include "userlib/syscall.h" #define Dim 10 /* sum total of the arrays doesn't fit in * physical memory */ /* The matrices to be filled-in and multiplied */ int A[Dim][Dim]; int B[Dim][Dim]; int C[Dim][Dim]; int main() { int i, j, k; Write("Start matmult\n",14,CONSOLE_OUTPUT); for (i = 0; i < Dim; i++) /* first initialize the matrices */ for (j = 0; j < Dim; j++) { A[i][j] = i; B[i][j] = j; C[i][j] = 0; } for (i = 0; i < Dim; i++) /* then multiply them together */ for (j = 0; j < Dim; j++) for (k = 0; k < Dim; k++) C[i][j] += A[i][k] * B[k][j]; Exit(C[Dim-1][Dim-1]); /* and then we're done */ return 0; }