Note that there are some explanatory texts on larger screens.

plurals
  1. POQuestion about parallel loop in MPI
    primarykey
    data
    text
    <p>hey there, I have a short question about openmpi in fortran: i have a code like this:</p> <pre><code>I) definitions of vars &amp; linear code, setting up some vars for later usage II) a while loop which works like that in pseudocode: nr=1 while(true) { filename='result'//nr//'.bin' (nr converted to string) if(!file_exists(filename)) goto 100 // file exists... so do something with it // calculations, read/write... nr=nr+1 } 100 continue III) some more linear code... </code></pre> <p>Now I want to make this a parallel computation with openmpi. The linear code from I) and III) should only be computed once and the while-loops should be run on several processors... How to best realize it? my problem is how the while-loop works: E.g. when processor 1 computes result1.bin, how to directly tell processor 2 to compute result2.bin? and how would it work if there are 30 files and I use </p> <p>mpirun -n 10 my_program</p> <p>? how does MPI "know" that after finishing computing one file, there are more files "waiting" to be processed: as soon as one processor has ended processing one file, THIS procesor should directly start over processing the next file in the queue..</p> <p>thanks so far!</p> # <p>EDIT:</p> # <p>Hey there, it's me again... I wanted to give OpenMP a try too, so I used a chunk of your code which reads the existing files and afterwards loops them (and processes them):</p> <pre><code>nfiles = 0 do write(filename,FMT='(A,I0,A)'), prefix, nfiles+1, suffix inquire(file=trim(filename),exist=exists) if (not(exists)) exit nfiles = nfiles + 1 enddo </code></pre> <p>now I tried the following code:</p> <pre><code>call omp_set_num_threads(2) !$OMP PARALLEL !$OMP DO do i=startnum, endnum write(filename,FMT='(A,I0,A)'), prefix, i, suffix ...CODE DIRECTLY HERE TO PROCESS THE FILE... enddo !$OMP END DO !$OMP END PARALLEL </code></pre> <p>But it gives me always errors like that: "It is illegal to branch out of a DO loop associated with an Open MP DO or PARALLEL DO directive."</p> <p>Always about the codelines with this sort of code:</p> <pre><code>read (F_RESULT,*,ERR=1) variable </code></pre> <p>Where F_RESULT is a filehandle...What could be wrong about it? variable is defined outside of the loop block, and I already tried to set OpenMP directive to </p> <pre><code>private(variable) </code></pre> <p>so that each thread has his own copy, but that didn't work out! Thanks so far for your help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload