INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Run time error

Run time error

(OP)
Hi guys,

Perhaps I need some help again. My program can compile but it generate run time error.
The message is

"C:\Console1\Console1\Debug\Console1.exe is not a valid Win32 application"

When I reduce the number of elements in arrays, it said



What is the bug I should look for ?

Thanks a lot.

RE: Run time error

(OP)
I used Intel Visual Fortran Compiler.

RE: Run time error

The error message seems pretty clear to me.

You have an array R which has at least 1 dimension, maybe 2 or 3, it does not matter because the error message is telling you that the problem is with the first dimension.

It says that you have declared the first dimension to have a maximum allowed index value of 2, yet, the index being passed to R and the reason why the program stopped, is 3.

So, look for place where you call R and inspect the value of the index in the first dimnension; you do that by simply adding write statements before call to R, just make sure you flush the output channel otherwise the data will be left in the queue.

RE: Run time error

(OP)
I am wondering what R is. My program does not contain the array of such name. I did have array "r" (small r, not R) with one dimension, two elements, i.e., a vector of 2 elements. However, I will try to look for it. Thanks for the suggestion.

RE: Run time error

(OP)
Oh goshhhh

salgerman , you are absolutely amazing!

By the way, what about "not a valid Win32 application" ?

When I declare A(48,48,2,48,48,48) it has this error.
But when I declare A(20,20,2,20,20,20) it can run.

What could it be ?

I'd like to thank you for your suggestion in this and the previous post. It works!

RE: Run time error

Fortran is case-insensitive, by the way, so r and R are the same thing.

Sounds like a memory problem.

20*20*2*20*20*20 = 6.4MB
48*48*2*48*48*48 = 509MB

what's your computer's RAM? And remeber, not all is available to you, MS-Windows alone takes a good chunk, plus every other program, browsers, etc.

RE: Run time error

Oh, sorry, I forgot to multiply the numbers above by the size of the type of A.

is A an integer or real?

I think integers are 4-bytes long and reals 8-bytes long...if A is real, multiply the numbers above times 8...do you have 4GB of RAM? available to be used?

RE: Run time error

(OP)
I have 6 GB of rams, but it still cannot run when I declared that high.

RE: Run time error

Quote (armeros)


I have 6 GB of rams, but it still cannot run when I declared that high.
You have probably reached the maximum array size - see
https://software.intel.com/en-us/articles/intel-fo...

Anyway, 6-dimensional array isn't good idea. The task should be reduced to the usual matrices and vectors.

RE: Run time error

If you're compiling 32-bit then the max size will be 2Gb. Are you using a 32 or 64 bit OS? I know you have 6Gb RAM but that doesn't imply you are running a 64bit OS. Is your program built for 32 or 64 bit? It defaults to WIN32 which is 32 bit. It will be x64 for 64bit.

RE: Run time error

This message from the first post
"C:\Console1\Console1\Debug\Console1.exe is not a valid Win32 application"
says, that it's 32-bit.

RE: Run time error

(OP)
mikrom,

I used your suggestion, and it can run, but it takes time so long that I wonder if it is still running. When I do (30,30,2,30,30,30) (AND I DID NOT USE MULTIDIMENSIONal ARRAYS!), each loop is about 4 seconds. When I do (250,250,2,250,250,250), the first loop takes 1 hour and it still does not finish.

RE: Run time error

(OP)
It seems I have to find a better way to write the code. The loop takes more than 1, maybe 2 or 3, to complete. In the less elements version, it took 160 loops to finish. It will be more than 6 days and I can't wait that long since this is only the first part of the code.

RE: Run time error

Are you using any kind of parallel processing? I have done it once before, it is pretty trivial to implement and reduces real running time several times. Look into OpenMP.

RE: Run time error

(OP)

Quote:

Are you using any kind of parallel processing?

No, and I heard that it is quite complicated ? I will take a look at OpenMP tomorrow and see what it is. Does it require an installation of other softwares ?

Thanks for all helps here.

RE: Run time error

At the time of my parallel processing needs, I was initially using G95 when I read it does not support OpenMP. G95 does support something called co-arrays; but, to make use of that, you really need to write your program in a different way...said another way, you would need to re-write an existing program.

GFortran does support OpenMP out of the box, at least on Linux; for Windows, you may have to fetch a separate download.

So, you first need to find out if your compiler supports OpenMP; if so, great, if not you may need to consider switching compilers...that's what I did.

The nice thing about OpenMP is that you do NOT need to re-write an existing program to make use of it. OpenMP directives are placed behind regular Fortran comments to the point that if the compmiler being used does not support OpenMP, the directives stay out of the way and the program compiles and runs normally in just one CPU.

Needless to say, you need to make sure that your loops can be executed in parallel, in the first place; meaning, calculations for a given iteration shouldn't need values that need to be calculated in another iteration...said another way, your loops shouldn't need to run sequentially, in some order; instead, loops should be able to be run in any order.

If it almost as you yourself made 5 copies of your program and then modify each copy to alter the outer loop so that instead of going from 1 to 250, it goes from 1-50 in one copy, 51-100 in the next, 101-150...you get the picture; then you can run your program in any order, generate the matrix, write it disk and glue it back together after the fact...OpenMP would do that for you without you having to make copies of your program or modifying your one set of nested loops...OpenMP will take care of it.

RE: Run time error

(OP)
I use Intel Visual Fortran Compiler(it runs under Microsoft Visual Studio 2008). My computer is 32-bit, Windows 7.


However, I need help from IMSL libraries. I don't know how to incorporate the libraries in GFortran. (For GFortran, I used Geany compiler.)

RE: Run time error

It looks like Intel supports OpenMP with -Qopenmp compiler flag. You may need version 10.1 or later.

RE: Run time error

(OP)
zI tried to read these two links and it is still not clear to me how I can use openMP with my compilers.

https://software.intel.com/sites/products/documentation/doclib/stdxe/2013/composerxe/compiler/fortran-mac/GUID-0E85F327-A19E-410C-8203-0A89C8F32635.htm

https://software.intel.com/en-us/articles/how-to-use-intelr-compiler-openmp-compatibility-libraries-on-windows

Suppose I have pararell loops,

CODE --> FORTRAN

DO i=1,250
                DO j = 1,250
                  DO ii=1,2
                  ................................
                  ................................
                   DO k = 1,250
                     DO  = 1,250
                     .............................
                     .............................
                     END DO
                  END DO
                END DO
               END DO
             END DO 

Could you please give me suggestion how to do this ?

Thank you very much.

RE: Run time error

(OP)
I should be more specific about pseudo code

CODE --> FORTRAN

PROGRAM test
IMPLICIT NONE
REAL, PARAMETERS :: a,b,c
REAL, DIMENSION (250,250,2,250,250,250) :: X,Y
DO i=1,250
                DO j = 1,250
                  DO ii=1,2
                  ................................
                  ................................
                   DO k = 1,250
                     DO l = 1,250
                     .............................
                     .............................
                     END DO
                  END DO
                END DO
               END DO
             END DO 
END PROGRAM test 

RE: Run time error

Check this out...go to the pages from the various bullets...first, you need to learn to compile for using OpenMP...you need compiler flags and you need to add "use openmp_lib" statement inside the fortran source THEN, of course the directives surrounding the do loop to be parallelized.

RE: Run time error

salgerman, thank you very much for the information about OpenMP.
I never tried such thing before before, but now I'm interested now.

I have gfortran 4.8.1 installed with MinGW+MSYS on Windows.
First when I tried the switch -fopenmp I got an error. Then I added to my MinGW+MSYS installation the package mingw32-pthreads-w32 and now it compiles.

example: armeros.f95

CODE

! Compile with OpenMP:
! gfortran armeros.f95 -o armeros -fopenmp
program test
implicit none
integer :: i,j,ii,k,l,threads,thread_id
integer, external :: omp_get_num_threads, omp_get_thread_num
do i=1,250
  do j = 1,250
    !$OMP PARALLEL
    threads = omp_get_num_threads()
    thread_id = omp_get_thread_num() + 1
    do ii=1,2
      do k = 1,250
        do l = 1,250
          call do_something(i,j,ii,k,l,thread_id,threads)
        end do
      end do
    end do
    !$OMP END PARALLEL
  end do
end do
end program test

subroutine do_something(i,j,ii,k,l,thread_id,threads)
  implicit none
  integer :: i,j,ii,k,l,thread_id,threads

  write(*,10) thread_id, threads,i,j,ii,k,l 
  10 format(i2,'/',i2,': (i,j,ii,k,l) = (',i3,',',i3,',',i3,',',i3,',',i3,')') 
end subroutine do_something 

Compilation & Running:

CODE

$ gfortran armeros.f95 -o armeros -fopenmp
$ armeros
 2/ 2: (i,j,ii,k,l) = (  1,  1,  1,  1,  1)
 2/ 2: (i,j,ii,k,l) = (  1,  1,  1,  1,  2)
 2/ 2: (i,j,ii,k,l) = (  1,  1,  1,  1,  3)
 ...
 ... 

I have realized that number of threads returned from the function omp_get_num_threads() depends of the machine. At my work I got 8 threads and here (see above) at my hhome machine only 2.
The usage of threads seems to be very different too: At my work machine I saw 2 threads (1 and 8) and here only one thread (i.e.2( seems to be used.

Now, the question is how could be the task of armeros parallelized properly.
smile

RE: Run time error

Quote:


The usage of threads seems to be very different too: At my work machine I saw 2 threads (1 and 8) and here only one thread (i.e.2) seems to be used.

Wrong! After a while - now at my home machine i see that the thead 1 will be used too:

CODE

...
 1/ 2: (i,j,ii,k,l) = (  1,  2,  2, 12, 72)
 1/ 2: (i,j,ii,k,l) = (  1,  2,  2, 21,196)
 1/ 2: (i,j,ii,k,l) = (  1,  2,  2, 12, 73)
 1/ 2: (i,j,ii,k,l) = (  1,  2,  2, 21,197)
... 

RE: Run time error

mikrom: say, in your office computer, can you try specifying one more argument to the PARALLEL directive? Let's try to purposely increase the number of threads being used.

CODE

!$omp parallel do NUM_THREADS(4)
    .
    .
    .
    !$omp end parallel do 

Additionally, there may be need to specify which variables are private to the thread (mostly loop indices) and which variables are shared among threads (to be sure, the one variable to which all threads are contributing to).

CODE

!$omp parallel do NUM_THREADS(4)
    !$omp     private(ii,k,l) &
    !$omp     shared(A)
    .
    .
    .
    !$omp end parallel do 

RE: Run time error

(OP)
Do we need more than one single computer (or single processor) to do this ?

RE: Run time error


I don't know about multiple computers; what I have done before with these few directives is to take advantage of more than one core on a single computer...I know my Linux box at the office has 4 cores; this laptop seems to have two dual-core processors. You can easily inspect your computer by opening "my computer" properties or open the "task manager" and go to "performance" tab.

RE: Run time error

I took this simple example with 3 loops

CODE

! NON PARALLEL example
! Compile:
! gfortran armeros_n.f95 -o armeros_n
program test
implicit none
integer :: i,j, k, thread_id, threads, n
real :: start, finish

call cpu_time(start)
thread_id = 1
threads = 1
n = 0
do i=1, 4
  do j = 1, 5
    do k = 1, 5
      call do_something(i, j, k, thread_id, threads)
      n = n + 1
    end do
  end do
end do
call cpu_time(finish)

write(*,*)
write(*,*) 'Count = ', n
write(*,*) 'Time in seconds =', finish-start

end program test

subroutine do_something(i, j, k, thread_id,threads)
  implicit none
  integer :: i, j, k, thread_id, threads

  write(*,10) thread_id, threads, i, j, k 
  10 format(i2,'/',i2,': (i,j,k) = (',i3,',',i3,',',i3,')') 
end subroutine do_something 

and tried to parallelize the outer loop

CODE

do i=1, 4
 ...
end do 

using 4 threads - so:

CODE

! PARALLEL example
! Compile with OpenMP:
! gfortran armeros_p.f95 -o armeros_p -fopenmp
program test
implicit none
integer :: i,j,k, threads,thread_id, n
integer, external :: omp_get_num_threads, omp_get_thread_num
real :: start, finish

call cpu_time(start)
n = 0
!$omp parallel NUM_THREADS(4) PRIVATE(thread_id, i, j, k) 
threads = omp_get_num_threads()
thread_id = omp_get_thread_num() + 1
!$omp parallel do
do j = 1, 5
  do k = 1, 5
    i = thread_id
    call do_something(i, j, k, thread_id, threads)
    n = n + 1
  end do
end do
!$omp end parallel do
!$omp end parallel
call cpu_time(finish)

write(*,*)
write(*,*) 'Count = ', n
write(*,*) 'Time in seconds =', finish-start

end program test

subroutine do_something(i, j, k, thread_id,threads)
  implicit none
  integer :: i, j, k, thread_id, threads

  write(*,10) thread_id, threads, i, j, k 
  10 format(i2,'/',i2,': (i,j,k) = (',i3,',',i3,',',i3,')') 
end subroutine do_something 

Output:

CODE

$ gfortran armeros_p.f95 -o armeros_p -fopenmp
$ armeros_p
 2/ 4: (i,j,k) = (  2,  1,  1)
 1/ 4: (i,j,k) = (  1,  1,  1)
 3/ 4: (i,j,k) = (  3,  1,  1)
 4/ 4: (i,j,k) = (  4,  1,  1)
...
...
2/ 4: (i,j,k) = (  2,  5,  5)
1/ 4: (i,j,k) = (  1,  5,  5)
3/ 4: (i,j,k) = (  3,  5,  5)
4/ 4: (i,j,k) = (  4,  5,  5)

Count =          100
Time in seconds =   0.00000000 
It seems to work, but I don't see any CPU-time improvement between normal and parallelized version for bigger valuess of J and K.

For example for max J,K = 250 I got with normal version better CPU-time than with the parallelized version

CODE

...
 1/ 1: (i,j,k) = (  4,250,249)
 1/ 1: (i,j,k) = (  4,250,250)

 Count =       250000
 Time in seconds =  0.936005950 
and with parallelized version

CODE

...
 3/ 4: (i,j,k) = (  3,250,250)
 2/ 4: (i,j,k) = (  2,250,250)
 1/ 4: (i,j,k) = (  1,250,249)
 4/ 4: (i,j,k) = (  4,250,250)
 1/ 4: (i,j,k) = (  1,250,250)

 Count =       250000
 Time in seconds =   1.68481004 
What is wrong ?

RE: Run time error

Nothing is wrong...there is some overhead when creating and managing threads, so, the payback is not immediate...you would need to do away with your write statements give your do_something subroutine something costly to do, like calculating the sine of an angle or logarithm of something...then, keep increasing the number of times it is done...eventually, you will notice the ratio of the times it take to solve of 1cpu vs. Xcpu starts to increase, here is a sample picture.

Having said said that, I think you are using the "$omp parallel do" directive incorrectly. Consider the following:

  • A program structure is not supposed to be changed when adding OpenMP directives...you changed it, you took away the outer-most loop.
  • A program with OpenMP directives (behind in-line comment markers) is supposed to work the same whether the compiler understood the directives or not.
  • In short, you do NOT put a "$omp parallel do" INSTEAD of an actual loop; you use the directive to wrap the loop that you desire to parallelize.
In your case, you took away the outer loop and the associated loop variable i...what if the value of i was actually being used in some formula and affecting the calculated values? If the program runs in one thread, i will always be 1; if the program runs in 4 threads, the values will be 1, 2, 3, 4....but that is besides the point...what if the i-loop was supposed to go from 1 to 5000? You are not going to get 5000 threads and expect to assign i the value of the current thread...so, you leave the loop alone and simply surround it with omp directives and let OpenMP break down the range of the loop variable values into as many threads it can...but the values to the loop variable are assigned from its range, not from whatever thread it is in...those are two different things.



RE: Run time error

Thank you salgerman.

RE: Run time error

I tried the example without changing outer loop - only by adding OpenMP directives (on a machine with CPU Intel i7):

CODE

! PARALLEL example
! Compile with OpenMP:
! gfortran armeros_p.f95 -o armeros_p -fopenmp
program test
implicit none
integer :: i,j,k, thread_id, threads, n
integer, external :: omp_get_num_threads, omp_get_thread_num
real :: start, finish

call cpu_time(start)
n = 0
!$omp parallel do NUM_THREADS(4) PRIVATE(i, j, k, thread_id, threads)
do i=1, 4
  do j = 1, 5
    do k = 1, 5
      threads = omp_get_num_threads()
      thread_id = omp_get_thread_num() + 1
      call do_something(i, j, k, thread_id, threads)
      n = n + 1
    end do
  end do
end do
!$omp end parallel do
call cpu_time(finish)

write(*,*)
write(*,*) 'Count = ', n
write(*,*) 'Time in seconds =', finish-start

end program test

subroutine do_something(i, j, k, thread_id,threads)
  implicit none
  integer :: i, j, k, thread_id, threads

  write(*,10) thread_id, threads, i, j, k 
  10 format(i2,'/',i2,': (i,j,k) = (',i3,',',i3,',',i3,')') 
end subroutine do_something 

It seems to process the outer loop in 4 threads:

CODE

$ gfortran armeros_p.f95 -o armeros_p -fopenmp

$ armeros_p
 2/ 4: (i,j,k) = (  2,  1,  1)
 3/ 4: (i,j,k) = (  3,  1,  1)
 1/ 4: (i,j,k) = (  1,  1,  1)
 4/ 4: (i,j,k) = (  4,  1,  1)
 2/ 4: (i,j,k) = (  2,  1,  2)
 ...
 ...
 4/ 4: (i,j,k) = (  4,  5,  4)
 2/ 4: (i,j,k) = (  2,  5,  5)
 3/ 4: (i,j,k) = (  3,  5,  5)
 1/ 4: (i,j,k) = (  1,  5,  5)
 4/ 4: (i,j,k) = (  4,  5,  5)

 Count =          100
 Time in seconds =   0.00000000 

When I delete the NUM_THREADS(4) clause then the function omp_get_num_threads() returns 8 threads but only 4 seems to be used in processing:

CODE

$ armeros_p
 2/ 8: (i,j,k) = (  2,  1,  1)
 3/ 8: (i,j,k) = (  3,  1,  1)
 1/ 8: (i,j,k) = (  1,  1,  1)
 4/ 8: (i,j,k) = (  4,  1,  1)
 2/ 8: (i,j,k) = (  2,  1,  2)
 ...
 ...
 4/ 8: (i,j,k) = (  4,  5,  4)
 2/ 8: (i,j,k) = (  2,  5,  5)
 3/ 8: (i,j,k) = (  3,  5,  5)
 1/ 8: (i,j,k) = (  1,  5,  5)
 4/ 8: (i,j,k) = (  4,  5,  5)
 ... 

When I changed the outer loop up to i = 8, all 8 threads were used, so it seems that OpenMP specifies the number of threads to be used automatically.

Further, I replaced write statement in the subroutine with simple computation, removed from the code the calls of OMP-functions omp_get_num_threads() and omp_get_thread_num(). Then I tried to compare the performance for bigger loops (i=1..8; j=1..50000; k=1..50000) but I didn't notice any performance improvement in parallelized version.
But I believe that there is a performance improvement for specific big cases. My goal was only to try how to use OpenMP.

RE: Run time error

Cool.

I wonder how performance improves if, instead, you actually increase the range of the outer-most loop

CODE

!$omp parallel do NUM_THREADS(4) PRIVATE(i, j, k, thread_id, threads)do i=1, 8
do i=1, 100000
  do j = 1, 50
    do k = 1, 50
      threads = omp_get_num_threads()
      thread_id = omp_get_thread_num() + 1
      call do_something(i, j, k, thread_id, threads)
      n = n + 1
    end do
  end do
end do
!$omp end parallel do 

We may need to read up more details about the "parallel" directives, how exactly they work and how to better enhance program performance...I think things depend on where you place the directive. For example:

CODE

!$omp parallel do NUM_THREADS(4) PRIVATE(i, j, k, thread_id, threads)do i=1, 8
do i = 1, 8
  do j = 1, 50000
    do k = 1, 50000
      threads = omp_get_num_threads()
      thread_id = omp_get_thread_num() + 1
      call do_something(i, j, k, thread_id, threads)
      n = n + 1
    end do
  end do
end do
!$omp end parallel do 

versus

CODE

do i=1, 8
  do j = 1, 50000
!$omp parallel do NUM_THREADS(4) PRIVATE(i, j, k, thread_id, threads)
    do k = 1, 50000
      threads = omp_get_num_threads()
      thread_id = omp_get_thread_num() + 1
      call do_something(i, j, k, thread_id, threads)
      n = n + 1
    end do
!$omp end parallel do
  end do
end do 

Anyway, mikrom, sounds we (mostly you) are done with this thread. Thanks for all the reporting.



RE: Run time error

mikrom...two more things

The one time when I started to use OpenMP, I found that I had to limit the number of threads because if I didn't, the program would tend to use all processors and make the machine unresponsive until the program was done...so, it may be best to limit it...I think you can request the number of processors available, take away one or two and use the rest...

Lastly...how do you make the code to show up syntax-highlighted?

RE: Run time error

Hi salgerman,

I guess that to use OpenMP efficiently a profitable will require intensive study of this matter.
But as i wrote above, my goal was just to see this thing a little bit closer
I see that this discussion is beyond the topic of this thread.

Quote:


... how do you make the code to show up syntax-highlighted?

1. Before posting the source, I'm using "Convert to HTML" on the Syntax menu of my editor vim.
It creates a new file, which contains the HTML equivalent of the syntax highlighted source.

2. Then I'm running this script for converting HTML into TGML

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close