Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

What's the best way to do this?

alexismor
Beginner
400 Views
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!

Message Edited by alexismor on 09-18-2005 09:30 PM

Message Edited by alexismor on 09-18-2005 09:31 PM

0 Kudos
2 Replies
Jugoslav_Dujic
Valued Contributor II
400 Views
What's wrong with a plain vanilla do-loop?
DO j=1,n
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
Jugoslav
0 Kudos
alexismor
Beginner
400 Views
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
0 Kudos
Reply