Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Array programming
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Scalar languages=== In scalar languages such as [[C (programming language)|C]] and [[Pascal (programming language)|Pascal]], operations apply only to single values, so ''a''+''b'' expresses the addition of two numbers. In such languages, adding one array to another requires indexing and looping, the coding of which is tedious. <syntaxhighlight lang="c"> for (i = 0; i < n; i++) for (j = 0; j < n; j++) a[i][j] += b[i][j]; </syntaxhighlight> In array-based languages, for example in Fortran, the nested for-loop above can be written in array-format in one line, <syntaxhighlight lang="fortran"> a = a + b </syntaxhighlight> or alternatively, to emphasize the array nature of the objects, <syntaxhighlight lang="fortran"> a(:,:) = a(:,:) + b(:,:) </syntaxhighlight> While scalar languages like C do not have native array programming elements as part of the language proper, this does not mean programs written in these languages never take advantage of the underlying techniques of vectorization (i.e., utilizing a CPU's [[Single instruction, multiple data|vector-based instructions]] if it has them or by using multiple CPU cores). Some C compilers like [[GNU Compiler Collection|GCC]] at some optimization levels detect and vectorize sections of code that its heuristics determine would benefit from it. Another approach is given by the [[OpenMP]] API, which allows one to parallelize applicable sections of code by taking advantage of multiple CPU cores.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)