hello_image.f90 サンプルは Hello world プログラムです。通常の Hello world とは異なり、この Coarray Fortran プログラムは、ホストマシンで平行して実行される複数のイメージ、またはプロセスにスポーンします。このアプリケーションのソースコードは、次のように単純な Fortran プログラムです。
program hello_image write(*,*) "Hello from image ", this_image(), & "out of ", num_images()," total images" end program hello_image
this_image() および num_images() の関数呼び出しに注目してください。これらは、新しい Fortran 2008 組み込み関数です。num_images() 関数は、このプログラムでスポーンされたイメージまたはプロセス数の合計を返します。this_image() 関数は、1 から N の範囲の各イメージの一意の識別子を返します。N はこのプログラムで作成されるイメージの合計数です。
インテル® Visual Fortran Composer XE 2011 のインストール後、Microsoft* Visual Studio* を起動し、coarray_samples.sln ファイルを開きます。
Coarray を使用してプロジェクトをビルドするには、
[プロジェクト] > [プロパティ] > [Fortran] > [Command Line (コマンドライン)] > /Qcoarray を選択します。
次に、ソリューションをビルドして ([ビルド] > [ソリューションのビルド])、実行ファイルを開始します ([デバッグ] > [デバッグなしで開始])。出力結果は次のようになります。
Hello from image 1 out of 8 total images Hello from image 6 out of 8 total images Hello from image 7 out of 8 total images Hello from image 2 out of 8 total images Hello from image 5 out of 8 total images Hello from image 8 out of 8 total images Hello from image 3 out of 8 total images Hello from image 4 out of 8 total images
デフォルトでは、Coarray Fortran アプリケーションがインテル® Fortran コンパイラーでコンパイルされると、ホスト・プラットフォームのプロセッサー・コア数と同じ数のイメージが作成されます。上記は、デュアル・クワッドコアで合計 8 コアを搭載するホストシステムで実行された例です。各イメージは個別にスポーンされたプロセスであり、非同期に実行します。
/Qcoarray オプションは、/Qopenmp オプションとともに使用できません。Coarray Fortran 言語拡張と OpenMP* 拡張機能は混在できません。
© 2010 Intel Corporation. 無断での引用、転載を禁じます。