Neko  0.8.1
A portable framework for high-order spectral element flow simulations
math.f90
Go to the documentation of this file.
1 ! Copyright (c) 2008-2020, UCHICAGO ARGONNE, LLC.
2 !
3 ! The UChicago Argonne, LLC as Operator of Argonne National
4 ! Laboratory holds copyright in the Software. The copyright holder
5 ! reserves all rights except those expressly granted to licensees,
6 ! and U.S. Government license rights.
7 !
8 ! Redistribution and use in source and binary forms, with or without
9 ! modification, are permitted provided that the following conditions
10 ! are met:
11 !
12 ! 1. Redistributions of source code must retain the above copyright
13 ! notice, this list of conditions and the disclaimer below.
14 !
15 ! 2. Redistributions in binary form must reproduce the above copyright
16 ! notice, this list of conditions and the disclaimer (as noted below)
17 ! in the documentation and/or other materials provided with the
18 ! distribution.
19 !
20 ! 3. Neither the name of ANL nor the names of its contributors
21 ! may be used to endorse or promote products derived from this software
22 ! without specific prior written permission.
23 !
24 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 ! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 ! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 ! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
28 ! UCHICAGO ARGONNE, LLC, THE U.S. DEPARTMENT OF
29 ! ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
31 ! TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ! DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ! THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ! (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 !
37 ! Additional BSD Notice
38 ! ---------------------
39 ! 1. This notice is required to be provided under our contract with
40 ! the U.S. Department of Energy (DOE). This work was produced at
41 ! Argonne National Laboratory under Contract
42 ! No. DE-AC02-06CH11357 with the DOE.
43 !
44 ! 2. Neither the United States Government nor UCHICAGO ARGONNE,
45 ! LLC nor any of their employees, makes any warranty,
46 ! express or implied, or assumes any liability or responsibility for the
47 ! accuracy, completeness, or usefulness of any information, apparatus,
48 ! product, or process disclosed, or represents that its use would not
49 ! infringe privately-owned rights.
50 !
51 ! 3. Also, reference herein to any specific commercial products, process,
52 ! or services by trade name, trademark, manufacturer or otherwise does
53 ! not necessarily constitute or imply its endorsement, recommendation,
54 ! or favoring by the United States Government or UCHICAGO ARGONNE LLC.
55 ! The views and opinions of authors expressed
56 ! herein do not necessarily state or reflect those of the United States
57 ! Government or UCHICAGO ARGONNE, LLC, and shall
58 ! not be used for advertising or product endorsement purposes.
59 !
60 module math
61  use num_types, only : rp, dp, sp, qp
62  use comm
63  implicit none
64  private
65 
67  real(kind=rp), public, parameter :: neko_eps = epsilon(1.0_rp)
68 
70  real(kind=rp), public, parameter :: neko_m_ln2 = log(2.0_rp)
71 
73  real(kind=rp), public, parameter :: pi = 4._rp*atan(1._rp)
74 
75  interface abscmp
76  module procedure sabscmp, dabscmp, qabscmp
77  end interface abscmp
78 
79  interface relcmp
80  module procedure srelcmp, drelcmp, qrelcmp
81  end interface relcmp
82 
83  public :: abscmp, rzero, izero, row_zero, rone, copy, cmult, cadd, cfill, &
89 
90 contains
91 
93  pure function sabscmp(x, y)
94  real(kind=sp), intent(in) :: x
95  real(kind=sp), intent(in) :: y
96  logical :: sabscmp
97 
98  sabscmp = abs(x - y) .lt. neko_eps
99 
100  end function sabscmp
101 
103  pure function dabscmp(x, y)
104  real(kind=dp), intent(in) :: x
105  real(kind=dp), intent(in) :: y
106  logical :: dabscmp
107 
108  dabscmp = abs(x - y) .lt. neko_eps
109 
110  end function dabscmp
111 
113  pure function qabscmp(x, y)
114  real(kind=qp), intent(in) :: x
115  real(kind=qp), intent(in) :: y
116  logical :: qabscmp
117 
118  qabscmp = abs(x - y) .lt. neko_eps
119 
120  end function qabscmp
121 
123  pure function srelcmp(x, y, eps)
124  real(kind=sp), intent(in) :: x
125  real(kind=sp), intent(in) :: y
126  real(kind=sp), intent(in), optional :: eps
127  logical :: srelcmp
128  if (present(eps)) then
129  srelcmp = abs(x - y) .le. eps*abs(y)
130  else
131  srelcmp = abs(x - y) .le. neko_eps*abs(y)
132  end if
133 
134  end function srelcmp
135 
137  pure function drelcmp(x, y, eps)
138  real(kind=dp), intent(in) :: x
139  real(kind=dp), intent(in) :: y
140  real(kind=dp), intent(in), optional :: eps
141  logical :: drelcmp
142  if (present(eps)) then
143  drelcmp = abs(x - y) .le. eps*abs(y)
144  else
145  drelcmp = abs(x - y) .le. neko_eps*abs(y)
146  end if
147 
148  end function drelcmp
149 
150 
152  pure function qrelcmp(x, y, eps)
153  real(kind=qp), intent(in) :: x
154  real(kind=qp), intent(in) :: y
155  real(kind=qp), intent(in), optional :: eps
156  logical :: qrelcmp
157  if (present(eps)) then
158  qrelcmp = abs(x - y)/abs(y) .lt. eps
159  else
160  qrelcmp = abs(x - y)/abs(y) .lt. neko_eps
161  end if
162 
163  end function qrelcmp
164 
166  subroutine rzero(a, n)
167  integer, intent(in) :: n
168  real(kind=rp), dimension(n), intent(inout) :: a
169  integer :: i
170 
171  do i = 1, n
172  a(i) = 0.0_rp
173  end do
174  end subroutine rzero
175 
177  subroutine izero(a, n)
178  integer, intent(in) :: n
179  integer, dimension(n), intent(inout) :: a
180  integer :: i
181 
182  do i = 1, n
183  a(i) = 0
184  end do
185  end subroutine izero
186 
188  subroutine row_zero(a, m, n, e)
189  integer, intent(in) :: m, n, e
190  real(kind=rp), intent(inout) :: a(m,n)
191  integer :: j
192 
193  do j = 1,n
194  a(e,j) = 0.0_rp
195  end do
196  end subroutine row_zero
197 
199  subroutine rone(a, n)
200  integer, intent(in) :: n
201  real(kind=rp), dimension(n), intent(inout) :: a
202  integer :: i
203 
204  do i = 1, n
205  a(i) = 1.0_rp
206  end do
207  end subroutine rone
208 
210  subroutine copy(a, b, n)
211  integer, intent(in) :: n
212  real(kind=rp), dimension(n), intent(in) :: b
213  real(kind=rp), dimension(n), intent(inout) :: a
214  integer :: i
215 
216  do i = 1, n
217  a(i) = b(i)
218  end do
219 
220  end subroutine copy
221 
229  subroutine masked_copy(a, b, mask, n, m)
230  integer, intent(in) :: n, m
231  real(kind=rp), dimension(n), intent(in) :: b
232  real(kind=rp), dimension(n), intent(inout) :: a
233  integer, dimension(0:m) :: mask
234  integer :: i, j
235 
236  do i = 1, m
237  j = mask(i)
238  a(j) = b(j)
239  end do
240 
241  end subroutine masked_copy
242 
243 
245  subroutine cmult(a, c, n)
246  integer, intent(in) :: n
247  real(kind=rp), dimension(n), intent(inout) :: a
248  real(kind=rp), intent(in) :: c
249  integer :: i
250 
251  do i = 1, n
252  a(i) = c * a(i)
253  end do
254  end subroutine cmult
255 
257  subroutine cadd(a, s, n)
258  integer, intent(in) :: n
259  real(kind=rp), dimension(n), intent(inout) :: a
260  real(kind=rp), intent(in) :: s
261  integer :: i
262 
263  do i = 1, n
264  a(i) = a(i) + s
265  end do
266  end subroutine cadd
267 
269  subroutine cfill(a, c, n)
270  integer, intent(in) :: n
271  real(kind=rp), dimension(n), intent(inout) :: a
272  real(kind=rp), intent(in) :: c
273  integer :: i
274 
275  do i = 1, n
276  a(i) = c
277  end do
278  end subroutine cfill
279 
281  function glsum(a, n)
282  integer, intent(in) :: n
283  real(kind=rp), dimension(n) :: a
284  real(kind=rp) :: tmp, glsum
285  integer :: i, ierr
286  tmp = 0.0_rp
287  do i = 1, n
288  tmp = tmp + a(i)
289  end do
290  call mpi_allreduce(tmp, glsum, 1, &
291  mpi_real_precision, mpi_sum, neko_comm, ierr)
292 
293  end function glsum
294 
296  function glmax(a, n)
297  integer, intent(in) :: n
298  real(kind=rp), dimension(n) :: a
299  real(kind=rp) :: tmp, glmax
300  integer :: i, ierr
301  tmp = a(1)
302  do i = 2, n
303  tmp = max(tmp,a(i))
304  end do
305  call mpi_allreduce(tmp, glmax, 1, &
306  mpi_real_precision, mpi_max, neko_comm, ierr)
307  end function glmax
308 
310  function glimax(a, n)
311  integer, intent(in) :: n
312  integer, dimension(n) :: a
313  integer :: tmp, glimax
314  integer :: i, ierr
315  tmp = a(1)
316  do i = 2, n
317  tmp = max(tmp,a(i))
318  end do
319  call mpi_allreduce(tmp, glimax, 1, &
320  mpi_integer, mpi_max, neko_comm, ierr)
321  end function glimax
322 
324  function glmin(a, n)
325  integer, intent(in) :: n
326  real(kind=rp), dimension(n) :: a
327  real(kind=rp) :: tmp, glmin
328  integer :: i, ierr
329  tmp = a(1)
330  do i = 2, n
331  tmp = min(tmp,a(i))
332  end do
333  call mpi_allreduce(tmp, glmin, 1, &
334  mpi_real_precision, mpi_min, neko_comm, ierr)
335  end function glmin
336 
338  function glimin(a, n)
339  integer, intent(in) :: n
340  integer, dimension(n) :: a
341  integer :: tmp, glimin
342  integer :: i, ierr
343  tmp = a(1)
344  do i = 2, n
345  tmp = min(tmp,a(i))
346  end do
347  call mpi_allreduce(tmp, glimin, 1, &
348  mpi_integer, mpi_min, neko_comm, ierr)
349  end function glimin
350 
351 
352 
353 
355  subroutine chsign(a, n)
356  integer, intent(in) :: n
357  real(kind=rp), dimension(n), intent(inout) :: a
358  integer :: i
359 
360  do i = 1, n
361  a(i) = -a(i)
362  end do
363 
364  end subroutine chsign
365 
367  function vlmax(vec,n) result(tmax)
368  integer :: n, i
369  real(kind=rp), intent(in) :: vec(n)
370  real(kind=rp) :: tmax
371  tmax = real(-99d20, rp)
372  do i=1,n
373  tmax = max(tmax,vec(i))
374  end do
375  end function vlmax
376 
378  function vlmin(vec,n) result(tmin)
379  integer, intent(in) :: n
380  real(kind=rp), intent(in) :: vec(n)
381  real(kind=rp) :: tmin
382  integer :: i
383  tmin = real(99.0e20, rp)
384  do i=1,n
385  tmin = min(tmin,vec(i))
386  end do
387  end function vlmin
388 
390  subroutine invcol1(a, n)
391  integer, intent(in) :: n
392  real(kind=rp), dimension(n), intent(inout) :: a
393  integer :: i
394 
395  do i = 1, n
396  a(i) = 1.0_rp / a(i)
397  end do
398 
399  end subroutine invcol1
400 
402  subroutine invcol3(a, b, c, n)
403  integer, intent(in) :: n
404  real(kind=rp), dimension(n), intent(inout) :: a
405  real(kind=rp), dimension(n), intent(in) :: b,c
406  integer :: i
407 
408  do i = 1, n
409  a(i) = b(i) / c(i)
410  end do
411 
412  end subroutine invcol3
413 
415  subroutine invers2(a, b, n)
416  integer, intent(in) :: n
417  real(kind=rp), dimension(n), intent(inout) :: a
418  real(kind=rp), dimension(n), intent(in) :: b
419  integer :: i
420 
421  do i = 1, n
422  a(i) = 1.0_rp / b(i)
423  end do
424 
425  end subroutine invers2
426 
429  subroutine vcross(u1, u2, u3, v1, v2, v3, w1, w2, w3, n)
430  integer, intent(in) :: n
431  real(kind=rp), dimension(n), intent(in) :: v1, v2, v3
432  real(kind=rp), dimension(n), intent(in) :: w1, w2, w3
433  real(kind=rp), dimension(n), intent(out) :: u1, u2, u3
434  integer :: i
435 
436  do i = 1, n
437  u1(i) = v2(i)*w3(i) - v3(i)*w2(i)
438  u2(i) = v3(i)*w1(i) - v1(i)*w3(i)
439  u3(i) = v1(i)*w2(i) - v2(i)*w1(i)
440  end do
441 
442  end subroutine vcross
443 
446  subroutine vdot2(dot, u1, u2, v1, v2, n)
447  integer, intent(in) :: n
448  real(kind=rp), dimension(n), intent(in) :: u1, u2
449  real(kind=rp), dimension(n), intent(in) :: v1, v2
450  real(kind=rp), dimension(n), intent(out) :: dot
451  integer :: i
452  do i = 1, n
453  dot(i) = u1(i)*v1(i) + u2(i)*v2(i)
454  end do
455 
456  end subroutine vdot2
457 
460  subroutine vdot3(dot, u1, u2, u3, v1, v2, v3, n)
461  integer, intent(in) :: n
462  real(kind=rp), dimension(n), intent(in) :: u1, u2, u3
463  real(kind=rp), dimension(n), intent(in) :: v1, v2, v3
464  real(kind=rp), dimension(n), intent(out) :: dot
465  integer :: i
466 
467  do i = 1, n
468  dot(i) = u1(i)*v1(i) + u2(i)*v2(i) + u3(i)*v3(i)
469  end do
470 
471  end subroutine vdot3
472 
474  function vlsc3(u, v, w, n) result(s)
475  integer, intent(in) :: n
476  real(kind=rp), dimension(n), intent(in) :: u, v, w
477  real(kind=rp) :: s
478  integer :: i
479 
480  s = 0.0_rp
481  do i = 1, n
482  s = s + u(i)*v(i)*w(i)
483  end do
484 
485  end function vlsc3
486 
488  function vlsc2(u, v, n) result(s)
489  integer, intent(in) :: n
490  real(kind=rp), dimension(n), intent(in) :: u, v
491  real(kind=rp) :: s
492  integer :: i
493 
494  s = 0.0_rp
495  do i = 1, n
496  s = s + u(i)*v(i)
497  end do
498 
499  end function vlsc2
500 
502  subroutine add2(a, b, n)
503  integer, intent(in) :: n
504  real(kind=rp), dimension(n), intent(inout) :: a
505  real(kind=rp), dimension(n), intent(in) :: b
506  integer :: i
507 
508  do i = 1, n
509  a(i) = a(i) + b(i)
510  end do
511 
512  end subroutine add2
513 
515  subroutine add3(a, b, c, n)
516  integer, intent(in) :: n
517  real(kind=rp), dimension(n), intent(inout) :: c
518  real(kind=rp), dimension(n), intent(inout) :: b
519  real(kind=rp), dimension(n), intent(out) :: a
520  integer :: i
521 
522  do i = 1, n
523  a(i) = b(i) + c(i)
524  end do
525 
526  end subroutine add3
527 
529  subroutine add4(a, b, c, d, n)
530  integer, intent(in) :: n
531  real(kind=rp), dimension(n), intent(inout) :: d
532  real(kind=rp), dimension(n), intent(inout) :: c
533  real(kind=rp), dimension(n), intent(inout) :: b
534  real(kind=rp), dimension(n), intent(out) :: a
535  integer :: i
536 
537  do i = 1, n
538  a(i) = b(i) + c(i) + d(i)
539  end do
540 
541  end subroutine add4
542 
544  subroutine sub2(a, b, n)
545  integer, intent(in) :: n
546  real(kind=rp), dimension(n), intent(inout) :: a
547  real(kind=rp), dimension(n), intent(inout) :: b
548  integer :: i
549 
550  do i = 1, n
551  a(i) = a(i) - b(i)
552  end do
553 
554  end subroutine sub2
555 
557  subroutine sub3(a, b, c, n)
558  integer, intent(in) :: n
559  real(kind=rp), dimension(n), intent(inout) :: c
560  real(kind=rp), dimension(n), intent(inout) :: b
561  real(kind=rp), dimension(n), intent(out) :: a
562  integer :: i
563 
564  do i = 1, n
565  a(i) = b(i) - c(i)
566  end do
567 
568  end subroutine sub3
569 
570 
573  subroutine add2s1(a, b, c1, n)
574  integer, intent(in) :: n
575  real(kind=rp), dimension(n), intent(inout) :: a
576  real(kind=rp), dimension(n), intent(inout) :: b
577  real(kind=rp), intent(in) :: c1
578  integer :: i
579 
580  do i = 1, n
581  a(i) = c1 * a(i) + b(i)
582  end do
583 
584  end subroutine add2s1
585 
588  subroutine add2s2(a, b, c1, n)
589  integer, intent(in) :: n
590  real(kind=rp), dimension(n), intent(inout) :: a
591  real(kind=rp), dimension(n), intent(inout) :: b
592  real(kind=rp), intent(in) :: c1
593  integer :: i
594 
595  do i = 1, n
596  a(i) = a(i) + c1 * b(i)
597  end do
598 
599  end subroutine add2s2
600 
602  subroutine addsqr2s2(a, b, c1, n)
603  integer, intent(in) :: n
604  real(kind=rp), dimension(n), intent(inout) :: a
605  real(kind=rp), dimension(n), intent(in) :: b
606  real(kind=rp), intent(in) :: c1
607  integer :: i
608 
609  do i = 1,n
610  a(i) = a(i) + c1 * ( b(i) * b(i) )
611  end do
612 
613  end subroutine addsqr2s2
614 
616  subroutine cmult2(a, b, c, n)
617  integer, intent(in) :: n
618  real(kind=rp), dimension(n), intent(inout) :: a
619  real(kind=rp), dimension(n), intent(in) :: b
620  real(kind=rp), intent(in) :: c
621  integer :: i
622 
623  do i = 1, n
624  a(i) = c * b(i)
625  end do
626 
627  end subroutine cmult2
628 
630  subroutine invcol2(a, b, n)
631  integer, intent(in) :: n
632  real(kind=rp), dimension(n), intent(inout) :: a
633  real(kind=rp), dimension(n), intent(in) :: b
634  integer :: i
635 
636  do i = 1, n
637  a(i) = a(i) /b(i)
638  end do
639 
640  end subroutine invcol2
641 
642 
644  subroutine col2(a, b, n)
645  integer, intent(in) :: n
646  real(kind=rp), dimension(n), intent(inout) :: a
647  real(kind=rp), dimension(n), intent(in) :: b
648  integer :: i
649 
650  do i = 1, n
651  a(i) = a(i) * b(i)
652  end do
653 
654  end subroutine col2
655 
657  subroutine col3(a, b, c, n)
658  integer, intent(in) :: n
659  real(kind=rp), dimension(n), intent(inout) :: a
660  real(kind=rp), dimension(n), intent(in) :: b
661  real(kind=rp), dimension(n), intent(in) :: c
662  integer :: i
663 
664  do i = 1, n
665  a(i) = b(i) * c(i)
666  end do
667 
668  end subroutine col3
669 
671  subroutine subcol3(a, b, c, n)
672  integer, intent(in) :: n
673  real(kind=rp), dimension(n), intent(inout) :: a
674  real(kind=rp), dimension(n), intent(in) :: b
675  real(kind=rp), dimension(n), intent(in) :: c
676  integer :: i
677 
678  do i = 1,n
679  a(i) = a(i) - b(i) * c(i)
680  end do
681 
682  end subroutine subcol3
683 
685  subroutine add3s2(a, b, c, c1, c2 ,n)
686  integer, intent(in) :: n
687  real(kind=rp), dimension(n), intent(inout) :: a
688  real(kind=rp), dimension(n), intent(in) :: b
689  real(kind=rp), dimension(n), intent(in) :: c
690  real(kind=rp), intent(in) :: c1, c2
691  integer :: i
692 
693  do i = 1,n
694  a(i) = c1 * b(i) + c2 * c(i)
695  end do
696 
697  end subroutine add3s2
698 
699 
701  subroutine subcol4(a, b, c, d, n)
702  integer, intent(in) :: n
703  real(kind=rp), dimension(n), intent(inout) :: a
704  real(kind=rp), dimension(n), intent(in) :: b
705  real(kind=rp), dimension(n), intent(in) :: c
706  real(kind=rp), dimension(n), intent(in) :: d
707  integer :: i
708 
709  do i = 1,n
710  a(i) = a(i) - b(i) * c(i) * d(i)
711  end do
712 
713  end subroutine subcol4
714 
716  subroutine addcol3(a, b, c, n)
717  integer, intent(in) :: n
718  real(kind=rp), dimension(n), intent(inout) :: a
719  real(kind=rp), dimension(n), intent(in) :: b
720  real(kind=rp), dimension(n), intent(in) :: c
721  integer :: i
722 
723  do i = 1,n
724  a(i) = a(i) + b(i) * c(i)
725  end do
726 
727  end subroutine addcol3
728 
730  subroutine addcol4(a, b, c, d, n)
731  integer, intent(in) :: n
732  real(kind=rp), dimension(n), intent(inout) :: a
733  real(kind=rp), dimension(n), intent(in) :: b
734  real(kind=rp), dimension(n), intent(in) :: c
735  real(kind=rp), dimension(n), intent(in) :: d
736  integer :: i
737 
738  do i = 1,n
739  a(i) = a(i) + b(i) * c(i) * d(i)
740  end do
741 
742  end subroutine addcol4
743 
745  subroutine ascol5(a, b, c, d, e, n)
746  integer, intent(in) :: n
747  real(kind=rp), dimension(n), intent(inout) :: a
748  real(kind=rp), dimension(n), intent(in) :: b
749  real(kind=rp), dimension(n), intent(in) :: c
750  real(kind=rp), dimension(n), intent(in) :: d
751  real(kind=rp), dimension(n), intent(in) :: e
752  integer :: i
753 
754  do i = 1,n
755  a(i) = b(i)*c(i)-d(i)*e(i)
756  end do
757 
758  end subroutine ascol5
759 
761  subroutine p_update(a, b, c, c1, c2, n)
762  integer, intent(in) :: n
763  real(kind=rp), dimension(n), intent(inout) :: a
764  real(kind=rp), dimension(n), intent(in) :: b
765  real(kind=rp), dimension(n), intent(in) :: c
766  real(kind=rp), intent(in) :: c1, c2
767  integer :: i
768 
769  do i = 1,n
770  a(i) = b(i) + c1*(a(i)-c2*c(i))
771  end do
772 
773  end subroutine p_update
774 
776  subroutine x_update(a, b, c, c1, c2, n)
777  integer, intent(in) :: n
778  real(kind=rp), dimension(n), intent(inout) :: a
779  real(kind=rp), dimension(n), intent(in) :: b
780  real(kind=rp), dimension(n), intent(in) :: c
781  real(kind=rp), intent(in) :: c1, c2
782  integer :: i
783 
784  do i = 1,n
785  a(i) = a(i) + c1*b(i)+c2*c(i)
786  end do
787 
788  end subroutine x_update
789 
791  function glsc2(a, b, n)
792  integer, intent(in) :: n
793  real(kind=rp), dimension(n), intent(in) :: a
794  real(kind=rp), dimension(n), intent(in) :: b
795  real(kind=rp) :: glsc2, tmp
796  integer :: i, ierr
797 
798  tmp = 0.0_rp
799  do i = 1, n
800  tmp = tmp + a(i) * b(i)
801  end do
802 
803  call mpi_allreduce(tmp, glsc2, 1, &
804  mpi_real_precision, mpi_sum, neko_comm, ierr)
805 
806  end function glsc2
807 
809  function glsc3(a, b, c, n)
810  integer, intent(in) :: n
811  real(kind=rp), dimension(n), intent(in) :: a
812  real(kind=rp), dimension(n), intent(in) :: b
813  real(kind=rp), dimension(n), intent(in) :: c
814  real(kind=rp) :: glsc3, tmp
815  integer :: i, ierr
816 
817  tmp = 0.0_rp
818  do i = 1, n
819  tmp = tmp + a(i) * b(i) * c(i)
820  end do
821 
822  call mpi_allreduce(tmp, glsc3, 1, &
823  mpi_real_precision, mpi_sum, neko_comm, ierr)
824 
825  end function glsc3
826  function glsc4(a, b, c, d, n)
827  integer, intent(in) :: n
828  real(kind=rp), dimension(n), intent(in) :: a
829  real(kind=rp), dimension(n), intent(in) :: b
830  real(kind=rp), dimension(n), intent(in) :: c
831  real(kind=rp), dimension(n), intent(in) :: d
832  real(kind=rp) :: glsc4, tmp
833  integer :: i, ierr
834 
835  tmp = 0.0_rp
836  do i = 1, n
837  tmp = tmp + a(i) * b(i) * c(i) * d(i)
838  end do
839 
840  call mpi_allreduce(tmp, glsc4, 1, &
841  mpi_real_precision, mpi_sum, neko_comm, ierr)
842 
843  end function glsc4
845  subroutine sort(a,ind,n)
846  integer, intent(in) :: n
847  real(kind=rp), intent(inout) :: a(n)
848  integer, intent(inout) :: ind(n)
849  real(kind=rp) :: aa
850  integer :: j, ir, i, ii, l
851  do j = 1, n
852  ind(j)=j
853  end do
854 
855  if (n.le.1) return
856 
857  l=n/2+1
858  ir=n
859  do while (.true.)
860  if (l.gt.1) then
861  l=l-1
862  aa = a(l)
863  ii = ind(l)
864  else
865  aa = a(ir)
866  ii = ind(ir)
867  a(ir) = a( 1)
868  ind(ir) = ind( 1)
869  ir=ir-1
870  if (ir.eq.1) then
871  a(1) = aa
872  ind(1) = ii
873  return
874  endif
875  endif
876  i=l
877  j=l+l
878  do while (j .le. ir)
879  if (j.lt.ir) then
880  if ( a(j).lt.a(j+1) ) j=j+1
881  endif
882  if (aa.lt.a(j)) then
883  a(i) = a(j)
884  ind(i) = ind(j)
885  i=j
886  j=j+j
887  else
888  j=ir+1
889  endif
890  end do
891  a(i) = aa
892  ind(i) = ii
893  end do
894  end subroutine sort
895 
896 end module math
double real
Definition: device_config.h:12
Definition: comm.F90:1
type(mpi_comm) neko_comm
MPI communicator.
Definition: comm.F90:16
type(mpi_datatype) mpi_real_precision
MPI type for working precision of REAL types.
Definition: comm.F90:22
Definition: math.f90:60
subroutine, public cmult(a, c, n)
Multiplication by constant c .
Definition: math.f90:246
subroutine, public cmult2(a, b, c, n)
Multiplication by constant c .
Definition: math.f90:617
subroutine, public row_zero(a, m, n, e)
Sets row e to 0 in matrix a.
Definition: math.f90:189
subroutine, public invcol2(a, b, n)
Vector division .
Definition: math.f90:631
real(kind=rp) function, public vlsc2(u, v, n)
Compute multiplication sum .
Definition: math.f90:489
real(kind=rp), parameter, public pi
Definition: math.f90:73
real(kind=rp) function, public glsc3(a, b, c, n)
Weighted inner product .
Definition: math.f90:810
pure logical function qabscmp(x, y)
Return double precision absolute comparison .
Definition: math.f90:114
subroutine, public ascol5(a, b, c, d, e, n)
Returns .
Definition: math.f90:746
subroutine, public invers2(a, b, n)
Compute inverted vector .
Definition: math.f90:416
subroutine, public cadd(a, s, n)
Add a scalar to vector .
Definition: math.f90:258
subroutine, public addsqr2s2(a, b, c1, n)
Returns .
Definition: math.f90:603
real(kind=rp) function, public glsc4(a, b, c, d, n)
Definition: math.f90:827
subroutine, public add2s1(a, b, c1, n)
Vector addition with scalar multiplication (multiplication on first argument)
Definition: math.f90:574
real(kind=rp) function, public glsc2(a, b, n)
Weighted inner product .
Definition: math.f90:792
subroutine, public subcol3(a, b, c, n)
Returns .
Definition: math.f90:672
subroutine, public rone(a, n)
Set all elements to one.
Definition: math.f90:200
subroutine, public x_update(a, b, c, c1, c2, n)
Returns .
Definition: math.f90:777
subroutine, public add3(a, b, c, n)
Vector addition .
Definition: math.f90:516
integer function, public glimin(a, n)
Min of an integer vector of length n.
Definition: math.f90:339
real(kind=rp) function, public glsum(a, n)
Sum a vector of length n.
Definition: math.f90:282
subroutine, public sub3(a, b, c, n)
Vector subtraction .
Definition: math.f90:558
subroutine, public addcol4(a, b, c, d, n)
Returns .
Definition: math.f90:731
subroutine, public add2(a, b, n)
Vector addition .
Definition: math.f90:503
subroutine, public cfill(a, c, n)
Set all elements to a constant c .
Definition: math.f90:270
subroutine, public invcol3(a, b, c, n)
Invert a vector .
Definition: math.f90:403
pure logical function sabscmp(x, y)
Return single precision absolute comparison .
Definition: math.f90:94
subroutine, public add3s2(a, b, c, c1, c2, n)
Returns .
Definition: math.f90:686
subroutine, public subcol4(a, b, c, d, n)
Returns .
Definition: math.f90:702
subroutine, public addcol3(a, b, c, n)
Returns .
Definition: math.f90:717
pure logical function dabscmp(x, y)
Return double precision absolute comparison .
Definition: math.f90:104
subroutine, public invcol1(a, n)
Invert a vector .
Definition: math.f90:391
subroutine, public masked_copy(a, b, mask, n, m)
Copy a masked vector .
Definition: math.f90:230
real(kind=rp), parameter, public neko_m_ln2
Definition: math.f90:70
subroutine, public chsign(a, n)
Change sign of vector .
Definition: math.f90:356
subroutine, public col2(a, b, n)
Vector multiplication .
Definition: math.f90:645
subroutine, public izero(a, n)
Zero an integer vector.
Definition: math.f90:178
real(kind=rp) function, public glmax(a, n)
Max of a vector of length n.
Definition: math.f90:297
subroutine, public sort(a, ind, n)
Use Heap Sort (p 231 Num. Rec., 1st Ed.)
Definition: math.f90:846
subroutine, public copy(a, b, n)
Copy a vector .
Definition: math.f90:211
subroutine, public add4(a, b, c, d, n)
Vector addition .
Definition: math.f90:530
subroutine, public col3(a, b, c, n)
Vector multiplication with 3 vectors .
Definition: math.f90:658
pure logical function drelcmp(x, y, eps)
Return double precision relative comparison .
Definition: math.f90:138
real(kind=rp), parameter, public neko_eps
Machine epsilon .
Definition: math.f90:67
subroutine, public vdot3(dot, u1, u2, u3, v1, v2, v3, n)
Compute a dot product (3-d version) assuming vector components etc.
Definition: math.f90:461
pure logical function qrelcmp(x, y, eps)
Return quad precision relative comparison .
Definition: math.f90:153
subroutine, public rzero(a, n)
Zero a real vector.
Definition: math.f90:167
subroutine, public vdot2(dot, u1, u2, v1, v2, n)
Compute a dot product (2-d version) assuming vector components etc.
Definition: math.f90:447
real(kind=rp) function, public vlmin(vec, n)
minimun value of a vector of length n
Definition: math.f90:379
real(kind=rp) function, public vlmax(vec, n)
maximum value of a vector of length n
Definition: math.f90:368
integer function, public glimax(a, n)
Max of an integer vector of length n.
Definition: math.f90:311
subroutine, public sub2(a, b, n)
Vector substraction .
Definition: math.f90:545
subroutine, public add2s2(a, b, c1, n)
Vector addition with scalar multiplication (multiplication on second argument)
Definition: math.f90:589
real(kind=rp) function, public glmin(a, n)
Min of a vector of length n.
Definition: math.f90:325
subroutine, public vcross(u1, u2, u3, v1, v2, v3, w1, w2, w3, n)
Compute a cross product assuming vector components etc.
Definition: math.f90:430
pure logical function srelcmp(x, y, eps)
Return single precision relative comparison .
Definition: math.f90:124
real(kind=rp) function, public vlsc3(u, v, w, n)
Compute multiplication sum .
Definition: math.f90:475
subroutine, public p_update(a, b, c, c1, c2, n)
Returns .
Definition: math.f90:762
integer, parameter, public qp
Definition: num_types.f90:10
integer, parameter, public dp
Definition: num_types.f90:9
integer, parameter, public sp
Definition: num_types.f90:8
integer, parameter, public rp
Global precision used in computations.
Definition: num_types.f90:12
#define max(a, b)
Definition: tensor.cu:40