meaning of enclosed parallel region - parallel-processing

These days I'm learning to use openmp for parallel operating the former codes, but when I'm reading some resources on the internet, I get confused about some concept, like enclosed parallel region. I'm not a native speaker in English, and I don't major in computer science, so I'm not sure what's the meaning of it. The following is a copy of https://software.intel.com/zh-cn/node/512042 that explaining the private clause. So my question is what's the meaning of enclosed parallel construct, can I understand it as nest parallel construct? If not, what's the difference between this two concepts? If there is an example, that will be the best! Thank you for all who answer my question.
Variables in a list can appear in other clauses as follows:
Variables that appear in a PRIVATE, FIRSTPRIVATE, or REDUCTION clause
in a parallel construct can also appear in a PRIVATE clause in an
enclosed parallel, task, or worksharing construct.
Variables that appear in a PRIVATE or FIRSTPRIVATE clause in a task
construct can also appear in a PRIVATE clause in an enclosed parallel
or task construct.
Variables that appear in a PRIVATE, FIRSTPRIVATE, LASTPRIVATE, or
REDUCTION clause in a worksharing construct can also appear in a
PRIVATE clause in an enclosed parallel or task construct.

So my question is what's the meaning of enclosed parallel construct,
can I understand it as nest parallel construct?
Yes, your understanding is correct. An enclosed parallel construct is nested inside an enclosing parallel construct -- so the enclosing parallel construct is more extensive than the enclosed.
If you write your code in one long source file then the enclosed construct is likely to be indented further than the enclosing construct.

Related

Are operators a subset of statements?

Basically in all high-level languages (as I know) we have two main categories of language mechanisms to create a program: statements and expressions.
Usually statements are represented by some subset of language's keywords: if/else/switch, for/foreach/while, {} (or BEGIN/END), etc.
Expressions are represented by literals (which represent some data) and operators: literals: 1, 2, -100, testTest, etc; operators: +, -, /, *, ==, ===, etc.
If we think deeper, we can notice that statements usually answer on question "what?" and expressions -- on question "how?". Statements represent actions, expressions represent the context of actions.
Then we may look in expressions' parts again: literals and operators. Operators are actions too.
And here is my question again: are operators a subset of statement?
P.S. Generally, I understand that statements and expression are used together to aim some programming target. Separation of this categories is mostly theoretical.
In general, "operator" describes a kind of syntactic form, which can be used to produce an expression, a statement, or some other class of language entity. So, technically, the answer to your question is, "no".
For example, Haskell uses a | operator to generate an algebraic type spec, which is neither an expression nor a statement:
data Maybe a = Just a | Nothing

Is a single constant value considered an expression?

After reading this answer on a CSS question, I wonder:
In Computer Science, is a single, constant value considered an expression?
In other words, is 7px an expression? What about just 7?
Quoting Wikipedia, emphasis mine:
An expression in a programming language is a combination of one or more explicit values, constants, variables, operators, and functions that the programming language interprets [...] and computes to produce [...] another value. This process, as for mathematical expressions, is called evaluation.
Quoting MS Docs, emphasis mine:
An expression is a sequence of one or more operands and zero or more operators that can be evaluated to a single value, object, method, or namespace. Expressions can consist of a literal value [...].
These both seems to indicate that values are expressions. However, one could argue that a value will not be evaluated, as it is already only a value, and therefore doesn't qualify.
Quoting Techopedia, emphasis mine:
[...] In terms of structure, experts point out that an expression inherently needs at least one 'operand’ or value that is acted on, and must have one or more operators. [...]
This suggests that even x does not qualify as expression as it is lacking one or more operators.
It depends on the exact definition of course, but under most definitions expressions are defined recursively with constants being one of the basis cases. So, yes, literal values are special cases of expressions.
You can look at grammars for various languages such as the one for Python
If you trace through the grammar you see that an expr can be an atom which includes number literals. The fact that number literals are Python expressions is also obvious when you consider productions like:
comparison: expr (comp_op expr)*
This is the production which captures expressions like x < 7, which wouldn't be captured if 7 isn't a valid expression.
In Computer Science, is a single, constant value considered an expression?
It depends entirely on the context. For example, FORTRAN, BASIC, and COBOL all have line numbers. Those are numeric constant values that are not expressions.
In other contexts (even within those languages) a numeric constant may be an expression.

In PROLOG, How can I use assert recursively without getting 'true' result?

I'm planning to make new facts based on existing facts, by using assert.
However, the number of facts to be made will be more than 500, so that typing semicolon to go further steps become pretty tedious work.
thus I want to ignore or pass the 'true'(in the SWI PROLOG)
Are there any ways to deal with this?(ex. automatically pass all the 'true's...)
here's a part of my code
%initialize
initialize :-
discipline(X,Y),
assert(result(X,0)).
I have too many Xs in discipline(X,Y)..
maybe
?- forall(a_fact(F), your_fact_processing(F)).
In this specific case forall is actually preferred, but in general, in Prolog you have to rely on the language's mechanism for this kind of iteration. Here's an example for your case:
initialize:-
discipline(X,Y),
assert(result(X,0)),
fail.
initialize.
In this bit of code above, you are telling the interpreter that initialize should perform all the 'asserts' given possible disciplines through the backtracking mechanism. Unless you become really familiar with this, Prolog will never "click" for you.
Note that in this example initialize will never fail, even if there are no disciplines (and therefore no results) to assert. You'll need some extra work to detect edge-cases like that - which is why forall is actually preferred for this specific task of assertin many facts.
Also note that if it's good practice to not have singleton variables declared, you can use the notation where variables that you won't use start with the '_' (underscore) character.

What languages don't define execution order for multi-statement for statements?

Some C-like languages allow multiple statements in the update part of a for statement, e.g.
for (int i = 0; i < limit; i++, butter--, syrup--, pancakesDevoured++)
Java explicitly defines the order for such statements in JLS 14.14.1.2 and 15.8.3 of ECMA-334 (C#) says "the expressions of the for-iterator, if any, are evaluated in
sequence" which I'm reading as left-to-right.
What languages, if any, allow multiple statements in the update part of a for loop but either don't define an ordering for such statements or use an order other than left to right?
edit: removed the C tag since that started a sequence point discussion and there's plenty of that already.
Technically, that's a single expression, not one or more statements, though the distinction isn't super important.
Good old C makes only limited promises about what order expressions like this will be evaluated in. In your example, the order doesn't matter. But consider this expression:
a[i++] = i
If i was 1 before evaluating this expression, should a[1] now equal 1 or 2? As I understand the C specification, the behavior of this expression is undefined, meaning that what you get depends on which compiler you use.
Thanks to #mizo for a readable reference on sequence points, and to #ChrisDodd for pointing out that if you're making simple independent assignments that are separated by the comma operator, C and C++ do fully specify a left-to-right evaluation order.

Prolog loops and conditional statements?

Is there anything in Prolog that works like a for loop and if then condition?
if/then/else can be obtained with (->)/2 and (;)/2:
( If ->
Then
; Else
)
Sometimes this is useful. In general though (when the condition contains variables), it will make your programs unsound and incomplete. Whenever it is possible to describe the conditions with pattern matching, you should use pattern matching instead. You can then not only check but also generate solutions.
If you are looking for such kinds of statements then you are not thinking in Prolog :)
Just kidding, by the way there aren't plain translation or for and if/else, but you can think about how they should be in prolog:
an if/else statement can be obtained by just having two rules that match over different conditions
a for loop can be done with two recursive rules, one is the base case and it doesn't depends upon itself to keepon while the other does what you intend to do inside the loop and follows itself..

Resources