Octopus
face_splitting.F90
Go to the documentation of this file.
1!! Copyright (C) 2024 A. Buccheri
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17
18#include "global.h"
19
21 use, intrinsic :: iso_fortran_env
22
23 use global_oct_m
27
28 implicit none
29 private
31
32contains
33
85 subroutine column_wise_khatri_rao_product(y, x, z)
86 real(real64), intent(in ), contiguous :: y(:, :)
87 real(real64), intent(in ), contiguous :: x(:, :)
88 real(real64), intent(out), contiguous :: z(:, :)
89
90 real(real64), parameter :: alpha = 1.0_real64
91 integer :: nrows_x, nrows_y, ncols, k, ij
92
93 nrows_x = size(x, 1)
94 nrows_y = size(y, 1)
95 ncols = size(x, 2)
96
97 ! x and y arrays should have the same number of columns
98 assert(size(y, 2) == ncols)
99 ! The number of rows of z should equal the size(x, 1) * size(y, 1)
100 assert(size(z, 1) == nrows_x * nrows_y)
101 ! z should have the same number of columns as both x and y arrays
102 assert(size(z, 2) == ncols)
103
104 ! dger performs A := alpha*x*y**T + A, requiring A to be zeroed
105 !$omp parallel do collapse(2) default(shared)
106 do k = 1, ncols
107 do ij = 1, nrows_x * nrows_y
108 z(ij, k) = 0.0_real64
109 enddo
110 enddo
111 !$omp end parallel do
112
113 do k = 1, ncols
114 ! Abuse the fact that I can pass a 1D array, z(:, k), of size (nrows_x * nrows_y) to
115 ! lapack''s interface as long as it is contiguous in memory
116 call dger(nrows_x, nrows_y, alpha, x(:, k), 1, y(:, k), 1, z(:, k), nrows_y)
117 enddo
118
119 end subroutine column_wise_khatri_rao_product
120
121end module face_splitting_oct_m
122
123!! Local Variables:
124!! mode: f90
125!! coding: utf-8
126!! End:
subroutine, public column_wise_khatri_rao_product(y, x, z)
Column-wise Kronecker product.