- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyone,
I'm slowly getting better at Fortran, in no small part to your numerous contributions. I was wondering if someone could tell me the best way to do this:
dim=size(H(1,: )) !it's a square matrix
k=0
forall(i=1:dim,j=1:dim,H(i,j).ne.0)
k=k+1
row(k)=i
col(k)=j
val(k)=H(i,j)
end forall
I know that this code is illegal, but it represents what I'd like to do (which is fill 3 arrays with the row, column and value of the non-zero elements of H).
Thanks!
I'm slowly getting better at Fortran, in no small part to your numerous contributions. I was wondering if someone could tell me the best way to do this:
dim=size(H(1,: )) !it's a square matrix
k=0
forall(i=1:dim,j=1:dim,H(i,j).ne.0)
k=k+1
row(k)=i
col(k)=j
val(k)=H(i,j)
end forall
I know that this code is illegal, but it represents what I'd like to do (which is fill 3 arrays with the row, column and value of the non-zero elements of H).
Thanks!
Message Edited by alexismor on 09-18-2005 09:30 PM
Message Edited by alexismor on 09-18-2005 09:31 PM
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What's wrong with a plain vanilla do-loop?
DO j=1,nJugoslav
DO i=1,n
IF (H(i,j).NE.0) THEN
k = k+1
row(k) = i
col(k) = j
val(k) = H(i,j)
END IF
END DO
END DO
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Jugoslav,
I guess nothing is wrong with it. I'm just trying to use the intrinsic functions as much as possible because it just seems more elegant :) (and faster since at some point I'll be running my code on a cluster).
Cheers,
Alexis
I guess nothing is wrong with it. I'm just trying to use the intrinsic functions as much as possible because it just seems more elegant :) (and faster since at some point I'll be running my code on a cluster).
Cheers,
Alexis

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page