|
liblapackwrap 0.1
|
00001 /* 00002 * Wrapper for a variety of LAPACK routines, to provide a unified interface. 00003 00004 Copyright (C) 2010 Joseph Pingenot 00005 00006 This program is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU Lesser General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 00019 */ 00020 00021 #include <stdio.h> 00022 #include <stdlib.h> 00023 #include <string.h> 00024 #include "liblapackwrap/blaswrap_complex_double.h" 00025 #include "liblapackwrap/blaswrap_functions_complex_double.c" 00026 00027 /**frontend for llw_complex_double_gemm but if you don't have a matrix C yet (clearly, if you're calling this routine, you want one. 00028 */ 00029 int llw_complex_double_gemm_a(char transa, char transb, int M, int N, int K, LLW_complex_double_COMPLEX *alpha, LLW_CONST LLW_complex_double_COMPLEX *A, int LDA, LLW_CONST LLW_complex_double_COMPLEX *B, int LDB, LLW_complex_double_COMPLEX **C) { 00030 *C = (LLW_complex_double_COMPLEX*)malloc(M*N*sizeof(LLW_complex_double_COMPLEX)); 00031 if((*C) == NULL) return 100; 00032 //fprintf(stderr, "N=%d M=%d N*M=%lu\n", M, N, (long unsigned)M*N); 00033 for(long unsigned i=0; i<M*N; i++) { 00034 //fprintf(stderr, "\tC=%p *C=%p (*C)[%lu]=%g\n", (void*)C, (void*)*C, i, (*C)[i]); 00035 llw_bw_complex_double_set_from_double(&((*C)[i]), 0); 00036 //fprintf(stderr, "\t\t->(*C)[%lu]=%g\n", i, (*C)[i]); 00037 } 00038 LLW_complex_double_COMPLEX zero; 00039 llw_bw_complex_double_set_from_double(&zero, 0.0); 00040 return llw_complex_double_gemm(transa, transb, M, N, K, alpha, A, LDA, B, LDB, &zero, *C, M); 00041 } 00042 00043 int llw_complex_double_gemm(char transa, char transb, int M, int N, int K, LLW_complex_double_COMPLEX *alpha, LLW_CONST LLW_complex_double_COMPLEX *A, int LDA, LLW_CONST LLW_complex_double_COMPLEX *B, int LDB, LLW_complex_double_COMPLEX *beta, LLW_complex_double_COMPLEX *C, int LDC) { 00044 int ka=(transa=='N')?K:M; 00045 int kb=(transb=='N')?K:N; 00046 LLW_complex_double_COMPLEX *a; 00047 LLW_complex_double_COMPLEX *b; 00048 #ifdef LLW_CONST 00049 a = (LLW_complex_double_COMPLEX*)malloc(LDA*ka*sizeof(LLW_complex_double_COMPLEX)); 00050 if(a == NULL) return 100; 00051 b = (LLW_complex_double_COMPLEX*)malloc(LDA*kb*sizeof(LLW_complex_double_COMPLEX)); 00052 if(b == NULL) { 00053 free(a); 00054 return 100; 00055 } 00056 memcpy(a, A, LDA*ka*sizeof(LLW_complex_double_COMPLEX)); 00057 memcpy(b, B, LDB*kb*sizeof(LLW_complex_double_COMPLEX)); 00058 #else 00059 a = A; 00060 b = B; 00061 #endif 00062 #ifdef FCALL 00063 GEMM(&transa, &transb, &M, &N, &K, 00064 #ifdef LLW_complex_double_IS_COMPLEX 00065 (LAPACK_COMPLEX_TYPENAME*)alpha, 00066 #else 00067 (LAPACK_COMPLEX_TYPENAME*)&alpha, 00068 #endif 00069 (LAPACK_COMPLEX_TYPENAME*)a, &LDA, (LAPACK_COMPLEX_TYPENAME*)b, &LDB, 00070 #ifdef LLW_complex_double_IS_COMPLEX 00071 (LAPACK_COMPLEX_TYPENAME*)beta, 00072 #else 00073 (LAPACK_COMPLEX_TYPENAME*)&beta, 00074 #endif 00075 (LAPACK_COMPLEX_TYPENAME*)C, &LDC); 00076 #else 00077 GEMM(transa, transb, M, N, K, 00078 #ifdef LLW_complex_double_IS_COMPLEX 00079 (LAPACK_COMPLEX_TYPENAME*)alpha, 00080 #else 00081 *alpha, 00082 #endif 00083 (LAPACK_COMPLEX_TYPENAME*)a, LDA, (LAPACK_COMPLEX_TYPENAME*)b, LDB, 00084 #ifdef LLW_complex_double_IS_COMPLEX 00085 (LAPACK_COMPLEX_TYPENAME*)beta, 00086 #else 00087 *beta, 00088 #endif 00089 (LAPACK_COMPLEX_TYPENAME*)C, LDC); 00090 #endif 00091 #ifdef LLW_CONST 00092 free(a); 00093 free(b); 00094 #endif 00095 return 0; 00096 }