Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions lib/node_modules/@stdlib/blas/base/caxpy/benchmark/fortran/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#/
# @license Apache-2.0
#
# Copyright (c) 2026 The Stdlib Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#/

# VARIABLES #

ifndef VERBOSE
QUIET := @
else
QUIET :=
endif

# Determine the OS ([1][1], [2][2]).
#
# [1]: https://en.wikipedia.org/wiki/Uname#Examples
# [2]: http://stackoverflow.com/a/27776822/2225624
OS ?= $(shell uname)
ifneq (, $(findstring MINGW,$(OS)))
OS := WINNT
else
ifneq (, $(findstring MSYS,$(OS)))
OS := WINNT
else
ifneq (, $(findstring CYGWIN,$(OS)))
OS := WINNT
else
ifneq (, $(findstring Windows_NT,$(OS)))
OS := WINNT
endif
endif
endif
endif

# Define the program used for compiling Fortran source files:
ifdef FORTRAN_COMPILER
FC := $(FORTRAN_COMPILER)
else
FC := gfortran
endif

# Define the command-line options when compiling Fortran files:
FFLAGS ?= \
-std=f95 \
-ffree-form \
-O3 \
-Wall \
-Wextra \
-Wno-compare-reals \
-Wimplicit-interface \
-fno-underscoring \
-pedantic

# Determine whether to generate position independent code ([1][1], [2][2]).
#
# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option
ifeq ($(OS), WINNT)
fPIC ?=
else
fPIC ?= -fPIC
endif

# List of includes (e.g., `-I /foo/bar -I /beep/boop`):
INCLUDE ?=

# List of Fortran source files:
SOURCE_FILES ?= ../../src/caxpy.f

# List of Fortran targets:
f_targets := benchmark.length.out


# RULES #

#/
# Compiles Fortran source files.
#
# @param {string} SOURCE_FILES - list of Fortran source files
# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`)
# @param {string} [FORTRAN_COMPILER] - Fortran compiler
# @param {string} [FFLAGS] - Fortran compiler flags
# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code
#
# @example
# make
#
# @example
# make all
#/
all: $(f_targets)

.PHONY: all

#/
# Compiles Fortran source files.
#
# @private
# @param {string} SOURCE_FILES - list of Fortran source files
# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`)
# @param {string} FC - Fortran compiler
# @param {string} FFLAGS - Fortran compiler flags
# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code
#/
$(f_targets): %.out: %.f
$(QUIET) $(FC) $(FFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $<

#/
# Runs compiled benchmarks.
#
# @example
# make run
#/
run: $(f_targets)
$(QUIET) ./$<

.PHONY: run

#/
# Removes generated files.
#
# @example
# make clean
#/
clean:
$(QUIET) -rm -f *.o *.out

.PHONY: clean
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
!>
! @license Apache-2.0
!
! Copyright (c) 2026 The Stdlib Authors.
!
! Licensed under the Apache License, Version 2.0 (the "License");
! you may not use this file except in compliance with the License.
! You may obtain a copy of the License at
!
! http://www.apache.org/licenses/LICENSE-2.0
!
! Unless required by applicable law or agreed to in writing, software
! distributed under the License is distributed on an "AS IS" BASIS,
! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
! See the License for the specific language governing permissions and
! limitations under the License.
!<

program bench
implicit none
! ..
! Local constants:
character(5), parameter :: name = 'caxpy'
integer, parameter :: iterations = 10000000
integer, parameter :: repeats = 3
integer, parameter :: min = 1
integer, parameter :: max = 6
! ..
call main()
contains

subroutine print_version()
print '(A)', 'TAP version 13'
end subroutine print_version

subroutine print_summary( total, passing )
integer, intent(in) :: total, passing
character(len=999) :: str, tmp
intrinsic adjustl, trim

print '(A)', '#'
write (str, '(I15)') total
tmp = adjustl( str )
print '(A,A)', '1..', trim( tmp )
print '(A,A)', '# total ', trim( tmp )
write (str, '(I15)') passing
tmp = adjustl( str )
print '(A,A)', '# pass ', trim( tmp )
print '(A)', '#'
print '(A)', '# ok'
end subroutine print_summary

subroutine print_results( iterations, elapsed )
integer, intent(in) :: iterations
double precision, intent(in) :: elapsed
double precision :: rate
character(len=999) :: str, tmp
intrinsic dble, adjustl, trim

rate = dble( iterations ) / elapsed
print '(A)', ' ---'
write (str, '(I15)') iterations
tmp = adjustl( str )
print '(A,A)', ' iterations: ', trim( tmp )
write (str, '(f100.9)') elapsed
tmp = adjustl( str )
print '(A,A)', ' elapsed: ', trim( tmp )
write (str, '(f100.9)') rate
tmp = adjustl( str )
print '(A,A)', ' rate: ', trim( tmp )
print '(A)', ' ...'
end subroutine print_results

double precision function benchmark( iterations, len )
interface
subroutine caxpy( N, alpha, x, strideX, y, strideY )
integer :: N, strideX, strideY
complex :: alpha
complex :: x(*), y(*)
end subroutine caxpy
end interface

integer, intent(in) :: iterations, len
double precision :: elapsed
real :: t1, t2
double precision :: r1, r2
integer :: i
complex :: alpha
complex, allocatable :: x(:), y(:)
intrinsic random_number, cpu_time, cmplx

allocate( x(len), y(len) )

! Initialize alpha
call random_number( r1 )
call random_number( r2 )
alpha = cmplx( real(r1)*10.0, real(r2)*10.0 )

! Initialize vectors
do i = 1, len
call random_number( r1 )
call random_number( r2 )
x( i ) = cmplx( real(r1)*1000.0, real(r2)*1000.0 )

call random_number( r1 )
call random_number( r2 )
y( i ) = cmplx( real(r1)*1000.0, real(r2)*1000.0 )
end do

call cpu_time( t1 )

do i = 1, iterations
call caxpy( len, alpha, x, 1, y, 1 )
if ( y(1) /= y(1) ) then
print '(A)', 'should not return NaN'
exit
end if
end do

call cpu_time( t2 )
elapsed = t2 - t1

deallocate( x, y )
benchmark = elapsed
end function benchmark

subroutine main()
integer :: count, iter, len, i, j
double precision :: elapsed
character(len=999) :: str, tmp
intrinsic adjustl, trim

call print_version()
count = 0

do i = min, max
len = 10**i
iter = iterations / 10**(i-1)
do j = 1, repeats
count = count + 1
write (str, '(I15)') len
tmp = adjustl( str )
print '(A,A,A,A)', '# fortran::', name, ':len=', trim( tmp )
elapsed = benchmark( iter, len )
call print_results( iter, elapsed )
write (str, '(I15)') count
tmp = adjustl( str )
print '(A,A,A)', 'ok ', trim( tmp ), ' benchmark finished'
end do
end do

call print_summary( count, count )
end subroutine main

end program bench
2 changes: 1 addition & 1 deletion lib/node_modules/@stdlib/blas/base/caxpy/binding.gyp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @license Apache-2.0
#
# Copyright (c) 2024 The Stdlib Authors.
# Copyright (c) 2026 The Stdlib Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/node_modules/@stdlib/blas/base/caxpy/include.gypi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @license Apache-2.0
#
# Copyright (c) 2024 The Stdlib Authors.
# Copyright (c) 2026 The Stdlib Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Header file containing function declarations for the Fortran interface to the BLAS Level 1 routine `caxpy`.
*/
#ifndef STDLIB_BLAS_BASE_CAXPY_FORTRAN_H
#define STDLIB_BLAS_BASE_CAXPY_FORTRAN_H

#include "stdlib/complex/float32/ctor.h"

/*
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C/Fortran compiler (a Fortran compiler must be configured to not attach underscores).
*/
#ifdef __cplusplus
extern "C" {
#endif

/**
* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant and adds the result to a single-precision complex floating-point vector.
*/
void caxpy( const CBLAS_INT *, const stdlib_complex64_t *, const void *, const CBLAS_INT *, void *, const CBLAS_INT * );

#ifdef __cplusplus
}
#endif

#endif // !STDLIB_BLAS_BASE_CCOPY_FORTRAN_H
Loading