MPI 사용 시 명령어들의 실행 순서

sangjun11316의 이미지

우선 질문 대상이 되는 코드는 아래와 같은 단순한 MPI 예제입니다.
process 0 이 process 1로부터 double들로 이루어진 배열을 받는 것인데요,

----------------------------------- script --------------------------------
1 program main

2 use MPI

3 integer count
4 real*8 data(0:99), value(200)
5 integer dest, i, ierr, num_procs, rank, status(MPI_STATUS_SIZE), tag

6 call MPI_INIT ( ierr )
7 call MPI_COMM_RANK ( MPI_COMM_WORLD, rank, ierr )
8 call MPI_COMM_SIZE ( MPI_COMM_WORLD, num_procs, ierr )

9 if ( rank .eq. 0 ) then

10 print *, ' BONES: '
11 print *, ' An MPI test program.'
12 print *, ' The number of processes : ', num_procs

13 endif

14 if ( rank .eq. 0 ) then

15 tag = 55

16 call MPI_RECV ( value, 200, MPI_DOUBLE_PRECISION, MPI_ANY_SOURCE, tag, &
MPI_COMM_WORLD, status, ierr )

18 print *, ' P: ', rank, ' Got data from processor ', &
status(MPI_SOURCE)

20 call MPI_GET_COUNT ( status, MPI_DOUBLE_PRECISION, count, ierr )

21 print *, ' P: ', rank, ' value(5) = ', value(5)

22 elseif ( rank .eq. 1 ) then

23 print *, ' '
24 print *, ' P: ', rank, ' - setting up data to send to process 0.'

25 do i = 0,99
26 data(i) = real(i)
27 enddo

28 dest = 0
29 tag = 55

30 call MPI_SEND ( data, 100, MPI_DOUBLE_PRECISION, dest, tag, &
MPI_COMM_WORLD, ierr )

31 else

32 print *, ' '
33 print *, ' P: ', rank, ' - MPI has no work for me! '

34 endif

35 call MPI_FINALIZE ( ierr )

36 if ( rank .eq. 0 ) then
37 print *, ' '
38 print *, 'BONES:'
39 print *, ' Normal end of execution.'
40 print *, ' '
41 endif
42 end
-----------------------------------------------------------------------------

실행시마다 변화는 있지만 위 코드를 컴파일해서 'mpirun -np 2 exe' 와 같이 실행시켜보면 아래와 같습니다.

-------------------------------------- result -------------------------------
1 BONES:
2 An MPI test program.
3 The number of processes : 2
4 P: 0 Got data from processor 1
5 P: 0 value(5) = 4.0000000000000000

6 P: 1 - setting up data to send to process 0.

7 BONES:
8 Normal end of execution.
-----------------------------------------------------------------------------

여기서부터 질문인데요, result 의 4번과 6번 줄을 보시면 process 1이 MPI_SEND (script 30번 줄)를 하기 전에 이미 process 0에서 MPI_RECV (script 16번 줄)를 한 후에야 실행될 print문이 실행되고 있음을 알 수 있는데요,

script만 읽으면서 생각할 땐 당연히 process 0은 script 16번 줄의 MPI_RECV에서 멈춰 있는 상태에서 (왜냐하면 받을 것이 아직 없기 때문에) process 1이 script의 30번 줄에 다다라서 MPI_SEND를 통해 보낸 후에야 그 다음의 print문을 실행할 것이기 때문에

result 의 6번 줄에 나오는 'setting up data~' 가 result 4번 줄의 'Got data ~' 보다 무조건 먼저 나오게 될 것이라 생각했는데 그게 아니더군요...^^;;

왜 결과가 이런 순서로 출력되는지 감이 잡히지 않아 질문올립니다 ㅠㅠ

....의 이미지

포트란에 mpi라.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.