Fortran を使用した MPI プログラミングは初めてです。2D グラフをプロットしたい。各プロセッサにグラフの 1 つのポイントを計算させ、それをルートに送信してファイルに書き込むようにしようとしています。誰かが2つの変数を送信する方法を教えてもらえますか.viz:x
と. 助けてくれてありがとう。 f(x)
mpi_gather
質問する
730 次
1 に答える
0
Hristoが言ったことと「明示的なインターフェイスなしで未割り当ての配列をルーチンに渡すことに何か問題がありますか?」の両方の例として、これがどのように行われるかを示します。
Program gather
Use mpi
Implicit None
Integer, Dimension( :, : ), Allocatable :: result
Integer, Dimension( 1:2 ) :: buffer
Integer :: me, nprocs, error
Integer :: x, fx
Call mpi_init( error )
Call mpi_comm_rank( mpi_comm_world, me , error )
Call mpi_comm_size( mpi_comm_world, nprocs, error )
If( me == 0 ) Then
Allocate( result( 1:2, 1:nprocs ) ) !Naughty - should check stat
Else
Allocate( result( 1:0, 1:0 ) ) !Naughty - should check stat
End If
x = me
fx = x * x
buffer( 1 ) = x
buffer( 2 ) = fx
Call mpi_gather( buffer, 2, mpi_integer, &
result, 2, mpi_integer, &
0, mpi_comm_world, error )
If( me == 0 ) Then
Write( *, '( 99999( i3, 1x ) )' ) result( 1, : )
Write( *, '( 99999( i3, 1x ) )' ) result( 2, : )
End If
Call mpi_finalize( error )
End Program gather
Wot now? mpif90 gather.f90
Wot now? mpirun -np 7 ./a.out
0 1 2 3 4 5 6
0 1 4 9 16 25 36
于 2012-12-04T10:51:56.637 に答える