[JSR] [JEP] Java Specification Requirement / Java Enhancement Proposal : 'Parallel OR' and 'Parallel AND'

Bernd Eckenfels ecki at zusammenkunft.net
Wed Jul 24 19:06:11 UTC 2019


Hello,

I don’t think you will get a new infix operator for this. And adding it to existing operators will be acquire risky change, might not improve performance for most situations - and most of all it is quite unlikely that you have a large number of terms at static compile time anyway.

However if you want to evaluate expressions in parallel on a dynamic and large collection, you can easily use a parallel stream. Using predicates as the expression terms to evaluate you can use for example findAny() for checking a or condition.

Gruss
Bernd


--
http://bernd.eckenfels.net

________________________________
Von: core-libs-dev <core-libs-dev-bounces at openjdk.java.net> im Auftrag von Prakhar Makhija <matcdac at gmail.com>
Gesendet: Mittwoch, Juli 24, 2019 4:49 PM
An: David Holmes; core-libs-dev at openjdk.java.net
Betreff: [JSR] [JEP] Java Specification Requirement / Java Enhancement Proposal : 'Parallel OR' and 'Parallel AND'

Hi David / All,


Earlier wanted to discuss just the implementation of 'OR operator', neither
'Conditional OR operator', nor 'Bitwise OR operator'

Same goes with 'AND operator'

Technically OR operator and AND operator are just binary operators, that's
true

I don't find it wrong considering there can be n operands, in an
expression, with either of the two operators or a combination of both,
where n >= 2

n can go nearby anything in powers of 10, it will take those many
sequential clock cycles, to actually resolve the expression

If you consider the same n as an expression of powers of 2, the same thing
can be done in parallel clubbed with divide and conquer, taking the same
number of clock cycles, but saving actual response time

This can be given as a input from console, or as a property, specifying
which implementation to use at runtime, sequential or parallel

But with the latter would lead to very frequent resource starvage, this
would need to be handled, to actually free the resources and give to pid or
ppid, heirarically, or based upon who is the callee, or who asked who to
wait, or some more other logic

All the threads parallelly evaluating the same expression, with either
operand, should be terminated and concluded as, when any thread results to:
'true' in case of OR
'false' in case of AND

An expression can have further sub-expressions; so an expression with
combination of both operands, will be considered as parent expression

Yes it does change the conventional implementation of OR operator, and AND
operator, in Java

So it would be better to have two new operators/symbols itself

Parallel OR
|||

Parallel AND
&&&

We can go with the symbol |&& also in case of Parallel AND


Looking forward to hearing your thoughts


Best Wishes & Regards
Prakhar Makhija

----

Hi Prakhar,


On 22/06/2019 1:28 am, Prakhar Makhija wrote:
> Topic: OR operator represented by ||

That should be the subject of your email - not a reply to a digest.


> Query: The expression evaluation of the operands, of OR operator, does it
> happen in parallel, when Java code runs, in the current versions?

No, there is no parallel evaluation of anything in Java. It would be
wrong to do so in this case as:

"The conditional-or operator || operator is like | (§15.22.2), but
evaluates its righthand operand only if the value of its left-hand
operand is false."


David


More information about the core-libs-dev mailing list