diff --git a/mex/sources/kalman/qt/test/Makefile b/mex/sources/kalman/qt/test/Makefile index 8e82c01db233375b3d220ce45ee88643630cbdca..5e2793ca26a26a15a64b9881a961fe4d66c06e51 100644 --- a/mex/sources/kalman/qt/test/Makefile +++ b/mex/sources/kalman/qt/test/Makefile @@ -1,12 +1,12 @@ # $Id: Makefile 531 2005-11-30 13:49:48Z kamenik $ # Copyright 2005, Ondra Kamenik -DEBUG = yes +#DEBUG = yes #LD_LIBS := -llapack -lcblas -lf77blas -latlas -lg2c CC_FLAGS := -DMATLAB -DWINDOWS -DNO_BLAS_H -DNO_LAPACK_H \ - -Wall -I../cc -I../sylv/cc -I../cc \ + -Wall -I../cc -I../../sylv/cc -I../cc \ -Ic:/"Program Files"/MATLAB_SV71/extern/include #-pg ifeq ($(DEBUG),yes) @@ -14,8 +14,8 @@ ifeq ($(DEBUG),yes) # CC_FLAGS := -DTIMING_LOOP -DDEBUG $(CC_FLAGS) -g KALMANLIB := kalmanlib_dbg.a else -# CC_FLAGS := $(CC_FLAGS) -O2 - CC_FLAGS := -DTIMING_LOOP $(CC_FLAGS) -O2 +# CC_FLAGS := $(CC_FLAGS) -O3 + CC_FLAGS := -DTIMING_LOOP $(CC_FLAGS) -O3 KALMANLIB := kalmanlib.a endif @@ -53,11 +53,19 @@ dummy.ch: %.o: %.cpp $(hsource) $(cppsource) c++ $(CC_FLAGS) -c $*.cpp +dgemvm_exe.exe: dgemvm_exe.o $(qtobjs) $(hsource) $(cppsource) + gcc $(CC_FLAGS) -o dgemvm_exe.exe dgemvm_exe.o ascii_array.o \ + $(qtobjs) $(LD_LIBS) + qtamvm_exe.exe: qtamvm_exe.o $(qtobjs) $(hsource) $(cppsource) gcc $(CC_FLAGS) -o qtamvm_exe.exe qtamvm_exe.o ascii_array.o \ $(qtobjs) $(LD_LIBS) -all: $(objects) qtamvm_exe.exe # $(cppsource) $(hsource) $(kalmanhsource) $(kalmancppsource) +qtvmvm_exe.exe: qtvmvm_exe.o $(qtobjs) $(hsource) $(cppsource) + gcc $(CC_FLAGS) -o qtvmvm_exe.exe qtvmvm_exe.o ascii_array.o \ + $(qtobjs) $(LD_LIBS) + +all: $(objects) dgemvm_exe.exe qtvmvm_exe.exe qtamvm_exe.exe # $(cppsource) $(hsource) $(kalmanhsource) $(kalmancppsource) clear: rm -f *.o diff --git a/mex/sources/kalman/qt/test/dgemvm_exe.cpp b/mex/sources/kalman/qt/test/dgemvm_exe.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8c52b1932c7e8be93c23764347b846a77e247b86 --- /dev/null +++ b/mex/sources/kalman/qt/test/dgemvm_exe.cpp @@ -0,0 +1,108 @@ +/* +* Copyright (C) 2008-2009 Dynare Team +* +* This file is part of Dynare. +* +* Dynare 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, either version 3 of the License, or +* (at your option) any later version. +* +* Dynare 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. +* +* You should have received a copy of the GNU General Public License +* along with Dynare. If not, see <http://www.gnu.org/licenses/>. +*/ + +/****************************************************** +% +% This provides an interface to BLAS dgemv f90 library function +% to multiply Quasi trinagular matrix (T) with a vector a +% +% function [a] = dgevm(QT,a) +% +% use: +% dgemvm_exe QTt_file a_file size [loops - if enabled] +% +% NOTE: due to fortran matrix orientation, input matrices need to be passed +% as transposed so QTt instead QT +% +% 1. Ta = dgemv(Ld;a;n)+TV(T1;a;n). +% +% INPUTS +% T [double] mm*mm transition matrix of the state equation. +% a [double] mm state vector. +% +% OUTPUTS +% a update [double] mm vector of the state equation. +% as file: a_file_out +**********************************************************/ + +#include "cppblas.h" +#include <stdio.h> +#include <math.h> +#include "ascii_array.h" +#include <iostream> +#include <stdexcept> +#include <malloc.h> + +int main(int argc, char* argv[]) + { + + if (argc < 3 ) + { + printf("Must have min 2 input parameters.\n"); + exit(1); + } + + try + { + // make input matrices + int n=atoi(argv[3]); + double *Ta ; + AsciiNumberArray QT, a; + QT.GetMX(argv[1],n,n); + a.GetMX(argv[2],n,1); + const double alpha=1.0; + const double beta=0.0; + int inc =1; + //alpha=1.0;beta=0.0; + // create output and upload output data + Ta=(double *)calloc(n, sizeof(double)); + + +#ifdef TIMING_LOOP + int loops=1;//000; + if (argc >3 ) + loops = atoi(argv[4]); + for (int tt=0;tt<loops;++tt) + { +#endif +#ifdef DEBUG + // QT.print(); +#endif + // 1. T1 = QT2T(QT;n) and Ld = QT2Ld(QT;n); +// void BLAS_dgemv(BLCHAR trans, CONST_BLINT m, CONST_BLINT n, CONST_BLDOU alpha, +// CONST_BLDOU a, CONST_BLINT lda, CONST_BLDOU x, CONST_BLINT incx, +// CONST_BLDOU beta, BLDOU y, CONST_BLINT incy); + + BLAS_dgemv("N", &n, &n, &alpha, QT.data, &n, a.data, &inc, &beta, Ta, &inc); + + +#ifdef TIMING_LOOP + } + printf("QT array mvm: finished: %d loops\n",loops); +#endif + // create output and upload output data + WriteMX(argv[2], Ta,n,1); + free(Ta); + } + catch (std::exception e) + { + std::cout <<"Error" << std::endl; + } + + }; //main diff --git a/mex/sources/kalman/qt/test/qtamvm_exe.cpp b/mex/sources/kalman/qt/test/qtamvm_exe.cpp index 7ecc127d7cb4ba6c26334c37478c67fdcf046163..a8b96b0023da1ceb0a94e9e22dad176d564d5122 100644 --- a/mex/sources/kalman/qt/test/qtamvm_exe.cpp +++ b/mex/sources/kalman/qt/test/qtamvm_exe.cpp @@ -77,7 +77,7 @@ int main(int argc, char* argv[]) #ifdef TIMING_LOOP int loops=1;//000; if (argc >3 ) - loops = atoi(argv[2]); + loops = atoi(argv[4]); for (int tt=0;tt<loops;++tt) { #endif diff --git a/mex/sources/kalman/qt/test/qtvmvm_exe.cpp b/mex/sources/kalman/qt/test/qtvmvm_exe.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0bae9af109fc3aafae557f9b5c435a3609272bd4 --- /dev/null +++ b/mex/sources/kalman/qt/test/qtvmvm_exe.cpp @@ -0,0 +1,100 @@ +/* +* Copyright (C) 2008-2009 Dynare Team +* +* This file is part of Dynare. +* +* Dynare 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, either version 3 of the License, or +* (at your option) any later version. +* +* Dynare 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. +* +* You should have received a copy of the GNU General Public License +* along with Dynare. If not, see <http://www.gnu.org/licenses/>. +*/ + +/****************************************************** +% +% This provides an interface to QT f90 library by Andrea Pagano +% to multiply Quasi trinagular matrix (T) with a vector a +% +% function [a] = qtvmvm(QT,a) +% +% use: +% qtvmvm_exe QTt_file a_file size [loops - if enabled] +% +% NOTE: due to fortran matrix orientation, input matrices need to be passed +% as transposed so QTt instead QT +% +% 2. Ta = QTV(T1;a;n). +% +% INPUTS +% T [double] mm*mm transition matrix of the state equation. +% a [double] mm state vector. +% +% OUTPUTS +% a update [double] mm vector of the state equation. +% as file: a_file_out +**********************************************************/ + +#include "qt.h" +#include <stdio.h> +#include <math.h> +#include "ascii_array.h" +#include <iostream> +#include <stdexcept> +#include <malloc.h> + +int main(int argc, char* argv[]) + { + + if (argc < 3 ) + { + printf("Must have min 2 input parameters.\n"); + exit(1); + } + + try + { + // make input matrices + int n=atoi(argv[3]); + double *Ta ; + AsciiNumberArray QT, a; + QT.GetMX(argv[1],n,n); + a.GetMX(argv[2],n,1); + // create output and upload output data + Ta=(double *)calloc(n, sizeof(double)); + + +#ifdef TIMING_LOOP + int loops=1;//000; + if (argc >3 ) + loops = atoi(argv[4]); + for (int tt=0;tt<loops;++tt) + { +#endif +#ifdef DEBUG + // QT.print(); +#endif + // 1. T1 = QT2T(QT;n) and Ld = QT2Ld(QT;n); + qtv_(Ta, QT.data, a.data, &n) ; + + +#ifdef TIMING_LOOP + } + printf("QT array mvm: finished: %d loops\n",loops); +#endif + // create output and upload output data + WriteMX(argv[2], Ta,n,1); + free(Ta); + } + catch (std::exception e) + { + std::cout <<"Error" << std::endl; + } + + }; //main