Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- Software Development Tools (Compilers, Debuggers, Profilers & Analyzers)
- Intel® Fortran Compiler
- How to accessing a 2D array with indexing array

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

Highlighted
##

Qun_H_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

07-30-2017
12:32 AM

4 Views

How to accessing a 2D array with indexing array

Please help.

integer*4 idx(n),ind(m),k,p,q real*8 data(p,q),ipt(m),dp(p,q) DO k=1,m dp(idx(ind),k) = 2*ipt*data(idx(ind),k); ENDDO

My FORTRAN mex program has similar code as listed above. I need to recursively calculate specific elements of **dp,** column by column. The row indexes are given by the indexing arrays **idx** and **ind**. The results show that some of the elements are not properly set. I checked the program by setting break points in VS2013. It seems a indexing problem. My other version in which **dp** is 1D works very well. I also tried the following variations

dp([idx(ind)],k) = 2*ipt*data([idx(ind)],k);

Still without success. And the output seems somehow to be related to the optimization options /O2 or /O3.

I'm not familiar with Fortran. Only use it to write MEX to relieve the time-consuming part in MATLAB. **My question is when using indexing arrays to access specific elements of a 2D array, what's the meaning of the []? How can I properly code to realize the purpose.**

**Thanks.**

1 Reply

Highlighted
##

Michael_R_3

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-02-2017
07:51 AM

4 Views

Hi Qun,

Hi Qun,

It's a little hard to follow, but from my understanding you previously had declared dp(p), and had the k loop in matlab? And this worked?

My suggestion is to go back to basics, and rather than access as an array write as an explicit loop:

integer*4 idx(n),ind(m),k,p,q real*8 data(p,q),ipt(m),dp(p,q) ! New loop variable integer*4 i DO k=1,q ! dp(idx(ind),k) = 2*ipt*data(idx(ind),k); ! Replace with loop... DO i = 1, m dp(idx(ind(i)),k) = 2 * ipt(i) * data(idx(ind(i)),k) END DO END DO

Sorry if there's a mistake!

I also think that your k loop should be going from 1 to q as the second dimension is sized q, not m - maybe this is the source of your trouble?

FYI in Fortran [ ] or (/ /) are used to create an array - I don't think you need this for the example.

If this doesn't help try coding what you want in Matlab so it works, and post that here so that I, or others, can help.

Good luck,

Michael

For more complete information about compiler optimizations, see our Optimization Notice.