Integer variable no longer usable after forall construct - variables

I have an integer variable that is declared at the head of my subroutine. After I've used it as a control variable inside a forall construct, I can no longer use it as the control variable of a do loop. The compiler (Intel, v. 12.0.3) complains
xyz.f90(1210): error #6404: This name does not have a type, and must have an explicit type. [I]
do i=1,sp_basis%num_dim
---------------^
xyz.f90(1210): error #6063: An INTEGER or REAL data type is required in this context. [I]
do i=1,sp_basis%num_dim
I have tried to write a small example to replicate this behaviour (and compiled the file with the same compiler options as the actual problematic one, apart from -c), but this compiled & worked nicely, so below is my (slightly shortened) problematic code (implicit none applies to the entire module this code belongs to):
subroutine xyz(stuff)
use data, only: ppm, npeaks
! some declarations
integer :: i ! ...
associate(sp_basis => public_spectra%basis(counter))
spots = npeaks * np
allocate(ref_curves(spots,npeaks,sp_basis%num_dim), stat=stat)
if (stat.ne.0) then
! ...
end if
forall (i=1:max_dim) uppers(i) = ubound(sp_int%int,i)
forall (i=1:max_dim) lowers(i) = lbound(sp_int%int,i)
forall (i=1:npeaks,j=1:sp_basis%num_dim) peak_pos_hertz(j,i) = ppm_to_hertz(ppm(permutation(j),i), sp_axes(j))
do peak_considered=1,npeaks
do pos=(peak_considered-1)*np+1,peak_considered*np
do i=1,sp_basis%num_dim ! <-- COMPLAINT
If I change i to a name that was not used as a forall construct's control variable everything works. Also, this is the second time I've run into this problem.
This is how the compilation is done (xyz.f90 is one of many files that make up the entire program):
ifort -c -g -C -check noarg_temp_created -traceback -warn -warn nodeclarations -nogen-interface xyz.f90
Does any of you know what the problem might be?
Thanks a lot for your time!

For all those interested, it's a bug in the Intel compiler. Here you can read more about it. Also it sounds like this bug will be fixed in a compiler version that is to be released some time in 2012.

Related

I use Simply Fortran, but cannot include modules there [duplicate]

This question already has an answer here:
The mysterious nature of Fortran 90 modules
(1 answer)
Closed 2 years ago.
I have written the following Fortran Code in the System called "Simply Fortran":
program math2
use prec, only: print_kind_info
implicit none
call print_kind_info
end program math2
module prec
implicit none
integer, parameter :: dp = selected_real_kind(P=10,R=30)
integer, parameter :: sp = selected_real_kind(P=5,R=15)
integer, parameter :: dp_alt = kind(0.d0)
public :: dp, sp, print_kind_info
private
contains
! Subroutine comes here
subroutine print_kind_info()
real(sp) :: sing_prec
real(dp) :: double_prec
print*,'Single precision is kind ',sp
print*,'Double precision is kind ',dp
print*,'Kind of double precision number is ',dp_alt
end subroutine print_kind_info
end module prec
However, the module which I call 'prec' is not found. More precisely, the error message is the following:
use prec, only: print_kind_info
1
Fatal Error: Can't open module file 'prec.mod' for reading at (1): No such file or directory
compilation terminated.
Error(E42): Last command making (build\prec.o) returned a bad status
Error(E02): Make execution terminated
* Failed *
What I have to do that the module (see above code) is recognized properly? It is recognized in File Outline, but it is not inside the "module" folder. And I really don't have a plan here what to do. Moreover I have no experience with the Makefile environment (this BASHrc-like things I am not familar with).
Simply said: The problem is that the compiler doesn't know the module prec.mod at is defined after the main program but is used already in the main program.
So first define the module and after that the main program.
Better would be to place the module in a separate files and the main program in another file and compile these (in the right order) and link everything together.

How can a CMake variable be hidden?

I have a CMake project which lets a globally set variable (set with -DARDUINO_SDK_PATH=/a/b/c on command line) disappear i.e. suddenly the given value is gone which leads to a fatal error.
I know there are different ways to "hide" a variable (e.g. inside functions or external projects)
In my case:
the variable is not being set explicitly anywhere in the code (e.g. via set() or find_path())
the access which leads to the error is on top level (i.e. not inside a function)
there are instructions (i.e. same file/line) where in one case the variable has the value it's been given and the next time it's gone
Tracing the variable with variable_watch(ARDUINO_SDK_PATH) I can see that everything works fine before the compiler is being checked:
cmake -DARDUINO_SDK_PATH=/a/b/c <path>
...
... everything fine, ${DARDUINO_SDK_PATH} == '/a/b/c' everywhere
...
-- Check for working C compiler: /usr/bin/avr-gcc
...
... here the variable is empty and not being traced any more
...
Here is my suggestion:
Does the compiler check (indicated by check for working C compiler .. on the terminal) have it's own variable space and does not know variables provided on command line?
Note: This question is a generalization of this question, which has become way too specialized but might offer some useful background information.
That any modification to variable is not traced after the variable_watch() command seems like a bug somewhere in CMake to me.
Generally speaking a "cached CMake variable" can be hidden by a "normal CMake variable" with the same name. But e.g. find_path() won't run again or modify a variable if already set.
Here is an example:
cmake_minimum_required(VERSION 2.4)
project(VariableWatchTest NONE)
variable_watch(MY_TEST_VAR)
set(MY_TEST_VAR "something" CACHE INTERNAL "")
message("${MY_TEST_VAR}")
set(MY_TEST_VAR "hiding something")
message("${MY_TEST_VAR}")
unset(MY_TEST_VAR)
message("${MY_TEST_VAR}")
find_path(MY_TEST_VAR NAMES "CMakeLists.txt" HINTS "${CMAKE_CURRENT_LIST_DIR}")
message("${MY_TEST_VAR}")
Would give (without the variable_watch() messages:
-- something
-- hiding something
-- something
-- something
References
What's the CMake syntax to set and use variables?
I'm not sure whether this is a bug or a feature but (at least some) CMake variables are not available in certain steps of the CMake configuration procedure.
You can check this by adding something like this to your toolchain file:
MESSAGE("FOO: ${FOO}")
and run CMake like this
cd build-dir
cmake -DFOO=TEST ..
You will likely see FOO printed with value TEST once in the beginning of the configuration process and later printed again but being empty.
Just don't access variables from the global space inside a toolchain file (doesn't belong there anyway).

Accessing files using MPI

THIS WORKED (see comment in the code)
I am new to MPI and still learning it. I am actually trying to write a code in Fortran to read data from same set of files (already generated) on each processor at same time and perform different computations in different processors. For which I decided to use,
program...
use mpi
implicit none
.
.
.
call mpi_file_open(mpi_comm_world,filename_i,mpi_mode_rdonly,mpi_info_null,i,ierr)
to start with the program. Now, each processor calls a subroutine in which I am trying to use normal fortran command to open files, open(i,*)...(since I don't use mpi in subroutine).
First, I am not confident about this idea itself. Next, it gives this error,
_open(mpi_comm_world,filename_i,mpi_mode_rdonly,mpi_status_ignore,i,ierr) (1)
Error: There is no specific subroutine for the generic 'mpi_file_open'
at (1)
Please give your suggestions and comments.
The thing I am trying to do is very long because of subroutine, I would just include a prototype code, if this is solved, my problem will be solved. The code below gives the same error as said before. Please give your suggestions. Thanks.
program hello
use mpi
integer::ierr,num_procs,my_id,i,j,no
call MPI_INIT(ierr)
call MPI_COMM_RANK (MPI_COMM_WORLD,my_id,ierr)
call MPI_COMM_SIZE (MPI_COMM_WORLD,num_size,ierr)
open(4,file='hella') !CHANGING THIS LINE
do i=1,num_size
if(i-1 .eq. my_id)print*,"In",my_id
if(i-1 .eq. my_id)then
read(4,*)no
print*,no
endif
enddo
call mpi_finalize(ierr)
end program hello

How do I access global variables in local scope without "possibly used before declaration" -errors?

I'm getting this warning: WARNING: $a possibly used before declaration. for my function:
Func test()
If (IsDeclared("a")) Then
ConsoleWrite($a)
Else
ConsoleWrite("Not declared")
EndIf
EndFunc
Global $a = "test"
test()
Can be avoided by using the global variable as a parameter to the function. But I need this construct because it's tied to a file-operation which I don't want to execute every time I need the variable.
How can I do this without generating a "possibly used before declaration" -error?
Firstly, this warning is reported by Au3Check.exe, a program that is separate from the AutoIt compiler itself. You'll find that your program will still compile/run after this warning is printed. One possible solution is to just ignore it, or not run Au3Check on your code (not recommended).
Your code will work fine if you simply defined your functions at the end. You were probably already aware of this, and I know when you #include functions they will likely be at the top.
Another possible solution if it really is annoying you is to use Eval. I don't recommend this as it's not needed and breaks your script if using Au3Stripper (used to be obfuscator) though your code is already broken by the use of IsDeclared.
A solution (probably the best solution) you probably wouldn't have thought of is using Dim for this.
Func test()
If(IsDeclared("a")) Then
Dim $a
ConsoleWrite($a & #LF)
Else
ConsoleWrite("Not declared" & #LF)
EndIf
EndFunc
Global $a = "test"
test()
Basically, Dim acts like Local, unless a variable with that name already exists in the global scope, in which case it is reused.
I'm getting this warning: WARNING: $a possibly used before declaration.
AU3Check determined a variable being accessed prior to its declaration (by order of code). It's unaware the containing function is not called prior to variable's declaration, hence produces a warning (rather than reporting an error).
Declaring concerning function after declaration of global variable it is to access prevents AU3Check's warning. Example:
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
Global $a = "test"
test()
Func test()
If (IsDeclared("a")) Then
ConsoleWrite($a)
Else
ConsoleWrite("Not declared")
EndIf
EndFunc

Can't find libgfortran-3.dll in Fortran

I am new to mingw32-gfortran, and I am finding it hard to statically link the specific dll's. I am trying to write a code on finding large factorials,the code compiles without any errors on code::blocks but gives an error about missing dll's when opened from cmd. Is there anyway to statically link these dll's to my exe (I don't mind if it is bloated,I just want my code to be portable).
Does gfortran provide similar libraries for static linking? I have also posted my code for any reference. It would really mean much to me if someone here helped me out, I have already tried code blocks forums,and read numerous posts on other websites. Still no luck.
Note : I use Win 7 64-bit
! A fortran95 program for G95
! By WQY
program main
implicit none
integer ,allocatable,dimension (:) :: a
integer :: re_i,n,digit=1,temp=0,zero=0,i,j,beg,rate,ends
allocate(a(10000000))
a(1)=1
print*,'please enter the number'
read *, n
call system_clock(beg,rate)
do j=2,n
do i=zero+1,digit
temp=temp+a(i)*j
a(i)=temp-(temp/10)*10
temp=temp/10
end do
do while (temp>0)
digit=digit+1
a(digit) = temp-(temp/10)*10
temp = (temp/10)
end do
do while(a(zero+1)==0)
zero=zero+1
end do
end do
call system_clock(ends,rate)
write(*,1,advance='no') a(digit)
write (*,2,advance ='no') '.'
write (*,1) ( a(i),i=digit-1,digit-50,-1)
1 format(120i1)
print *,' X 10^' ,digit-1
2 format(100a1)
print '("computation time ",f6.3," seconds")',real(ends-beg)/real(rate)
re_i=system("pause")
end
Does anyone know how to compile a program in gfortan from command line? Errors seems to pop up every time I try to do so.