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 debug_oct_m
24 use global_oct_m
26 use io_oct_m, only: io_open, io_close
29
30 implicit none
31 private
33
34contains
35
87 subroutine column_wise_khatri_rao_product(y, x, z)
88 real(real64), intent(in ), contiguous :: y(:, :)
89 real(real64), intent(in ), contiguous :: x(:, :)
90 real(real64), intent(out), contiguous :: z(:, :)
91
92 real(real64), parameter :: alpha = 1.0_real64
93 integer :: nrows_x, nrows_y, ncols, k, ij
94
95 nrows_x = size(x, 1)
96 nrows_y = size(y, 1)
97 ncols = size(x, 2)
98
99 ! x and y arrays should have the same number of columns
100 assert(size(y, 2) == ncols)
101 ! The number of rows of z should equal the size(x, 1) * size(y, 1)
102 assert(size(z, 1) == nrows_x * nrows_y)
103 ! z should have the same number of columns as both x and y arrays
104 assert(size(z, 2) == ncols)
105
106 ! dger performs A := alpha*x*y**T + A, requiring A to be zeroed
107 !$omp parallel do collapse(2) default(shared)
108 do k = 1, ncols
109 do ij = 1, nrows_x * nrows_y
110 z(ij, k) = 0.0_real64
111 enddo
112 enddo
113 !$omp end parallel do
114
115 do k = 1, ncols
116 ! Abuse the fact that I can pass a 1D array, z(:, k), of size (nrows_x * nrows_y) to
117 ! lapack''s interface as long as it is contiguous in memory
118 call dger(nrows_x, nrows_y, alpha, x(:, k), 1, y(:, k), 1, z(:, k), nrows_y)
119 enddo
120
121 end subroutine column_wise_khatri_rao_product
122
123end module face_splitting_oct_m
124
125!! Local Variables:
126!! mode: f90
127!! coding: utf-8
128!! End:
subroutine, public column_wise_khatri_rao_product(y, x, z)
Column-wise Kronecker product.
Definition: io.F90:114
subroutine, public io_close(iunit, grp)
Definition: io.F90:418
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:352