Line data Source code
1 : !/*************************************************************************
2 : ! *
3 : ! * Project
4 : ! * _____ _____ __ __ _____
5 : ! * / ____| __ \| \/ | __ \
6 : ! * ___ _ __ ___ _ __ | | __| |__) | \ / | |__) |
7 : ! * / _ \| '_ \ / _ \ '_ \| | |_ | ___/| |\/| | ___/
8 : ! *| (_) | |_) | __/ | | | |__| | | | | | | |
9 : ! * \___/| .__/ \___|_| |_|\_____|_| |_| |_|_|
10 : ! * | |
11 : ! * |_|
12 : ! *
13 : ! * Copyright (C) Akiel Aries, <akiel@akiel.org>, et al.
14 : ! *
15 : ! * This software is licensed as described in the file LICENSE, which
16 : ! * you should have received as part of this distribution. The terms
17 : ! * among other details are referenced in the official documentation
18 : ! * seen here : https://akielaries.github.io/openGPMP/ along with
19 : ! * important files seen in this project.
20 : ! *
21 : ! * You may opt to use, copy, modify, merge, publish, distribute
22 : ! * and/or sell copies of the Software, and permit persons to whom
23 : ! * the Software is furnished to do so, under the terms of the
24 : ! * LICENSE file. As this is an Open Source effort, all implementations
25 : ! * must be of the same methodology.
26 : ! *
27 : ! *
28 : ! *
29 : ! * This software is distributed on an AS IS basis, WITHOUT
30 : ! * WARRANTY OF ANY KIND, either express or implied.
31 : ! *
32 : ! ************************************************************************/
33 : ! mtx_routines.f90
34 :
35 : !> FORTRAN Subroutine for Matrix Addition on flattened matrices as arrays
36 : !! of type float32. Contains C++ wrapper function
37 : !! @param A Addend A, an array representing a Matrix
38 : !! @param B Addend B, an array representing a Matrix
39 : !! @param C Sum C, an array representing the sum of A + B
40 : !! @param mtx_size Assumes same size M x N
41 1 : SUBROUTINE mtx_add_routine_float_(A, B, C, mtx_size) bind(C)
42 : USE :: ISO_FORTRAN_ENV
43 : USE :: ISO_C_BINDING
44 :
45 : INTEGER, INTENT(IN) :: mtx_size
46 : REAL(KIND=C_FLOAT), DIMENSION(mtx_size, mtx_size), INTENT(IN) :: A, B
47 : REAL(KIND=C_FLOAT), DIMENSION(mtx_size, mtx_size), INTENT(OUT) :: C
48 :
49 13 : C = A + B
50 1 : END SUBROUTINE mtx_add_routine_float_
51 :
52 : !> FORTRAN Subroutine for Matrix Addition on flattened matrices as arrays
53 : !! of type int32. Contains C++ wrapper function
54 : !! @param A Addend A, an array representing a Matrix
55 : !! @param B Addend B, an array representing a Matrix
56 : !! @param C Sum C, an array representing the sum of A + B
57 : !! @param mtx_size Assumes same size M x N
58 2 : SUBROUTINE mtx_add_routine_int_(A, B, C, mtx_size) bind(C)
59 : USE :: ISO_FORTRAN_ENV
60 : USE :: ISO_C_BINDING
61 :
62 : INTEGER, INTENT(IN) :: mtx_size
63 : INTEGER(C_INT), DIMENSION(mtx_size, mtx_size), INTENT(IN) :: A, B
64 : INTEGER(C_INT), DIMENSION(mtx_size, mtx_size), INTENT(OUT) :: C
65 :
66 1049614 : C = A + B
67 2 : END SUBROUTINE mtx_add_routine_int_
68 :
69 : !> FORTRAN Subroutine for Matrix Multiplication using Fortran intrinsics.
70 : !! Contains C++ wrapper function
71 : !! @param A Multiplier A, an array representing a Matrix
72 : !! @param B Multiplicand B, an array representing a Matrix
73 : !! @param C Product C, an array representing the produce Matrix
74 : !! @param rows_a Number of rows Matrix A
75 : !! @param cols_a Number of columns Matrix A
76 : !! @param cols_b Number of columns Matrix B
77 2 : SUBROUTINE mtx_mult_routine_int_(A, B, C, rows_a, cols_a, cols_b) bind(C)
78 : USE :: ISO_FORTRAN_ENV
79 : USE :: ISO_C_BINDING
80 : IMPLICIT NONE
81 :
82 : INTEGER(KIND=C_INT), INTENT(IN) :: rows_a, cols_a, cols_b
83 : INTEGER(KIND=C_INT), DIMENSION(rows_a, cols_a), INTENT(IN) :: A
84 : INTEGER(KIND=C_INT), DIMENSION(cols_a, cols_b), INTENT(IN) :: B
85 : INTEGER(KIND=C_INT), DIMENSION(rows_a, cols_b), INTENT(OUT) :: C
86 :
87 : INTEGER :: i, j, k
88 :
89 : ! Perform matrix multiplication flipping indexing to keep standard with
90 : ! C/C++ calls
91 1030 : DO i = 1, rows_a
92 1049622 : DO j = 1, cols_b
93 :
94 1048592 : C(j, i) = 0
95 1074791508 : DO k = 1, cols_a
96 :
97 1074790480 : C(j, i) = C(j, i) + A(k, i)*B(j, k)
98 :
99 : END DO
100 :
101 : END DO
102 : END DO
103 :
104 2 : END SUBROUTINE mtx_mult_routine_int_
105 :
|