Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28988 Discussions

performance of logical flags with bit functions or logical variables

clabra
New Contributor I
265 Views
Hi,
I need use flag variables for intensive use in user defined types, but I'm not sure about the faster way for this. I'm considering two possibilities. The first one is use directly logical variables, as follow:

type node_t
....
logical(1), dimension(4) :: flag
...
end type
integer, parameter :: ACTIVE = 1

and the use is:

subroutine foo( node, ... )
type(node_t), intent(in) :: node
....
if( node%flag(ACTIVE) ) then
... do something ...
end if
....
end subroutine foo

The second possibility is use bit intrinsic function, with integer variables:

type node_t
....
integer(1) :: flag
...
end type
integer(1), parameter :: ACTIVE

with:

subroutine foo( node, ... )
type(node_t), intent(in) :: node
....
if( btest(node%flag,ACTIVE) ) then
... do something ...
end if
....
end subroutine foo


Someone can say something about the better way for this,
in order to obtain a good performance, I will really appreciated.

thanks
0 Kudos
1 Reply
TimP
Honored Contributor III
265 Views
You would really have to test performance yourself. If you do a significant amount of other processing, and the code isn't vectorizable, it seems unlikely you could measure a performance difference between your proposals. For potentially vectorizable code, you might have to evaluate default logical data types, if you are willing to use more data space to gain speed.
0 Kudos
Reply