Fortran Fortran 90/95: Array Help with IF Statement

Click For Summary
In Fortran 90/95, a 10x10 array can be modified using an if statement within nested do loops to set elements to zero based on a condition. To achieve simultaneous updates, a logical array can be created to identify which elements need changing, followed by applying modifications independently. The 'where' construct can also be utilized for this purpose, allowing for concise code that modifies elements based on conditions without traditional loops. However, it's important to note that due to the sequential nature of computer programs, true simultaneous updates across all elements aren't feasible without parallel processing. The discussion raises questions about the necessity of changing all memory locations at once, suggesting that the approach may depend on the specific requirements of the task.
Lukejambo
Messages
13
Reaction score
0
Hi,

For fortran 90/95, I've written a 10x10 array of numbers.

2 do loops (n,m) from 1 to 10 indicate the subscript of the elements in this array.

I've applied a generic rule to the array elements where they become 0 if they are above a certain number.

Using an if statement to change the elements they will become 0 or stay the same according to the do loops (ie: so element 1,1 will change first and element 10,10 will change last)

Is it possible to delay or stop the do loop so the if statement does its thing deciding whether an element changes and then change each and every element at the same time?

Any help would be much appreciated.
 
Technology news on Phys.org
You can create an array of type logical, which will be true for elements which need to be changed, and then do the modification independently.

In Fortran 90/95, you can also use the where construct instead of loops
Fortran:
real, dimension(10,10) :: a
where (a > x) a = 0
 
By nature a computer program is sequential, so it is only modifying one memory location at a time. The only way to modify all of the memory elements at the same time would be to have 100 cores(or threads) in parallel each modifying one of the memory locations. Even then, the memory modifications will probably not all happen at the same time. Why do you want to change all of the memory locations at once?
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 19 ·
Replies
19
Views
6K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 5 ·
Replies
5
Views
9K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K