Reputation: 5426
I have made a 10x10 array with random values. Using fortran 90.
Edit: I found a solution to my problem, going to add it when it is in a more presentable state.
real :: x
integer, dimension(10,10) :: matrix
integer d,f,j,sum
do d=1,10
do f=1,10
call RANDOM_NUMBER(x)
j = FLOOR(10*x)
matrix(d,f) = j
sum= sum + j
write(*,*)'RND number', matrix(d,f)
end do
end do
write(*,*)'Sum of all elements in the array: ', sum
Now, what I want to do is - to create 2 new arrays called array1 and array2, they would both be 5x10, and contain columns 1-5, and 6-10 of the initial array.
This problem I have is one step in a larger assignment, which involves sending the new arrays to slave nodes (using MPI), doing some work with them, and sending results back to the master node. But that is out of scope for this question.
Upvotes: 0
Views: 1279
Reputation: 724
Next time post up what you did...
integer, dimension(10,10) :: matrix
integer, dimension(10, 5) :: trunk
integer, dimension(10, 5) :: tail
...
trunk = matrix(:, 1: 5)
tail = matrix(:, 6:10)
Or... maybe EQUIVALENCE could work, which you would have to try as I may have it wrong...
EQUIVALENCE (Matrix,Trunk), (Tail,Matrix(6,1))
@Vladimir said, 'If you just want to avoid unsolicited advices about your coding style (which I tend to give), you can just say that.' and I may do the same.
SUM is definitely either a PURE or PURE ELEMENTAL intrinsic.
I am not sure about RANDOM_NUMBER...
But this may be more stylish as you can omit the loops:
Matrix = RANDOM_NUMBER(x)
WHERE (Matrix <= <somefloor>)...
mySum = SUM(Matrix)
Upvotes: 1