Difference between revisions of "Tutorials:ALPS Fortran Application Development"

From ALPS
Jump to: navigation, search
(Created page with " {{Languages|Tutorials:ALPS_Fortran_Application_Development}} ALPS FortranはALPSのFortranインターフェースモジュールです。ALPS Fortranを使用し、いくつ…")
 
 
Line 1: Line 1:
 
  {{Languages|Tutorials:ALPS_Fortran_Application_Development}}
 
  {{Languages|Tutorials:ALPS_Fortran_Application_Development}}
  
ALPS FortranはALPSのFortranインターフェースモジュールです。ALPS Fortranを使用し、いくつかの必要なサブルーチンを実装することで、容易にALPS上でFortranコードを実行することができます。
+
ALPS Fortran is the Fortran interface modules of ALPS. Using ALPS Fortran, You can run Fortran code program easily on ALPS by implementing some necessary subroutine.
本章ではALPS上で動作するFortranコードを書くための手順を説明します。また、既存のFortranコードをALPS Fortranに移植する手順やビルド設定ファイル(CMakeList.txt)の書き方についても本章で説明します。
+
This chapter describes the procedures for writing the Fortran code to run on ALPS.In addition, also described in this chapter on how to modify (CMakeList.txt) file setting procedures and build the Fortran code to be ported to the existing ALPS Fortran.
  
 +
==Introduction ALPS Fortran ==
  
==ALPS Fortranの概要 ==
+
The following figure shows the relationship diagram between ALPS system,ALPS Fortran,and user fortran program.
  
ALPS本体、ALPS Fortran及びFortranで記述されたユーザーアプリケーションの関係を以下に示します。
 
  
 +
[[File:fig1.png|500px|ALPS Fortranのmodule構成]]
  
[[File:fig1.png|500px|ALPS Fortranのモジュール構成]]
 
  
 +
ALPS Fortran is called from the ALPS, call the Subroutine of the user program as necessary.Thus, ALPS can control the Program has been implemented in Fortran as well as the C++ Program.On the other hand, ALPS Fortran has provided a Subroutine call the functions of ALPS.Therefore, user program will be able to use the ALPS functions as well as to call the normal Fortran Subroutine.
  
ALPS FortranはALPS本体からの呼び出しを受け、必要に応じてユーザーアプリケーションのサブルーチンをコールします。これにより、ALPSはC++で実装されたアプリケーションと同様にFortranで実装されたアプリケーションを制御できます。
+
==call flows subroutine ==
一方で、ALPS FortranはALPS本体の機能を呼び出すサブルーチンを提供しており、ユーザーアプリケーションは通常のFortranサブルーチンを呼び出すのと同様にALPSの機能を利用することができます。
 
 
 
==サブルーチン呼び出しの流れ ==
 
 
 
ALPS Fortranを使用した時のALPS / ユーザーアプリケーションの呼び出しの流れは以下のようになります。下図中の各サブルーチンについては[2.3.3]をご参照ください。
 
  
 +
The following figure shows the flow chart of the ALPS system and user program. Subroutines for each of the below, refer to the [2.3.3].
  
 
[[File:fig2.png|500px|呼び出し流れ図]]
 
[[File:fig2.png|500px|呼び出し流れ図]]
  
 +
==Preparation fortran source code  ==
  
 
+
To implement the Program using ALPS Fortran, you will need to prepare following two source code.
==Fortran コードの書き方  ==
+
* C++ source code for implementing main function(entory point of Program).
 
+
* Fortran source code for implementing according to a rule of the ALPS Fortran.
ALPS Fortranを利用したアプリケーションを実装するには、最低限、下記2つのソースコードを準備する必要があります。
 
* アプリケーションのエントリポイント(main関数)が実装されたC++ソースコード
 
* ALPS Fortranのルールに従って実装されたFortranソースコード
 
  
  
===エントリポイント ===
+
===Entry Point ===
  
 ここではmain関数(アプリケーションのエントリポイント)、ワーカー名等のアプリケーション設定を記述します。main関数は決まった内容を記述するだけであり、通常は変更の必要はありません。<br/>
+
This section describes the setting Program function main, such as main function(entry point of the Program) and the worker name.Main function is only to describe the fixed contents, usually does not need to be changed.Settings with Program, please refer to the following code,
 アプリケーションの設定ついては以下の設定用コードを記述します。
 
  
*アプリケーションのバージョン番号
+
*Program version numbers
*アプリケーションのコピーライト
+
*Program copyright
*ワーカー名
+
*Worker name
*エバリュエータ名
+
*Evaluator name
  
以下に、C++ソースコードの例を示します。
+
The following is an example of a C + + source code.
  
 
  1: #include <alps/parapack/parapack.h>
 
  1: #include <alps/parapack/parapack.h>
 
  2: #include "fortran_wrapper.h"
 
  2: #include "fortran_wrapper.h"
 
  3:
 
  3:
  4: // バージョンの設定
+
  4: // Version number setting
 
  5: PARAPACK_SET_VERSION("<span style="color:red">my version</span>");
 
  5: PARAPACK_SET_VERSION("<span style="color:red">my version</span>");
 
  6:
 
  6:
  7: // コピーライト表示の設定
+
  7: // Copywrite display setting
 
  8: PARAPACK_SET_COPYRIGHT("<span style="color:red">my copyright</span>");
 
  8: PARAPACK_SET_COPYRIGHT("<span style="color:red">my copyright</span>");
 
  9:
 
  9:
  10: // ワーカー名の設定
+
  10: // Worker name setting
 
  11: PARAPACK_REGISTER_WORKER(alps::fortran_wrapper, "worker name</span>");
 
  11: PARAPACK_REGISTER_WORKER(alps::fortran_wrapper, "worker name</span>");
 
  12:
 
  12:
  13: // エバリュエータの設定
+
  13: // Evaluator setting
  14: PARAPACK_REGISTER_EVALUATOR(alps::parapack::simple_evaluator,
+
  14: PARAPACK_REGISTER_EVALUATOR(alps::parapack::simple_evaluator,"<span style="color:red">evaluator name</span>");
15:                                                 "<span style="color:red">evaluator name</span>");
+
15:
 
  16:
 
  16:
 
  17: /**
 
  17: /**
  18: * アプリケーションのエントリポイント
+
  18: * Programのentry point
 
  19: */
 
  19: */
 
  20: int main(int argc, char** argv)
 
  20: int main(int argc, char** argv)
Line 68: Line 62:
 
  23: }
 
  23: }
  
上記例の内、変更が必要なのは赤字の部分になります。
+
In the above example, it needs to be changed will be the red part characters.
  
===Fortranソースコード===
+
===Fortran source code===
Fortranソースコードの内容は計算ロジックが主になります。ただし、ALPS Fortranを使用するためにいくつかのサブルーチンを必ず実装する必要があります。
+
The main contents of the Fortran source code is the calculation logic.However, there is always a need to implement some Subroutine to use the ALPS Fortran.You call the ALPS function via the Subroutine provided by the ALPS Fortran when performing the loading of the parameters and saving the calculation results.
また、計算結果の保存やパラメータの読み込み等を行う際はALPS Fortranが提供するサブルーチンを経由してALPS本体の機能を呼び出します。
 
  
====必須サブルーチン ====
+
====required Subroutine ====
ユーザーアプリケーションがALPSからの制御を受けるためには、Fortranソースコード内にいくつかのサブルーチンが必要になります。後述する各サブルーチンの説明をご一読の上、適切な実装を行ってください。これらを省略するとリンクエラーとなり、ビルドできません。
+
for the user program to control the function of ALPS, you will need some Subroutine in the Fortran source code.read on below for a description of each Subroutine,Implement appropriately,and is a link error if you omit them, you can not build.
これらのサブルーチンを実装する際は、以下の点に留意して実装してください。
+
when implementing these Subroutine, keep in mind the following points:
  
*全てのサブルーチンは引数として「integer(2) :: caller」が渡されます。callerはALPS本体の機能を利用するために内部で利用される変数です。したがって、callerの値を書き換えないでください。callerの値が変更された場合の動作は未保証になります。
+
*All Subroutine will be passed "(2) :: caller integer" as argument.caller is a variable that is used internally to take ALPS function.Therefore, please do not rewrite the value of the caller. If the value of caller behavior has been changed is not guaranteed.
  
 
+
*include the "alps / fortran / alps_fortran.h" In each Subroutine. This file will be required when calling the ALPS functions from Fortran code.<br/>
*各サブルーチンでは「alps/fortran/alps_fortran.h」をインクルードしてください。このファイルはFortranコードからALPS本体の機能を呼び出す際に必須になります。<br/>
+
So, with regard to the Subroutine required, you will need the following three lines immediately below the signature of the Subroutine.
したがって、必須サブルーチンにつきましては、サブルーチンのシグネチャ直下に以下の3行が必要になります。
 
  
 
  1: subroutine alps_init(caller)
 
  1: subroutine alps_init(caller)
Line 89: Line 81:
 
  4: integer :: caller(2)
 
  4: integer :: caller(2)
 
  5:
 
  5:
  6: ! --- 以下、略 --- !
+
  6: ! --- snip --- !
  
  
 
'''alps_init(caller)'''
 
'''alps_init(caller)'''
*引数
+
*Argument
 
{| border="1" cellpadding="5" cellspacing="0"
 
{| border="1" cellpadding="5" cellspacing="0"
  
|| ''''''
+
|| '''Type'''
|| '''名前'''
+
|| '''Name'''
 
|| '''I/O'''
 
|| '''I/O'''
|| '''説明'''
+
|| '''Meaning'''
 
|-
 
|-
 
|| integer
 
|| integer
 
|| caller(2)
 
|| caller(2)
 
|| in
 
|| in
||内部変数
+
|| local variable
 
|}
 
|}
  
*説明
+
*Explanation
本サブルーチンは計算が行われる前に一度だけコールされます。ここでは、配列の確保等、アプリケーションの初期化処理を行います。
+
This Subroutine will be called once before the calculation is performed.This is where the initialization process of the Program like as allocating arrays.
本サブルーチンは入力パラメータ1セットにつき、1回のみコールされます。
 
  
  
 
'''alps_init_observables(caller)'''
 
'''alps_init_observables(caller)'''
*引数
+
*Argument
 
{| border="1" cellpadding="5" cellspacing="0"
 
{| border="1" cellpadding="5" cellspacing="0"
  
|| ''''''
+
|| '''Type'''
|| '''名前'''
+
|| '''Name'''
 
|| '''I/O'''
 
|| '''I/O'''
|| '''説明'''
+
|| '''Meaning'''
 
|-
 
|-
 
|| integer
 
|| integer
 
|| caller(2)
 
|| caller(2)
 
|| in
 
|| in
||内部変数
+
|| local variable
 
|}
 
|}
  
*説明
+
*Explanation
本サブルーチンはalps_initがコールされた後に1度だけコールされます。ここでは、alps::ObservableSetの初期化を行います。本サブルーチンは入力パラメータ1セットにつき、1回のみ呼び出されます。
 
なお、alps::ObservableSetの詳細につきましては、ALPSのHPをご参照ください。
 
  
 +
This Subroutine will be called only once after it has been a call is alps_init. This is where you initialize the alps :: ObservableSet.This Subroutine is called once in one input parameter.Incidentally, detail information of the alps :: ObservableSet, refer to the ALPS HP.
  
 
'''alps_run(caller)'''
 
'''alps_run(caller)'''
*引数
+
*Argument
 
{| border="1" cellpadding="5" cellspacing="0"
 
{| border="1" cellpadding="5" cellspacing="0"
  
|| ''''''
+
|| '''Type'''
|| '''名前'''
+
|| '''Name'''
 
|| '''I/O'''
 
|| '''I/O'''
|| '''説明'''
+
|| '''Meaning'''
 
|-
 
|-
 
|| integer
 
|| integer
 
|| caller(2)
 
|| caller(2)
 
|| in
 
|| in
||内部変数
+
|| local variable
 
|}
 
|}
  
*説明
+
*Explanation
計算ロジックを実装します。本サブルーチンは後述するalps_progressが1.0以上を返すまで、ALPSから繰り返し呼び出されます。したがって、本サブルーチン内ではループを記述する必要はありません。
+
This subroutine is implemented the logic calculation.until it returns a value greater than or equal to 1.0 by alps_progress,This Subroutine is called repeatedly from ALPS.Therefore, in this Subroutine is necessary to take the loop structure is not available.
なお、スレッド並列実行時には、本サブルーチンはマルチスレッド下で動作します。そのため、スレッド並列で利用する際にはスレッドセーフな実装を行う必要があります。
+
In addition,while running at thread-level-parallelism,this subroutine work on multi-threading.Therefore, when used in thread-level-parallelism is required to provide thread-safe implementation
 
 
  
 
'''alps_progress(prgrs, caller)'''
 
'''alps_progress(prgrs, caller)'''
*引数
+
*Argument
 
{| border="1" cellpadding="5" cellspacing="0"
 
{| border="1" cellpadding="5" cellspacing="0"
  
|| ''''''
+
|| '''Type'''
|| '''名前'''
+
|| '''Name'''
 
|| '''I/O'''
 
|| '''I/O'''
|| '''説明'''
+
|| '''Meaning'''
 
|-
 
|-
 
|| real*8
 
|| real*8
 
|| prgrs
 
|| prgrs
 
|| out
 
|| out
||アプリケーションの進捗状態(0.0 ≦ prgrs)
+
||Programの進捗状態(0.0 ≦ prgrs)
 
|-
 
|-
 
|| integer
 
|| integer
 
|| caller(2)
 
|| caller(2)
 
|| in
 
|| in
||内部変数
+
|| local variable
 
|}
 
|}
  
*説明
+
*Explanation
本サブルーチンはalps_runが実行された後にALPSからコールされ、アプリケーションの進捗状態をALPSに返します。prgrsが1.0未満の間、ALPSは繰り返しalps_runをコールします。prgrsに1.0以上の値を代入すると、ALPSは計算が完了したとみなし、アプリケーションを終了します。
 
なお、スレッド並列実行時には、本サブルーチンはマルチスレッド下で動作します。そのため、スレッド並列で利用する際にはスレッドセーフな実装を行う必要があります。
 
  
 +
This Subroutine will be called by the ALPS has been finished after alps_run, ALPS is returned to the progress situation of the Program.While the prgrs value less than 1.0, ALPS will call repeatedly alps_run. When prgrs value more than 1.0 are substituted, ALPS judges that a calculation was completed, and will finish the program.In addition,while running at thread-level-parallelism,this subroutine work on multi-threading.Therefore, when used in thread-level-parallelism is required to provide thread-safe implementation
  
 
'''alps_is_thermalized(thrmlz, caller)'''
 
'''alps_is_thermalized(thrmlz, caller)'''
*引数
+
*Argument
 
{| border="1" cellpadding="5" cellspacing="0"
 
{| border="1" cellpadding="5" cellspacing="0"
  
|| ''''''
+
|| '''Type'''
|| '''名前'''
+
|| '''Name'''
 
|| '''I/O'''
 
|| '''I/O'''
|| '''説明'''
+
|| '''Meaning'''
 
|-
 
|-
 
|| real*8
 
|| real*8
 
|| thrmlz
 
|| thrmlz
 
|| out
 
|| out
||サーマライズ終了フラグ(0:/ 1:)
+
||thermalize ending flag(0:Not Completed / 1:Completed )
 
|-
 
|-
 
|| integer
 
|| integer
 
|| caller(2)
 
|| caller(2)
 
|| in
 
|| in
||内部変数
+
|| local variable
 
|}
 
|}
  
*説明
+
*Explanation
本サブルーチンはalps_runが実行された後にALPSからコールされ、サーマライズの完了/未完了を返します。thrmlzの値が0の場合、アプリケーションがサーマライズ中であるとみなし、計算結果を保存しません。thrmlzが1になるとサーマライズが完了したとみなし、計算結果の保存が開始されます。
+
This Subroutine will be called by the ALPS has been finished after alps_run, returns the incomplete / complete thermalize.When a value of thrmlz is 0, Program judges the calculation is now in thermalize, and does not save a calculation result data.On the other hand,value is 1, Program judges that thermalize was completed, and the calculation result saving is started.
なお、スレッド並列実行時には、本サブルーチンはマルチスレッド下で動作します。そのため、スレッド並列で利用する際にはスレッドセーフな実装を行う必要があります。
+
In addition,while running at thread-level-parallelism,this subroutine work on multi-threading.Therefore, when used in thread-level-parallelism is required to provide thread-safe implementation
 
 
  
 
'''alps_finalize(caller)'''
 
'''alps_finalize(caller)'''
*引数
+
*Argument
 
{| border="1" cellpadding="5" cellspacing="0"
 
{| border="1" cellpadding="5" cellspacing="0"
  
|| ''''''
+
|| '''Type'''
|| '''名前'''
+
|| '''Name'''
 
|| '''I/O'''
 
|| '''I/O'''
|| '''説明'''
+
|| '''Meaning'''
 
|-
 
|-
 
|| integer
 
|| integer
 
|| caller(2)
 
|| caller(2)
 
|| in
 
|| in
||内部変数
+
|| local variable
 
|}
 
|}
  
*説明
+
*Explanation
本サブルーチンは計算が完了した後(alps_progressが1.0以上を返した後)に1度だけコールされます。ここでは、alps_initで確保したメモリの解放等の終了処理を行います。
+
This Subroutine will be called only once (after returning the value greater than or equal to 1.0 from alps_progress) after completing your calculation. This is where you end processing such as the release of allocated memory.
 
 
  
 
'''alps_save(caller)'''
 
'''alps_save(caller)'''
*引数
+
*Argument
 
{| border="1" cellpadding="5" cellspacing="0"
 
{| border="1" cellpadding="5" cellspacing="0"
  
|| ''''''
+
|| '''Type'''
|| '''名前'''
+
|| '''Name'''
 
|| '''I/O'''
 
|| '''I/O'''
|| '''説明'''
+
|| '''Meaning'''
 
|-
 
|-
 
|| integer
 
|| integer
 
|| caller(2)
 
|| caller(2)
 
|| in
 
|| in
||内部変数
+
|| local variable
 
|}
 
|}
  
*説明
+
*Explanation
alps_runが実行された後にALPSからコールされます。ここではALPS本体の機能を利用してリスタートファイルの保存を行います。スレッド並列実行時には、本サブルーチンはマルチスレッド下で動作するため、スレッド並列で利用する際にはスレッドセーフな実装を行う必要があります。
+
This subroutine is called from ALPS has been finished after alps_run. Saves the restartrestart-file using the function of ALPS.In addition,while running at thread-level-parallelism,this subroutine work on multi-threading.Therefore, when used in thread-level-parallelism is required to provide thread-safe implementation.
  
  
 
'''alps_load(caller)'''
 
'''alps_load(caller)'''
*引数
+
*Argument
 
{| border="1" cellpadding="5" cellspacing="0"
 
{| border="1" cellpadding="5" cellspacing="0"
  
|| ''''''
+
|| '''Type'''
|| '''名前'''
+
|| '''Name'''
 
|| '''I/O'''
 
|| '''I/O'''
|| '''説明'''
+
|| '''Meaning'''
 
|-
 
|-
 
|| integer
 
|| integer
 
|| caller(2)
 
|| caller(2)
 
|| in
 
|| in
||内部変数
+
|| local variable
 
|}
 
|}
  
*説明
+
*Explanation
本サブルーチンはアプリケーションがリスタートされたときに1度だけコールされます。ここでは、ALPS本体の機能を利用して、保存されたリスタートファイルをロードします。
+
This Subroutine will be called once, when the Program is restart. Load the saved restart-file using the ALPS functions.
 
 
 
 
====ALPS Fortran提供サブルーチン ====
 
ユーザーアプリケーションからALPSの機能を呼び出す際は、ALPS Fortranが提供するサブルーチンをコールします。
 
これらのサブルーチンは引数として「integer(2) :: caller」が必要になります。callerはALPS Fortranから渡される内部変数であり、必須サブルーチン(2.2.3.1)に引数で渡された変数をそのまま提供サブルーチンに渡す必要があります。
 
  
 +
====Subroutine provided ALPS Fortran====
 +
When you call the ALPS functions from the user program, call the Subroutine provided by the ALPS Fortran.
 +
These subroutine will require "(2) :: caller integer" as argument.
 +
caller is a local variable that is passed from the ALPS Fortran, you will need to pass the Subroutine provided as a variable passed in the argument to (2.2.3.1) Subroutine required.
  
 
'''alps_get_parameter(data, name, type, caller)'''
 
'''alps_get_parameter(data, name, type, caller)'''
*引数
+
*Argument
 
{| border="1" cellpadding="5" cellspacing="0"
 
{| border="1" cellpadding="5" cellspacing="0"
  
|| ''''''
+
|| '''Type'''
|| '''名前'''
+
|| '''Name'''
 
|| '''I/O'''
 
|| '''I/O'''
|| '''説明'''
+
|| '''Meaning'''
 
|-
 
|-
 
||  -
 
||  -
 
|| data
 
|| data
 
|| out
 
|| out
||取り出した値の格納先
+
||store of the value
 
|-
 
|-
 
|| character
 
|| character
 
|| name(*)
 
|| name(*)
 
|| in
 
|| in
||取り出したいパラメータの名前
+
||parameter name to take out
 
|-
 
|-
 
|| integer
 
|| integer
 
|| type
 
|| type
 
|| in
 
|| in
||dataの型
+
||data type
 
|-
 
|-
 
|| integer
 
|| integer
 
|| caller(2)
 
|| caller(2)
 
|| in
 
|| in
||内部変数
+
|| local variable
 
|}
 
|}
  
*説明
+
*Explanation
名前を指定して、ALPSからパラメータを受け取ります。パラメータの名前、型、要素数はそれぞれname、type、countで指定します。
+
Specify the name, ane receive a parameter from ALPS. parameter name, type, number of elements is specified '''name''', '''type''', in each count.This Subroutine will be used to initialize the arrays and variables in the mainly alps_init. In addition, the possible value of the type is defined in the alps_fortran.h.
本サブルーチンは主にalps_init内で配列や変数の初期化に利用されます。なお、typeが取りうる値はalps_fortran.hに定義されています。
 
  
  
 
'''alps_parameter_defined(res, name, caller)'''
 
'''alps_parameter_defined(res, name, caller)'''
*引数
+
*Argument
 
{| border="1" cellpadding="5" cellspacing="0"
 
{| border="1" cellpadding="5" cellspacing="0"
  
|| ''''''
+
|| '''Type'''
|| '''名前'''
+
|| '''Name'''
 
|| '''I/O'''
 
|| '''I/O'''
|| '''説明'''
+
|| '''Meaning'''
 
|-
 
|-
 
|| integer
 
|| integer
 
|| res
 
|| res
 
|| out
 
|| out
||パラメータ定義の有無(1:/ 0:)
+
||The presence or absence of definition of parameter(1:absence / 0:definition)
 
|-
 
|-
 
|| character
 
|| character
 
|| name(*)
 
|| name(*)
 
|| in
 
|| in
||パラメータの名前
+
||parameter name
 
|-
 
|-
 
|| integer
 
|| integer
 
|| caller(2)
 
|| caller(2)
 
|| in
 
|| in
||内部変数
+
|| local variable
 
|}
 
|}
  
*説明
+
*Explanation
nameで指定したパラメータがパラメータファイルに定義されているかどうかを返します。パラメータが定義されていればresに1が代入されます。定義されていなければ0が代入されます。
 
本サブルーチンは主にalps_init内で配列や変数の初期化に利用されます。
 
  
 +
Returns whether the parameter is defined in the parameter file is specified by '''name'''. '''1'''''Italic text'' is assigned to the res if it is defined. '''0'''''Italic text'' is assigned if it is not.This Subroutine will be used to initialize the arrays and variables in the mainly alps_init.
  
 
'''alps_init_observable(count, type, name, caller)'''
 
'''alps_init_observable(count, type, name, caller)'''
*引数
+
*Argument
 
{| border="1" cellpadding="5" cellspacing="0"
 
{| border="1" cellpadding="5" cellspacing="0"
  
|| ''''''
+
|| '''Type'''
|| '''名前'''
+
|| '''Name'''
 
|| '''I/O'''
 
|| '''I/O'''
|| '''説明'''
+
|| '''Meaning'''
 
|-
 
|-
 
|| integer
 
|| integer
 
|| count
 
|| count
 
|| in
 
|| in
||保存される計算結果の要素数
+
||Number of element of a stored calculation result
 
|-
 
|-
 
|| integer
 
|| integer
 
|| type
 
|| type
 
|| in
 
|| in
||dataの型
+
||data type
 
|-
 
|-
 
|| character
 
|| character
 
|| name(*)
 
|| name(*)
 
|| in
 
|| in
||保存したい計算結果(Observable)の名前
+
||The name of Observable to store
 
|-
 
|-
 
|| integer
 
|| integer
 
|| caller(2)
 
|| caller(2)
 
|| in
 
|| in
||内部変数
+
|| local variable
 
|}
 
|}
  
*説明
+
*Explanation
本サブルーチンは、alps_init_observable内でalps::ObservableSetにnameで指定されたObservableを登録するために使用します。
+
This Subroutine is used to register a name that is specified in the Observable to alps :: ObservableSet in alps_init_observable.
Observableの種類はcount及びtypeによって以下のように決定されます。
+
Observable types are determined as follows by '''type''' and '''count'''.
  
 
{| border="1" cellpadding="5" cellspacing="0"
 
{| border="1" cellpadding="5" cellspacing="0"
Line 396: Line 379:
  
 
'''alps_accumulate_observable(data, count, type, name, caller)'''
 
'''alps_accumulate_observable(data, count, type, name, caller)'''
*引数
+
*Argument
 
{| border="1" cellpadding="5" cellspacing="0"
 
{| border="1" cellpadding="5" cellspacing="0"
  
|| ''''''
+
|| '''Type'''
|| '''名前'''
+
|| '''Name'''
 
|| '''I/O'''
 
|| '''I/O'''
|| '''説明'''
+
|| '''Meaning'''
 
|-
 
|-
 
||  -
 
||  -
 
|| data
 
|| data
 
|| in
 
|| in
||保存される計算結果
+
||the calculation results to store
 
|-
 
|-
 
|| integer
 
|| integer
 
|| count
 
|| count
 
|| in
 
|| in
||保存される計算結果の要素数
+
||Number of element of a stored calculation result
 
|-
 
|-
 
|| integer
 
|| integer
 
|| type
 
|| type
 
|| in
 
|| in
||dataの型
+
||data type
 
|-
 
|-
 
|| character
 
|| character
 
|| name(*)
 
|| name(*)
 
|| in
 
|| in
||保存したい計算結果の名前
+
||The name of Observable to store
 
|-
 
|-
 
|| integer
 
|| integer
 
|| caller(2)
 
|| caller(2)
 
|| in
 
|| in
||内部変数
+
|| local variable
 
|}
 
|}
  
*説明
+
*Explanation
指定された名前のObservableにdata(= 計算結果)を保存します。本サブルーチンはalps_run内で計算結果を保存するために使用します。
+
Save the result data to Observable with the specified name. This Subroutine is used to store the results of a calculation in alps_run. count / name / type must match the ones specified in init_observable.
count / name / type はinit_observableで指定したものと一致している必要があります。
 
  
  
 
'''alps_dump(data, count, type, caller)'''
 
'''alps_dump(data, count, type, caller)'''
*引数
+
*Argument
 
{| border="1" cellpadding="5" cellspacing="0"
 
{| border="1" cellpadding="5" cellspacing="0"
  
|| ''''''
+
|| '''Type'''
|| '''名前'''
+
|| '''Name'''
 
|| '''I/O'''
 
|| '''I/O'''
|| '''説明'''
+
|| '''Meaning'''
 
|-
 
|-
 
|| -
 
|| -
 
|| data
 
|| data
 
|| in
 
|| in
||保存する値
+
||the values to store
 
|-
 
|-
 
|| integer
 
|| integer
 
|| count
 
|| count
 
|| in
 
|| in
||保存する値の要素数
+
||Number of elements of values to store
 
|-
 
|-
 
|| integer
 
|| integer
 
|| type
 
|| type
 
|| in
 
|| in
||dataの型
+
||data type
 
|-
 
|-
 
|| integer
 
|| integer
 
|| call(2)
 
|| call(2)
 
|| in
 
|| in
||内部変数
+
|| local variable
 
|}
 
|}
  
*説明
+
*Explanation
本サブルーチンは、alps_save内でリスタートファイルを保存するために使用します。alps_dumpを使用して保存した中断データはリスタート時に使用されます。
+
This Subroutine is used to save the restart-file in the alps_save. interruption data was saved using alps_dump will be used at restart.
  
  
 
'''alps_restore(data, count, type, caller)'''
 
'''alps_restore(data, count, type, caller)'''
*引数
+
*Argument
 
{| border="1" cellpadding="5" cellspacing="0"
 
{| border="1" cellpadding="5" cellspacing="0"
  
|| ''''''
+
|| '''Type'''
|| '''名前'''
+
|| '''Name'''
 
|| '''I/O'''
 
|| '''I/O'''
|| '''説明'''
+
|| '''Meaning'''
 
|-
 
|-
 
||  -
 
||  -
 
|| data
 
|| data
 
|| out
 
|| out
||ロードした値の格納先
+
||storage location of loaded values
 
|-
 
|-
 
|| integer
 
|| integer
 
|| count
 
|| count
 
|| in
 
|| in
||ロードする値の要素数
+
||Number of element of value to load
 
|-
 
|-
 
|| integer
 
|| integer
 
|| type
 
|| type
 
|| in
 
|| in
||dataの型
+
||data type
 
|-
 
|-
 
|| integer
 
|| integer
 
|| caller(2)
 
|| caller(2)
 
|| in
 
|| in
||内部変数
+
|| local variable
 
|}
 
|}
  
*説明
+
*Explanation
本サブルーチンは、alps_load内でリスタートファイルをロードするために使用します。リスタートファイル内にはalps_dumpで保存した順にデータが保存されます。したがって、alps_restoreでロードする際は保存時と同じ順番でデータを取り出してください。
+
This Subroutine is used to load the restart-file in the alps_load.to restart-file data is saved in the order in which they were saved in alps_dump.Therefore, when loading is alps_restore, remove the data in the same order as when it is saved.
 
 
 
 
  
===ビルド設定ファイルの書き方===
+
===editing configuration file ===
ユーザーアプリケーションはALPS同様、CMakeを使ってビルドします。以下はユーザーアプリケーションをCMakeでビルドするための設定ファイル(CMakeLists.txt)のサンプルです。
+
user program builds using CMake as well as ALPS. It is a sample of setting file(CMakeLists.txt) to build user program in CMake as follows.
  
 
  1: # CMakeList.txt
 
  1: # CMakeList.txt
  2: # CMakeを実行するための設定ファイル
+
  2: # editing configuration file for CMake
 
  3:
 
  3:
 
  4: cmake_minimum_required(VERSION 2.8.0 FATAL_ERROR)
 
  4: cmake_minimum_required(VERSION 2.8.0 FATAL_ERROR)
 
  5:
 
  5:
  6: #プロジェクト名の設定
+
  6: #Project name setting
 
  7: project(<span style="color:red">hello_sample</span>)
 
  7: project(<span style="color:red">hello_sample</span>)
 
  8:
 
  8:
  9: # find ALPS Fortran の設定
+
  9: # find ALPS Fortran setting
 
  10: find_package(ALPS REQUIRED NO_SYSTEM_ENVIRONMENT_PATH)
 
  10: find_package(ALPS REQUIRED NO_SYSTEM_ENVIRONMENT_PATH)
 
  11: message(STATUS "ALPS version: ${ALPS_VERSION}")
 
  11: message(STATUS "ALPS version: ${ALPS_VERSION}")
 
  12: include(${ALPS_USE_FILE})
 
  12: include(${ALPS_USE_FILE})
 
  13:
 
  13:
  14: # 作成する実行ファイル名と必要なソースコード
+
  14: # Source code required to create and run file name
 
  15: add_executable(<span style="color:red">hello main.C hello_impl.f</span>)
 
  15: add_executable(<span style="color:red">hello main.C hello_impl.f</span>)
  16: # 実行ファイル生成に必要な外部ライブラリ
+
  16: # External library file required to generate execution
 
  17: target_link_libraries(<span style="color:red">hello </span>${ALPS_LIBRARIES} ${ALPS_FORTRAN_LIBRARIES})
 
  17: target_link_libraries(<span style="color:red">hello </span>${ALPS_LIBRARIES} ${ALPS_FORTRAN_LIBRARIES})
  
上記例のうち、変更が必要なのは赤字の部分になります。
+
In the above example, it needs to be changed will be the red part characters.
 
 
 
 
==既存コードの移植  ==
 
本節では、以下に示すisingプログラムを例に、既存のFortranアプリケーションをALPS上で動作させるための手順について説明します。
 
  
 +
==Porting of existing program code  ==
 +
In this section, in case of the ising model program shown below,Describes the procedure that ALPS to work on the existing Fortran Program.
  
===移植の準備 ===
 
本節ではalps_fortran.tar.gzを解凍して生成されるtutorialフォルダ内のファイルを使用します。移植作業の準備として、tutorialフォルダ内の以下のファイルを作業ディレクトリにコピーしてください。
 
  
*ising_original.f:移植元のソースコード
+
===preparation porting ===
*template.f90:ALPS Fortranアプリケーションのソースコードテンプレート
+
In this section, we will use the file in the tutorial directory that is generated by extracting the alps_fortran.tar.gz.In preparation for the porting work, copy the following file to a working directory in the tutorial directory.
*main.C:アプリケーションのエントリポイント
 
*CMakeList.txt:CMakeList.txtのテンプレート
 
  
 +
*ising_original.f:original source code
 +
*template.f90:Template source cod of ALPS Fortran Program
 +
*main.C:entry point of Program
 +
*CMakeList.txt:Template of CMakeList.txt
  
template.f90にはFortranでALPSアプリケーションを実装する際に必要となる全てのサブルーチンが定義されています。そのため、新規アプリケーションを開発する際はtemplate.f90を元に開発進めることができます。
 
  
 +
All Subroutine which are necessary implementing ALPSProgram in template.f90 is defined.Therefore, when developing a new Program you can proceed with the development based on template.f90.
  
なお、移植元コードの大まかな構造は以下の通りです。
+
The rough structure of original code is as follows.
  
 
{| border="1" cellpadding="5" cellspacing="0"
 
{| border="1" cellpadding="5" cellspacing="0"
  
 
|| ''' '''
 
|| ''' '''
|| '''処理内容'''
+
|| '''Processing contents'''
 
|-
 
|-
 
||4-7
 
||4-7
|| 変数の宣言、初期化
+
|| Variable Declaration & Initialization
 
|-
 
|-
 
||8-23
 
||8-23
|| 配列要素の初期化
+
|| Array element Initialization
 
|-
 
|-
 
||24-47
 
||24-47
||メインループ
+
||main loop
 
|-
 
|-
 
||25-34
 
||25-34
||計算
+
||calculation
 
|-
 
|-
 
|| 36
 
|| 36
||サーマライズチェック
+
||thermalize check
 
|-
 
|-
 
||37-46
 
||37-46
||計算結果の保存
+
||saving calculation resutls
 
|-
 
|-
 
||48-58
 
||48-58
||結果の出力
+
||results output
 
|}
 
|}
  
 +
===porting fortran code===
 +
The porting of Fortran code, we will assign to Subroutine, the processing being done in each block of ising_original.f. This section describes an example of tutorial/alps_ising.f90 as a sample of after-porting code.
  
===Fortranコードの移植===
+
====Variable declaration====
Fortranコードの移植では、ising_original.fの各ブロックで行われている処理を、サブルーチンに割り当てていきます。本節では、移植後のサンプルとしてtutorial/alps_ising.f90を例に説明します。
 
  
====変数の宣言====
+
Each variable has been declared in the ising_original.f is at the porting is turned into ALPS module.In order to porting to ALPS because there is a need to Subroutine for each processing unit, and modify it to allow access to the variables from each Subroutine.
ising_original.f内で宣言されている各変数はALPS移植時にはmodule化します。ALPSに移植するためには処理単位ごとにサブルーチン化する必要があるため、各サブルーチンから変数にアクセスできるようにするためです。
 
  
*移植元
+
*before porting
 
  4:          DIMENSION IS(20,20),IP(20),IM(20),P(-4:4),A(4)
 
  4:          DIMENSION IS(20,20),IP(20),IM(20),P(-4:4),A(4)
 
  5:    C PARAMETERS
 
  5:    C PARAMETERS
Line 586: Line 564:
 
  7:          DATA IX/1234567/, V0/.465661288D-9/
 
  7:          DATA IX/1234567/, V0/.465661288D-9/
  
*移植後
+
*after porting
 
  1:    module ising_mod
 
  1:    module ising_mod
 
  2:      implicit none
 
  2:      implicit none
Line 599: Line 577:
 
  11:
 
  11:
  
配列IP、IM、IS、Pはalps_init内で初期化するため、ここでは移植後はサイズ指定しません。また、移植元コードの配列Aは結果保存用の配列ですが、移植後はALPSの仕組みを利用します。したがって移植後のコードに配列Aは必要ありません。また、移植後の各変数の値は、パラメータファイルから取得します。
+
IP, IM, IS, P array are initialized in alps_init, the size of the after transplantation does not specify here.In addition, original array A is for storing a result, this array is in the after-porting will use the mechanism of ALPS.Therefore, array A is not necessary for code after the porting.Also, the value of each variable after porting gotten from the parameter file.In addition, '''K''' is a variable variable after the porting to count the number of iterations.
なお、移植後の変数Kは繰り返し回数をカウントするための変数です。移植後はdoループを使わずにKの値で繰り返し制御やサーマライズチェックを行います。<br/>
+
Thermalize check after porting is responsible for control and repeat with the value of K to do without a loop.<br/>
'''※本節ではMPI並列での実行を想定しているので、スレッドセーフについては考慮していません。'''
+
'''※In this section, so that is expected to run in parallel MPI, for thread-safe is not considered.'''
 
 
  
====初期化処理====
+
====Initializing process====
移植元コードの初期化処理は配列の各要素を初期化していますが、移植後コードでは初期化処理をalps_initサブルーチンで実行します。
+
<!--移植元 codeの初期化処理は配列の各要素を初期化していますが、移植後 codeでは初期化処理をalps_initSubroutineで実行します。
最初にalps_get_parameterを使用して変数・配列の初期化を行い、その後配列要素の初期化を行います。また、移植後は結果保存用の配列を用意せず、alps_init_observableサブルーチン内で結果保存用のObservableを用意します。
+
最初にalps_get_parameterを使用して変数・配列の初期化を行い、その後配列要素の初期化を行います。また、移植後は結果保存用の配列を用意せず、alps_init_observableSubroutine内で結果保存用のObservableを用意します。
なお、alps_init及びalps_init_observableはALPSから自動的にコールされるので移植後コード内でコールする必要はありません。
+
なお、alps_init及びalps_init_observableはALPSから自動的にコールされるので移植後 code内でコールする必要はありません。-->
 +
Initialization process of the original code may have to initialize each element of the array, at after-porting code, run in the initialization process is Subroutine alps_init.First,Initializes the array variables, using the alps_get_parameter, then initialize the array elements.Also, do not prepare the array for storing the results after porting, prepare the Observable for saving the results in alps_init_observableSubroutine.In addition, it is not necessary for alps_init and alps_init_observable to call it in after-porting code because it is called automatically by ALPS.Also, do not prepare an array for storing the results, prepare the Observable for saving the results in alps_init_observableSubroutine.
  
*移植元
+
*before porting
 
   8:    C TABLES
 
   8:    C TABLES
 
   9:          DO 10 I=-4,4
 
   9:          DO 10 I=-4,4
Line 627: Line 605:
 
  23:    21  A(I)=0.0
 
  23:    21  A(I)=0.0
  
*移植後(alps_init)
+
*after porting(alps_init)
 
  13:    subroutine alps_init(caller)
 
  13:    subroutine alps_init(caller)
 
  14:      use ising_mod
 
  14:      use ising_mod
Line 671: Line 649:
 
  54:    end subroutine alps_init
 
  54:    end subroutine alps_init
  
移植後は21~24行目でalps_get_parameterをコールしており、ALPSを通してパラメータファイルの内容を取得しています。なお、34~51行目の処理は移植元と同じです。
+
Above code shows that it calls the alps_get_parameter in line 21 to 24, getting the contents of the parameter file through the ALPS.In addition, the processing of line 34-51 is the same as the original code.
  
*移植後(alps_init_observables)
+
*after porting(alps_init_observables)
  
 
   92:    subroutine alps_init_observables(caller)
 
   92:    subroutine alps_init_observables(caller)
Line 686: Line 664:
 
  101:    end subroutine alps_init_observables
 
  101:    end subroutine alps_init_observables
  
移植後は計算結果の保存用バッファとして"Energy"及び"Magnetization"という名前でObservableを用意しています。移植元ではEnergy及びMagnetizationそれぞれについて総和と二乗和を計算していますが、これらの計算はObservableが自動的に行います。
+
<!--移植後は計算結果の保存用バッファとして"Energy"及び"Magnetization"という名前でObservableを用意しています。移植元ではEnergy及びMagnetizationそれぞれについて総和と二乗和を計算していますが、これらの計算はObservableが自動的に行います。-->
 +
Observable are available with the name "Magnetization" and "Energy" as a buffer for storing the calculation result after porting.In the original code, calculates the sum of squares with the sum for each Magnetization and Energy, but,these calculations is done automatically by Observable after porting.
  
 +
====calcuration and saving results====
 +
<!--移植元 codeではdoループ内(移植前25行目)で繰り返し計算を行っていますが、移植後はdoループを使わずにalps_run及びalps_progressSubroutineを使用します。-->
 +
Although there has been in the do loop iteration (line 25 original-code)in the original code, and after porting, uses the alps_progressSubroutine alps_run without a do loop.
  
====計算及び結果保存====
+
*before porting
移植元コードではdoループ内(移植前25行目)で繰り返し計算を行っていますが、移植後はdoループを使わずにalps_run及びalps_progressサブルーチンを使用します。
 
 
 
*移植前
 
 
  24:    C SIMULATION
 
  24:    C SIMULATION
 
  25:          DO 30 K=1,MCS+INT
 
  25:          DO 30 K=1,MCS+INT
Line 718: Line 697:
 
  47:    30  CONTINUE
 
  47:    30  CONTINUE
  
*移植後(alps_run)
+
*after porting(alps_run)
 
  56:    ! subroutine alps_run
 
  56:    ! subroutine alps_run
 
  57:    subroutine alps_run(caller)
 
  57:    subroutine alps_run(caller)
Line 756: Line 735:
 
  89:    end subroutine alps_run
 
  89:    end subroutine alps_run
  
計算処理自体(65~82行目)は移植元と同じですが、移植後はalps_runが自動的に繰り返しコールされるので、移植前の25行目にあたるループは記述しません。その変わり、86行目で繰り返し回数をカウントします。
+
<!--計算処理自体(65~82行目)は移植元と同じですが、移植後はalps_runが自動的に繰り返しコールされるので、移植前の25行目にあたるループは記述しません。その変わり、86行目で繰り返し回数をカウントします。
また、計算結果の保存はALPSの機能を使用します(84、85行目)。移植元では積算、二乗計算等を行っています(移植元43~46行目)が、これらはalps_accumulate_observableで自動的に行われます。
+
また、計算結果の保存はALPSの機能を使用します(84、85行目)。移植元では積算、二乗計算等を行っています(移植元43~46行目)が、これらはalps_accumulate_observableで自動的に行われます。-->
  
*移植後(alps_progress)
+
Calculation process itself(Line 65 to 82)  is the same as the original code, after porting will be called automatically alps_run repeatedly, the loop at line 25 of the Original Code is not writted.Instead, it counts the number of iterations in line 86.Also, save the results of the calculation using the ALPS function(line 84 and 85).In the original code (lines 43-46 the original code) are performed, such as calculating the integrated and square, but these are done automatically by alps_accumulate_observable.
 +
 
 +
*after porting(alps_progress)
 
  103:    ! alps_progerss
 
  103:    ! alps_progerss
 
  104:    subroutine alps_progress(prgrs, caller)
 
  104:    subroutine alps_progress(prgrs, caller)
Line 772: Line 753:
 
  113:    end subroutine alps_progress
 
  113:    end subroutine alps_progress
  
移植後は繰り返し計算の制御をalps_progressで行います。prgrsが1以上になるとalps_runがコールされなくなるので、カウンタ(K)の値を監視し、規定回数分実行されたらprgrsが1以上になるよう実装します。
+
<!--移植後は繰り返し計算の制御をalps_progressで行います。prgrsが1以上になるとalps_runがコールされなくなるので、カウンタ(K)の値を監視し、規定回数分実行されたらprgrsが1以上になるよう実装します。-->
 +
after porting, Alps_progress done in the control of the iterative calculation.prgrs value is greater than or equal to 1 is alps_run will no longer be called.Therefore, it is implemented as prgrs value is greater than or equal to 1 to monitor the value of (K), the number of times when you are running counter provision.
  
 +
====thermalized check====
 +
<!--移植前のサーマライズチェックはメインループ内(36行目)で行われていますが、移植後はalps_is_thermalizedSubroutineで行います。-->
 +
In the original code, hermalized-check has been run within the main loop (line 36).However,after porting,run for subroutine alps_is_thermalized.
  
====サーマライズチェック====
+
*before porting
移植前のサーマライズチェックはメインループ内(36行目)で行われていますが、移植後はalps_is_thermalizedサブルーチンで行います。
 
 
 
*移植前
 
 
  36:          IF(K.LE.INT) GOTO 30
 
  36:          IF(K.LE.INT) GOTO 30
  
*移植後(alps_is_thermalized):
+
*after porting(alps_is_thermalized):
 
  115:    ! alps_is_thermalized
 
  115:    ! alps_is_thermalized
 
  116:    subroutine alps_is_thermalized(thrmlz, caller)
 
  116:    subroutine alps_is_thermalized(thrmlz, caller)
Line 799: Line 781:
 
  130:    end subroutine alps_is_thermalized
 
  130:    end subroutine alps_is_thermalized
  
移植後はalps_progress同様、カウンタ(K)の値からサーマライズのチェックを行います。thrmlzが1になるとサーマライズが完了したとみなされます。
+
Similarly alps_progress, checks the thermalized from the value of (K) counter.
 +
are considered to have been completed thermalize and become value thrmlz=1.
  
 +
====output results====
 +
Post-processing and output of the results is done automatically when you use the ALPS.Therefore, the codes for output of calculation results and post-processing are not required.
  
====結果の出力====
+
*before porting
ALPSを使用すると結果の後処理や出力は自動的に行われます。したがって、移植後は計算結果の後処理・出力用のコードは必要ありません。
 
 
 
*移植前
 
 
  48:    C STATISTICS
 
  48:    C STATISTICS
 
  49:          DO 50 I=1,4
 
  49:          DO 50 I=1,4
Line 818: Line 800:
 
  58:        * /' MAG =',F10.5,' X  =',F10.5)
 
  58:        * /' MAG =',F10.5,' X  =',F10.5)
  
*移植後:該当コードなし
+
*after porting:code not available
  
 +
====Finalizing process====
 +
There is no end processing is not performed for allocate in the original code.
 +
However, after porting must be deallocate array that you allocate in alps_init.
  
====終了処理====
+
*before porting:code not available
移植前のコードではallocateを行っていないため終了処理がありません。しかし、移植後はalps_init内でallocateした領域を終了時に開放する必要があります。
 
  
*移植前:該当コードなし
+
*after porting(alps_finalize)
 
 
*移植後(alps_finalize)
 
 
  160:    ! alps_finalize
 
  160:    ! alps_finalize
 
  161:    subroutine alps_finalize(caller)
 
  161:    subroutine alps_finalize(caller)
Line 842: Line 824:
 
  173:    end subroutine alps_finalize
 
  173:    end subroutine alps_finalize
  
 +
====restart function====
 +
Only to implement (alps_save / alps_load), you can add functionality to restart restart-file Program I / O function of when you use the ALPS.The original code does not have the ability to restart, describes an example implementation of I / O function of the restart-file according to the ALPS below.
  
====リスタート機能====
+
*before porting:code not available
ALPSを使用するとリスタートファイルの入出力機能(alps_save / alps_load)を実装するだけで、アプリケーションにリスタート機能を追加できます。移植元にはリスタート機能がありませんが、以下にALPSによるリスタートファイルの入出力機能の実装例を説明します。
 
  
*移植前:該当コードなし
+
*after porting(alps_save)
 
 
*移植後(alps_save)
 
 
  132:    ! alps_save
 
  132:    ! alps_save
 
  133:    subroutine alps_save(caller)
 
  133:    subroutine alps_save(caller)
Line 863: Line 844:
 
  144:    end subroutine alps_save
 
  144:    end subroutine alps_save
  
alps_saveではリスタートに必要なる変数のみをalps_dumpで書き出します。ここでは、カウンタ(K)及び計算途中のデータ(IX、IS)を書き出しています。
+
alps_save writes in alps_dump the only variables that need to restart.Here, This section shows how to export counter (K) and data (IX, IS) calculating.
  
*移植後(alps_load)
+
*after porting(alps_load)
 
  146:    ! alps_load
 
  146:    ! alps_load
 
  147:    subroutine alps_load(caller)
 
  147:    subroutine alps_load(caller)
Line 879: Line 860:
 
  157:      return
 
  157:      return
 
  158:    end subroutine alps_load
 
  158:    end subroutine alps_load
alps_loadではalps_saveで書き出した(alps_dump)順番で読み込む(alps_restore)する必要があります。
+
There are (alps_restore) must be loaded in the order alps_save exported in (alps_dump) In alps_load.However, when you restart the ALPSProgram, alps_init will be called before alps_load is called.
なお、ALPSアプリケーションをリスタートした場合、alps_loadが呼ばれる前にalps_initが呼ばれます。つまり、K、IX、ISのメモリ確保や他の変数の初期化はalps_init内で行われるので、alps_load内で初期化等を行う必要はありません。
+
However, when you restart the ALPSProgram, alps_init will be called before alps_load is called.
 
+
In other words, the initialization of the memory allocation K,IX,and IS and other variables is done in alps_init, need to do initialization, etc. within the alps_load is not available.
  
====マルチスレッド対応につて====
+
====About support of multi-thread====
ALPSアプリケーションをマルチスレッドで動作させる場合、Fortranコードをスレッドセーフな実装にする必要があります。本節で説明したtutorial.f90の場合、2.4.2で準備した変数をスレッドローカルにすることでマルチスレッドに対応することができます。
+
If you want to run with multi-thread the ALPSProgram, must be thread-safe implementation of the Fortran code.If tutorial.f90 described in this section, you can support multi-thread by thread-local variables to prepare in 2.4.2.
  
*移植後(マルチスレッド版)
+
*after porting(multi-thread)
  
 
   1:    module ising_mod
 
   1:    module ising_mod
Line 901: Line 882:
 
  12:
 
  12:
  
===main.Cについて ===
+
===About main.C ===
main.Cはアプリケーションのエントリポイントになるため、必須のファイルです。ただし、main関数については内容を変更する必要はありません。アプリケーション設定に関しては[[#サブルーチン呼び出しの流れ]]を参照の上、必要に応じて変更してください。
+
main.C file is required to become entry point of the Program.But it is not necessary to change the contents of the main function.
 +
Configuration of main.C, change it if necessary. refer to 2.2.2.
  
===CMakeLists.txtについて ===
+
===About CMakeLists.txt ===
CMakeLists.txtを[[#Fortran コードの書き方]]を参照の上、変更してください。以下はCMakeLits.txtの例です。
+
change the CMakeLists.txt (see text 2.3). The following is an example of CMakeLits.txt.
  
 
  1: cmake_minimum_required(VERSION 2.8.0 FATAL_ERROR)
 
  1: cmake_minimum_required(VERSION 2.8.0 FATAL_ERROR)
Line 915: Line 897:
 
  7: include(${ALPS_USE_FILE})
 
  7: include(${ALPS_USE_FILE})
 
  8:
 
  8:
  9: # 作成する実行ファイル名と必要なソースコード
+
  9: # Source code required to create and run file name
 
  10: add_executable(tutorial main.C tutorial.f90)
 
  10: add_executable(tutorial main.C tutorial.f90)
 
  11: target_link_libraries(tutorial ${ALPS_LIBRARIES} ${ALPS_FORTRAN_LIBRARIES})
 
  11: target_link_libraries(tutorial ${ALPS_LIBRARIES} ${ALPS_FORTRAN_LIBRARIES})

Latest revision as of 07:32, 15 March 2012

ALPS Fortran is the Fortran interface modules of ALPS. Using ALPS Fortran, You can run Fortran code program easily on ALPS by implementing some necessary subroutine. This chapter describes the procedures for writing the Fortran code to run on ALPS.In addition, also described in this chapter on how to modify (CMakeList.txt) file setting procedures and build the Fortran code to be ported to the existing ALPS Fortran.

Introduction ALPS Fortran

The following figure shows the relationship diagram between ALPS system,ALPS Fortran,and user fortran program.


ALPS Fortranのmodule構成


ALPS Fortran is called from the ALPS, call the Subroutine of the user program as necessary.Thus, ALPS can control the Program has been implemented in Fortran as well as the C++ Program.On the other hand, ALPS Fortran has provided a Subroutine call the functions of ALPS.Therefore, user program will be able to use the ALPS functions as well as to call the normal Fortran Subroutine.

call flows subroutine

The following figure shows the flow chart of the ALPS system and user program. Subroutines for each of the below, refer to the [2.3.3].

呼び出し流れ図

Preparation fortran source code

To implement the Program using ALPS Fortran, you will need to prepare following two source code.

  •  C++ source code for implementing main function(entory point of Program).
  •  Fortran source code for implementing according to a rule of the ALPS Fortran.


Entry Point 

This section describes the setting Program function main, such as main function(entry point of the Program) and the worker name.Main function is only to describe the fixed contents, usually does not need to be changed.Settings with Program, please refer to the following code,

  • Program version numbers
  • Program copyright
  • Worker name
  • Evaluator name

The following is an example of a C + + source code.

1:	#include <alps/parapack/parapack.h>
2:	#include "fortran_wrapper.h"
3:	
4:	// Version number setting
5:	PARAPACK_SET_VERSION("my version");
6:	
7:	// Copywrite display setting
8:	PARAPACK_SET_COPYRIGHT("my copyright");
9:	
10:	// Worker name setting
11:	PARAPACK_REGISTER_WORKER(alps::fortran_wrapper, "worker name</span>");
12:	
13:	// Evaluator setting
14:	PARAPACK_REGISTER_EVALUATOR(alps::parapack::simple_evaluator,"evaluator name");
15:	
16:	
17:	/**
18:	 * Programのentry point
19:	 */
20:	int main(int argc, char** argv)
21:	{
22:	    return alps::parapack::start(argc, argv);
23:	}

In the above example, it needs to be changed will be the red part characters.

Fortran source code

The main contents of the Fortran source code is the calculation logic.However, there is always a need to implement some Subroutine to use the ALPS Fortran.You call the ALPS function via the Subroutine provided by the ALPS Fortran when performing the loading of the parameters and saving the calculation results.

required Subroutine 

for the user program to control the function of ALPS, you will need some Subroutine in the Fortran source code.read on below for a description of each Subroutine,Implement appropriately,and is a link error if you omit them, you can not build. when implementing these Subroutine, keep in mind the following points:

  • All Subroutine will be passed "(2) :: caller integer" as argument.caller is a variable that is used internally to take ALPS function.Therefore, please do not rewrite the value of the caller. If the value of caller behavior has been changed is not guaranteed.
  • include the "alps / fortran / alps_fortran.h" In each Subroutine. This file will be required when calling the ALPS functions from Fortran code.

So, with regard to the Subroutine required, you will need the following three lines immediately below the signature of the Subroutine.

1:	subroutine alps_init(caller)
2:	implicit none
3:	include "alps/fortran/alps_fortran.h"
4:	integer :: caller(2)
5:	
6:	! --- snip --- !


alps_init(caller)

  • Argument
Type Name I/O Meaning
integer caller(2) in local variable
  • Explanation

This Subroutine will be called once before the calculation is performed.This is where the initialization process of the Program like as allocating arrays.


alps_init_observables(caller)

  • Argument
Type Name I/O Meaning
integer caller(2) in local variable
  • Explanation

This Subroutine will be called only once after it has been a call is alps_init. This is where you initialize the alps :: ObservableSet.This Subroutine is called once in one input parameter.Incidentally, detail information of the alps :: ObservableSet, refer to the ALPS HP.

alps_run(caller)

  • Argument
Type Name I/O Meaning
integer caller(2) in local variable
  • Explanation

This subroutine is implemented the logic calculation.until it returns a value greater than or equal to 1.0 by alps_progress,This Subroutine is called repeatedly from ALPS.Therefore, in this Subroutine is necessary to take the loop structure is not available. In addition,while running at thread-level-parallelism,this subroutine work on multi-threading.Therefore, when used in thread-level-parallelism is required to provide thread-safe implementation

alps_progress(prgrs, caller)

  • Argument
Type Name I/O Meaning
real*8 prgrs out Programの進捗状態(0.0 ≦ prgrs)
integer caller(2) in local variable
  • Explanation

This Subroutine will be called by the ALPS has been finished after alps_run, ALPS is returned to the progress situation of the Program.While the prgrs value less than 1.0, ALPS will call repeatedly alps_run. When prgrs value more than 1.0 are substituted, ALPS judges that a calculation was completed, and will finish the program.In addition,while running at thread-level-parallelism,this subroutine work on multi-threading.Therefore, when used in thread-level-parallelism is required to provide thread-safe implementation

alps_is_thermalized(thrmlz, caller)

  • Argument
Type Name I/O Meaning
real*8 thrmlz out thermalize ending flag(0:Not Completed / 1:Completed )
integer caller(2) in local variable
  • Explanation

This Subroutine will be called by the ALPS has been finished after alps_run, returns the incomplete / complete thermalize.When a value of thrmlz is 0, Program judges the calculation is now in thermalize, and does not save a calculation result data.On the other hand,value is 1, Program judges that thermalize was completed, and the calculation result saving is started. In addition,while running at thread-level-parallelism,this subroutine work on multi-threading.Therefore, when used in thread-level-parallelism is required to provide thread-safe implementation

alps_finalize(caller)

  • Argument
Type Name I/O Meaning
integer caller(2) in local variable
  • Explanation

This Subroutine will be called only once (after returning the value greater than or equal to 1.0 from alps_progress) after completing your calculation. This is where you end processing such as the release of allocated memory.

alps_save(caller)

  • Argument
Type Name I/O Meaning
integer caller(2) in local variable
  • Explanation

This subroutine is called from ALPS has been finished after alps_run. Saves the restartrestart-file using the function of ALPS.In addition,while running at thread-level-parallelism,this subroutine work on multi-threading.Therefore, when used in thread-level-parallelism is required to provide thread-safe implementation.


alps_load(caller)

  • Argument
Type Name I/O Meaning
integer caller(2) in local variable
  • Explanation

This Subroutine will be called once, when the Program is restart. Load the saved restart-file using the ALPS functions.

Subroutine provided ALPS Fortran

When you call the ALPS functions from the user program, call the Subroutine provided by the ALPS Fortran. These subroutine will require "(2) :: caller integer" as argument. caller is a local variable that is passed from the ALPS Fortran, you will need to pass the Subroutine provided as a variable passed in the argument to (2.2.3.1) Subroutine required.

alps_get_parameter(data, name, type, caller)

  • Argument
Type Name I/O Meaning
- data out store of the value
character name(*) in parameter name to take out
integer type in data type
integer caller(2) in local variable
  • Explanation

Specify the name, ane receive a parameter from ALPS. parameter name, type, number of elements is specified name, type, in each count.This Subroutine will be used to initialize the arrays and variables in the mainly alps_init. In addition, the possible value of the type is defined in the alps_fortran.h.


alps_parameter_defined(res, name, caller)

  • Argument
Type Name I/O Meaning
integer res out The presence or absence of definition of parameter(1:absence / 0:definition)
character name(*) in parameter name
integer caller(2) in local variable
  • Explanation

Returns whether the parameter is defined in the parameter file is specified by name. 1Italic text is assigned to the res if it is defined. 0Italic text is assigned if it is not.This Subroutine will be used to initialize the arrays and variables in the mainly alps_init.

alps_init_observable(count, type, name, caller)

  • Argument
Type Name I/O Meaning
integer count in Number of element of a stored calculation result
integer type in data type
character name(*) in The name of Observable to store
integer caller(2) in local variable
  • Explanation

This Subroutine is used to register a name that is specified in the Observable to alps :: ObservableSet in alps_init_observable. Observable types are determined as follows by type and count.

type count 対応するObservable
ALPS_INT 1 IntObservable
ALPS_INT 1< in
ALPS_REAL 1 RealObservable
ALPS_REAL 1< RealVectorObservable
ALPS_DOUBLE_PRECISION 1 RealObservable
ALPS_DOUBLE_PRECISION 1< RealVectorObservable


alps_accumulate_observable(data, count, type, name, caller)

  • Argument
Type Name I/O Meaning
- data in the calculation results to store
integer count in Number of element of a stored calculation result
integer type in data type
character name(*) in The name of Observable to store
integer caller(2) in local variable
  • Explanation

Save the result data to Observable with the specified name. This Subroutine is used to store the results of a calculation in alps_run. count / name / type must match the ones specified in init_observable.


alps_dump(data, count, type, caller)

  • Argument
Type Name I/O Meaning
- data in the values to store
integer count in Number of elements of values to store
integer type in data type
integer call(2) in local variable
  • Explanation

This Subroutine is used to save the restart-file in the alps_save. interruption data was saved using alps_dump will be used at restart.


alps_restore(data, count, type, caller)

  • Argument
Type Name I/O Meaning
- data out storage location of loaded values
integer count in Number of element of value to load
integer type in data type
integer caller(2) in local variable
  • Explanation

This Subroutine is used to load the restart-file in the alps_load.to restart-file data is saved in the order in which they were saved in alps_dump.Therefore, when loading is alps_restore, remove the data in the same order as when it is saved.

editing configuration file

user program builds using CMake as well as ALPS. It is a sample of setting file(CMakeLists.txt) to build user program in CMake as follows.

1:	# CMakeList.txt
2:	# editing configuration file for CMake
3:	
4:	cmake_minimum_required(VERSION 2.8.0 FATAL_ERROR)
5:	
6:	#Project name setting
7:	project(hello_sample)
8:	
9:	# find ALPS Fortran setting
10:	find_package(ALPS REQUIRED NO_SYSTEM_ENVIRONMENT_PATH)
11:	message(STATUS "ALPS version: ${ALPS_VERSION}")
12:	include(${ALPS_USE_FILE})
13:	
14:	# Source code required to create and run file name
15:	add_executable(hello main.C hello_impl.f)
16:	# External library file required to generate execution
17:	target_link_libraries(hello ${ALPS_LIBRARIES} ${ALPS_FORTRAN_LIBRARIES})

In the above example, it needs to be changed will be the red part characters.

Porting of existing program code

In this section, in case of the ising model program shown below,Describes the procedure that ALPS to work on the existing Fortran Program.


preparation porting 

In this section, we will use the file in the tutorial directory that is generated by extracting the alps_fortran.tar.gz.In preparation for the porting work, copy the following file to a working directory in the tutorial directory.

  • ising_original.f:original source code
  • template.f90:Template source cod of ALPS Fortran Program
  • main.C:entry point of Program
  • CMakeList.txt:Template of CMakeList.txt


All Subroutine which are necessary implementing ALPSProgram in template.f90 is defined.Therefore, when developing a new Program you can proceed with the development based on template.f90.

The rough structure of original code is as follows.

Processing contents
4-7 Variable Declaration & Initialization
8-23 Array element Initialization
24-47 main loop
25-34 calculation
36 thermalize check
37-46 saving calculation resutls
48-58 results output

porting fortran code

The porting of Fortran code, we will assign to Subroutine, the processing being done in each block of ising_original.f. This section describes an example of tutorial/alps_ising.f90 as a sample of after-porting code.

Variable declaration

Each variable has been declared in the ising_original.f is at the porting is turned into ALPS module.In order to porting to ALPS because there is a need to Subroutine for each processing unit, and modify it to allow access to the variables from each Subroutine.

  • before porting
4:          DIMENSION IS(20,20),IP(20),IM(20),P(-4:4),A(4)
5:    C PARAMETERS
6:          DATA TEMP/2.5/, L/10/, MCS/1000/, INT/1000/
7:          DATA IX/1234567/, V0/.465661288D-9/
  • after porting
1:    module ising_mod
2:      implicit none
3:      real, parameter :: V0 = .465661288D-9
4:
5:      integer, allocatable, dimension(:) :: IP, IM
6:      integer, allocatable, dimension(:,:) :: IS
7:      real*8, allocatable, dimension(:) :: P
8:      integer :: K, MCS, INT, L, IX
9:      real :: TEMP
10:    end module ising_mod
11:

IP, IM, IS, P array are initialized in alps_init, the size of the after transplantation does not specify here.In addition, original array A is for storing a result, this array is in the after-porting will use the mechanism of ALPS.Therefore, array A is not necessary for code after the porting.Also, the value of each variable after porting gotten from the parameter file.In addition, K is a variable variable after the porting to count the number of iterations. Thermalize check after porting is responsible for control and repeat with the value of K to do without a loop.
※In this section, so that is expected to run in parallel MPI, for thread-safe is not considered.

Initializing process

Initialization process of the original code may have to initialize each element of the array, at after-porting code, run in the initialization process is Subroutine alps_init.First,Initializes the array variables, using the alps_get_parameter, then initialize the array elements.Also, do not prepare the array for storing the results after porting, prepare the Observable for saving the results in alps_init_observableSubroutine.In addition, it is not necessary for alps_init and alps_init_observable to call it in after-porting code because it is called automatically by ALPS.Also, do not prepare an array for storing the results, prepare the Observable for saving the results in alps_init_observableSubroutine.

  • before porting
 8:    C TABLES
 9:          DO 10 I=-4,4
10:          W=EXP(FLOAT(I)/TEMP)
11:     10   P(I)=W/(W+1/W)
12:          DO 11 I=1,L
13:          IP(I)=I+1
14:     11   IM(I)=I-1
15:          IP(L)=1
16:          IM(1)=L
17:    C INITIAL CONFIGURATION
18:          DO 20 I=1,L
19:          DO 20 J=1,L
20:     20   IS(I,J)=1
21:    C ACCUMULATION DATA RESET
22:          DO 21 I=1,4
23:     21   A(I)=0.0
  • after porting(alps_init)
13:    subroutine alps_init(caller)
14:      use ising_mod
15:      implicit none
16:      include "alps/fortran/alps_fortran.h"
17:      integer :: caller(2)
18:      integer :: i, j
19:      real*8 :: W
20:
21:      call alps_get_parameter(TEMP, "TEMPERATURE", ALPS_REAL, caller)
22:      call alps_get_parameter(L, "L", ALPS_INT, caller)
23:      call alps_get_parameter(MCS, "MCS", ALPS_INT, caller)
24:      call alps_get_parameter(INT, "INT", ALPS_INT, caller)
25:
26:      allocate( IP(L) )
27:      allocate( IM(L) )
28:      allocate( P(-4:4) )
29:      allocate( IS(L, L) )
30:
31:      K = 0
32:      IX = 1234567
33:
34:      do i = -4, 4
35:         W = exp(float(i)/TEMP)
36:         P(i) = W / (W + 1/W)
37:      end do
38:
39:      do i = 1, L
40:         IP(i) = i + 1
41:         IM(i) = i - 1
42:      end do
43:
44:      do i = 1, L
45:         do j = 1, L
46:            IS(i, j) = 1
47:         end do
48:      end do
49:
50:      IP(L) = 1
51:      IM(1) = L
52:
53:      return
54:    end subroutine alps_init

Above code shows that it calls the alps_get_parameter in line 21 to 24, getting the contents of the parameter file through the ALPS.In addition, the processing of line 34-51 is the same as the original code.

  • after porting(alps_init_observables)
 92:    subroutine alps_init_observables(caller)
 93:      implicit none
 94:      include "alps/fortran/alps_fortran.h"
 95:      integer :: caller(2)
 96:
 97:      call alps_init_observable(1, ALPS_REAL, "Energy", caller)
 98:      call alps_init_observable(1, ALPS_REAL, "Magnetization", caller)
 99:
100:      return
101:    end subroutine alps_init_observables

Observable are available with the name "Magnetization" and "Energy" as a buffer for storing the calculation result after porting.In the original code, calculates the sum of squares with the sum for each Magnetization and Energy, but,these calculations is done automatically by Observable after porting.

calcuration and saving results

Although there has been in the do loop iteration (line 25 original-code)in the original code, and after porting, uses the alps_progressSubroutine alps_run without a do loop.

  • before porting
24:    C SIMULATION
25:          DO 30 K=1,MCS+INT
26:          KIJ=0
27:          DO 31 I=1,L
28:          DO 31 J=1,L
29:          M=IS(IP(I),J)+IS(I,IP(J))+IS(IM(I),J)+IS(I,IM(J))
30:          KIJ=KIJ+1
31:          IS(I,J)=-1
32:          IX=IAND(IX*5*11,2147483647)
33:          IF(P(M).GT.V0*IX) IS(I,J)=1
34:     31   CONTINUE
35:    C DATA
36:          IF(K.LE.INT) GOTO 30
37:          EN=0
38:          MG=0
39:          DO 40 I=1,L
40:          DO 40 J=1,L
41:          EN=EN+IS(I,J)*(IS(IP(I),J)+IS(I,IP(J)))
42:     40   MG=MG+IS(I,J)
43:          A(1)=A(1)+EN
44:          A(2)=A(2)+EN**2
45:          A(3)=A(3)+MG
46:          A(4)=A(4)+MG**2
47:     30   CONTINUE
  • after porting(alps_run)
56:    ! subroutine alps_run
57:    subroutine alps_run(caller)
58:      use ising_mod
59:      implicit none
60:      include "alps/fortran/alps_fortran.h"
61:      integer :: caller(2)
62:      integer :: i, j, M
63:      real*8 :: EN, MG
64:
65:      do i = 1, L
66:         do j = 1, L
67:            M = IS(IP(i), j) + IS(i, IP(j)) + IS(IM(i), j) + IS(i, IM(j))
68:            IS(i, j) = -1
69:
70:            IX = IAND(IX * 5 * 11, 2147483647)
71:            if(P(M).gt.V0*IX) IS(i, j) = 1
72:         end do
73:      end do
74:
75:      EN = 0.0D0
76:      MG = 0.0D0
77:      do i = 1, L
78:         do j = 1, L
79:            EN = EN + IS(i, j) * (IS(IP(i), j) + IS(i, IP(j)))
80:            MG = MG + IS(i, j)
81:         end do
82:      end do
83:
84:      call alps_accumulate_observable(EN, 1, &
         ALPS_DOUBLE_PRECISION, "Energy", caller)
85:      call alps_accumulate_observable(MG, 1, &
         ALPS_DOUBLE_PRECISION, "Magnetization", caller)
86:      K = K + 1
87:
88:      return
89:    end subroutine alps_run


Calculation process itself(Line 65 to 82) is the same as the original code, after porting will be called automatically alps_run repeatedly, the loop at line 25 of the Original Code is not writted.Instead, it counts the number of iterations in line 86.Also, save the results of the calculation using the ALPS function(line 84 and 85).In the original code (lines 43-46 the original code) are performed, such as calculating the integrated and square, but these are done automatically by alps_accumulate_observable.

  • after porting(alps_progress)
103:    ! alps_progerss
104:    subroutine alps_progress(prgrs, caller)
105:      use ising_mod
106:      implicit none
107:      include "alps/fortran/alps_fortran.h"
108:      integer :: caller(2)
109:      real*8 :: prgrs
110:
111:      prgrs = K / (INT + MCS)
112:
113:    end subroutine alps_progress

after porting, Alps_progress done in the control of the iterative calculation.prgrs value is greater than or equal to 1 is alps_run will no longer be called.Therefore, it is implemented as prgrs value is greater than or equal to 1 to monitor the value of (K), the number of times when you are running counter provision.

thermalized check

In the original code, hermalized-check has been run within the main loop (line 36).However,after porting,run for subroutine alps_is_thermalized.

  • before porting
36:          IF(K.LE.INT) GOTO 30
  • after porting(alps_is_thermalized):
115:    ! alps_is_thermalized
116:    subroutine alps_is_thermalized(thrmlz, caller)
117:      use ising_mod
118:      implicit none
119:      include "alps/fortran/alps_fortran.h"
120:      integer :: caller(2)
121:      integer :: thrmlz
122:
123:      if(K >= INT) then
124:         thrmlz = 1
125:      else
126:         thrmlz = 0
127:      end if
128:
129:      return
130:    end subroutine alps_is_thermalized

Similarly alps_progress, checks the thermalized from the value of (K) counter. are considered to have been completed thermalize and become value thrmlz=1.

output results

Post-processing and output of the results is done automatically when you use the ALPS.Therefore, the codes for output of calculation results and post-processing are not required.

  • before porting
48:    C STATISTICS
49:          DO 50 I=1,4
50:     50   A(I)=A(I)/MCS
51:          C=(A(2)-A(1)**2)/L**2/TEMP**2
52:          X=(A(4)-A(3)**2)/L**2/TEMP
53:          ENG=A(1)/L**2
54:          AMG=A(3)/L**2
55:          WRITE(6,100) TEMP,L,ENG,C,AMG,X
56:     100  FORMAT(' TEMP=',F10.5,' SIZE=',I5,
57:         * /' ENG =',F10.5,' C   =',F10.5,
58:         * /' MAG =',F10.5,' X   =',F10.5)
  • after porting:code not available

Finalizing process

There is no end processing is not performed for allocate in the original code. However, after porting must be deallocate array that you allocate in alps_init.

  • before porting:code not available
  • after porting(alps_finalize)
160:    ! alps_finalize
161:    subroutine alps_finalize(caller)
162:      use ising_mod
163:      implicit none
164:      include "alps/fortran/alps_fortran.h"
165:      integer :: caller(2)
166:
167:      deallocate(IP)
168:      deallocate(IM)
169:      deallocate(P)
170:      deallocate(IS)
171:
172:      return
173:    end subroutine alps_finalize

restart function

Only to implement (alps_save / alps_load), you can add functionality to restart restart-file Program I / O function of when you use the ALPS.The original code does not have the ability to restart, describes an example implementation of I / O function of the restart-file according to the ALPS below.

  • before porting:code not available
  • after porting(alps_save)
132:    ! alps_save
133:    subroutine alps_save(caller)
134:      use ising_mod
135:      implicit none
136:      include "alps/fortran/alps_fortran.h"
137:      integer caller(2)
138:
139:      call alps_dump(K, 1, ALPS_INT, caller)
140:      call alps_dump(IX, 1, ALPS_INT, caller)
141:      call alps_dump(IS, L * L, ALPS_INT, caller)
142:
143:      return
144:    end subroutine alps_save

alps_save writes in alps_dump the only variables that need to restart.Here, This section shows how to export counter (K) and data (IX, IS) calculating.

  • after porting(alps_load)
146:    ! alps_load
147:    subroutine alps_load(caller)
148:      use ising_mod
149:      implicit none
150:      include "alps/fortran/alps_fortran.h"
151:      integer :: caller(2)
152:
153:      call alps_restore(K, 1, ALPS_INT, caller)
154:      call alps_restore(IX, 1, ALPS_INT, caller)
155:      call alps_restore(IS, L * L, ALPS_INT, caller)
156:
157:      return
158:    end subroutine alps_load

There are (alps_restore) must be loaded in the order alps_save exported in (alps_dump) In alps_load.However, when you restart the ALPSProgram, alps_init will be called before alps_load is called. However, when you restart the ALPSProgram, alps_init will be called before alps_load is called. In other words, the initialization of the memory allocation K,IX,and IS and other variables is done in alps_init, need to do initialization, etc. within the alps_load is not available.

About support of multi-thread

If you want to run with multi-thread the ALPSProgram, must be thread-safe implementation of the Fortran code.If tutorial.f90 described in this section, you can support multi-thread by thread-local variables to prepare in 2.4.2.

  • after porting(multi-thread)
 1:    module ising_mod
 2:      implicit none
 3:      real, parameter :: V0 = .465661288D-9
 4:
 5:      integer, allocatable, dimension(:) :: IP, IM
 6:      integer, allocatable, dimension(:,:) :: IS
 7:      real*8, allocatable, dimension(:) :: P
 8:      integer :: K, MCS, INT, L, IX
 9:      real :: TEMP
10:    !$omp threadprivate (K, MCS, INT, TEMP, IP, IM, P, IS, IX, L)
11:    end module ising_mod
12:

About main.C 

main.C file is required to become entry point of the Program.But it is not necessary to change the contents of the main function. Configuration of main.C, change it if necessary. refer to 2.2.2.

About CMakeLists.txt 

change the CMakeLists.txt (see text 2.3). The following is an example of CMakeLits.txt.

1:	cmake_minimum_required(VERSION 2.8.0 FATAL_ERROR)
2:	
3:	project(tutorial)
4:	
5:	find_package(ALPS REQUIRED NO_SYSTEM_ENVIRONMENT_PATH)
6:	message(STATUS "ALPS version: ${ALPS_VERSION}")
7:	include(${ALPS_USE_FILE})
8:	
9:	# Source code required to create and run file name
10:	add_executable(tutorial main.C tutorial.f90)
11:	target_link_libraries(tutorial ${ALPS_LIBRARIES} ${ALPS_FORTRAN_LIBRARIES})