GRASS Programmer's Manual  6.5.svn(2012)-r51648
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
blas_level_3.c
Go to the documentation of this file.
00001 
00002 /*****************************************************************************
00003 *
00004 * MODULE:       Grass PDE Numerical Library
00005 * AUTHOR(S):    Soeren Gebbert, Berlin (GER) Dec 2007
00006 *               soerengebbert <at> gmx <dot> de
00007 *               
00008 * PURPOSE:      linear equation system solvers
00009 *               part of the gpde library
00010 *               
00011 * COPYRIGHT:    (C) 2007 by the GRASS Development Team
00012 *
00013 *               This program is free software under the GNU General Public
00014 *               License (>=v2). Read the file COPYING that comes with GRASS
00015 *               for details.
00016 *
00017 *****************************************************************************/
00018 
00019 #include <math.h>
00020 #include <unistd.h>
00021 #include <stdio.h>
00022 #include <string.h>
00023 #include <stdlib.h>
00024 #include "grass/gmath.h"
00025 #include <grass/gis.h>
00026 
00027 
00050 void G_math_d_aA_B(double **A, double **B, double a, double **C, int rows,
00051                    int cols)
00052 {
00053     int i, j;
00054 
00055 
00056     /*If B is null, scale the matrix A with th scalar a */
00057     if (B == NULL) {
00058 #pragma omp for schedule (static) private(i, j)
00059         for (i = rows - 1; i >= 0; i--)
00060             for (j = cols - 1; j >= 0; j--)
00061                 C[i][j] = a * A[i][j];
00062 
00063         return;
00064     }
00065 
00066     /*select special cases */
00067     if (a == 1.0) {
00068 #pragma omp for schedule (static) private(i, j)
00069         for (i = rows - 1; i >= 0; i--)
00070             for (j = cols - 1; j >= 0; j--)
00071                 C[i][j] = A[i][j] + B[i][j];
00072     }
00073     else if (a == -1.0) {
00074 #pragma omp for schedule (static) private(i, j)
00075         for (i = rows - 1; i >= 0; i--)
00076             for (j = cols - 1; j >= 0; j--)
00077                 C[i][j] = B[i][j] - A[i][j];
00078     }
00079     else {
00080 #pragma omp for schedule (static) private(i, j)
00081         for (i = rows - 1; i >= 0; i--)
00082             for (j = cols - 1; j >= 0; j--)
00083                 C[i][j] = a * A[i][j] + B[i][j];
00084     }
00085 
00086     return;
00087 }
00088 
00113 void G_math_f_aA_B(float **A, float **B, float a, float **C, int rows,
00114                    int cols)
00115 {
00116     int i, j;
00117 
00118     /*If B is null, scale the matrix A with th scalar a */
00119     if (B == NULL) {
00120 #pragma omp for schedule (static) private(i, j)
00121         for (i = rows - 1; i >= 0; i--)
00122             for (j = cols - 1; j >= 0; j--)
00123                 C[i][j] = a * A[i][j];
00124         return;
00125     }
00126 
00127     /*select special cases */
00128     if (a == 1.0) {
00129 #pragma omp for schedule (static) private(i, j)
00130         for (i = rows - 1; i >= 0; i--)
00131             for (j = cols - 1; j >= 0; j--)
00132                 C[i][j] = A[i][j] + B[i][j];
00133     }
00134     else if (a == -1.0) {
00135 #pragma omp for schedule (static) private(i, j)
00136         for (i = rows - 1; i >= 0; i--)
00137             for (j = cols - 1; j >= 0; j--)
00138                 C[i][j] = B[i][j] - A[i][j];
00139     }
00140     else {
00141 #pragma omp for schedule (static) private(i, j)
00142         for (i = rows - 1; i >= 0; i--)
00143             for (j = cols - 1; j >= 0; j--)
00144                 C[i][j] = a * A[i][j] + B[i][j];
00145     }
00146 
00147     return;
00148 }
00149 
00150 
00174 void G_math_d_AB(double **A, double **B, double **C, int rows_A,
00175                  int cols_A, int rows_B)
00176 {
00177     int i, j, k;
00178 
00179 #pragma omp for schedule (static) private(i, j, k)
00180     for (i = 0; i < rows_A; i++) {
00181         for (j = 0; j < rows_B; j++) {
00182             C[i][j] = 0.0;
00183             for (k = cols_A - 1; k >= 0; k--) {
00184                 C[i][j] += A[i][k] * B[k][j];
00185             }
00186         }
00187     }
00188 
00189     return;
00190 }
00191 
00215 void G_math_f_AB(float **A, float **B, float **C, int rows_A,
00216                  int cols_A, int rows_B)
00217 {
00218     int i, j, k;
00219 
00220 #pragma omp for schedule (static) private(i, j, k)
00221     for (i = 0; i < rows_A; i++) {
00222         for (j = 0; j < rows_B; j++) {
00223             C[i][j] = 0.0;
00224             for (k = cols_A - 1; k >= 0; k--) {
00225                 C[i][j] += A[i][k] * B[k][j];
00226             }
00227         }
00228     }
00229 
00230     return;
00231 }