Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

problems with cshift

jft27
Beginner
840 Views
Hi,
I'm having a problem using chsift that doesn't make a lot of sense to me.

the following code works,
a(:, i:j) = chsift(a(:, i:j), shift = (/x, x, x/), dim =1)

but if i replace the shift with an array with value x and size 3 it goes out of bounds according to the results of compiling with -CB

what stupid thing am I doing wrong?

thanks
Jeremy
0 Kudos
5 Replies
Steven_L_Intel1
Employee
840 Views
I can't reproduce the problem based on this one line. Please submit a support request to Intel Premier Support and attach a small but complete program that demonstrates the problem. Or you can post a small but complete problem here for people to look at.
0 Kudos
jft27
Beginner
840 Views
okay here's an example where it does work
program shiftprob

  !the idea of the program is that if we store a block diagonal matrix
  !in a way where none of the zeros are kept and we then want to recover the
  !full structure then the function undiag will stick the blocks onto the diagonal parts of the array. 



  implicit none

  integer, parameter :: npol=3
  real :: a(npol, 4*npol), b(4*npol, 4*npol)


  a = 1.0 !a is where the matrix is stored

  b = undiag(a) !b will be block diagonal with the elements of a on the 'diagonal'

  print*, 'a', a
  print*, 'b', b



contains

  !=====================================================

  function undiag(x)
    
    real, dimension(:, :) :: x
    integer :: n, i, shift(npol)

    real, dimension(size(a, 2), size(a,2)) :: undiag

    n = size(x, 2)
    undiag = 0.0

    undiag(1:npol, :) = x

    do i = 1, n - npol + 1, npol
       shift = i-1
       undiag(:,i:i+npol-1) = cshift(undiag(:, i:i+npol-1),shift = (/i-1, i-1, i-1/) , dim = 1)

    end do


  end function undiag


  !====================================================

end program shiftprob
and here's one where it doesn't
program shiftprob

  !the idea of the program is that if we store a block diagonal matrix
  !in a way where none of the zeros are kept and we then want to recover the
  !full structure then the function undiag will stick the blocks onto the diagonal parts of the array. 



  implicit none

  integer, parameter :: npol=3
  real :: a(npol, 4*npol), b(4*npol, 4*npol)


  a = 1.0 !a is where the matrix is stored

  b = undiag(a) !b will be block diagonal with the elements of a on the 'diagonal'

  print*, 'a', a
  print*, 'b', b



contains

  !=====================================================

  function undiag(x)
    
    real, dimension(:, :) :: x
    integer :: n, i, shift(npol)

    real, dimension(size(a, 2), size(a,2)) :: undiag

    n = size(x, 2)
    undiag = 0.0

    undiag(1:npol, :) = x

    do i = 1, n - npol + 1, npol
       shift = i-1
       undiag(:,i:i+npol-1) = cshift(undiag(:, i:i+npol-1),shift = shift , dim = 1)

    end do


  end function undiag


  !====================================================

end program shiftprob
compile with

ifort -CB shiftprob.f90 -o shiftprob

hope someone can tell me what I'm doing wrong
thanks
Jeremy

Message Edited by Steve_Lionel on 12-13-2005 12:58 PM

0 Kudos
Steven_L_Intel1
Employee
840 Views
Hmm - works for me. What do you get when you type:

ifort -what shiftprob.f90
0 Kudos
jft27
Beginner
840 Views
Intel Fortran 9.0-5238

thanks for helping
Jeremy
0 Kudos
Steven_L_Intel1
Employee
840 Views
Hmm, that's somewhat old. There's an update coming out later this week - try it on that and let me know what happens.
0 Kudos
Reply