Ninf-G IDL files are processed by CPP(C Pre Processor).
Please pay attention to CPP keywords(ex. "#include").
Keywords described below are reserved by Ninf-G. You can't use these words as the name of module, functions or parameters.
Module
module_name ;
This specifies the identifier of the Ninf-G Executable. The name specified here is used for naming the Ninf-G stub file and the makefile for compiling it, etc.
Globals {
... C descriptions ... }
Global variables that can be used from all of the remote functions and remote methods that can be executed by the Ninf-G Executable can be defined. The expression between braces ({ c }) is written in C.
Note: The maximum number of Globals which can be defined in one IDL file is 100.
Note: The strings written in "Globals" are put to the Ninf-G stub file
which is generated by ng_gen as it is. So you can put CPP keywords
(like "#include < foo.h >") to the Ninf-G stub file by using "Globals".
But if you want multiple of them, please use multiple "Globals" like
below.
Globals{#include < foo.h >}
Globals{#include < bar.h >}
You can't write like below because Ninf-G IDL files are processed by CPP.
Globals{
#include < foo.h >
#include < bar.h >
}
Compiler "
... ";
This specifies the compiler to be used when the Ninf-G Executable is compiled.
CompileOptions "
... ";
This specifies the options to be applied when the Ninf-G Executable is compiled.
Note: The maximum number of CompileOptions which can be defined in one IDL file is 100.
Linker "
... ";
This specifies the linker to be used at link time of Ninf-G Executable.
Library "
... ";
This specifies the libraries and the options to be applied at the link time of Ninf-G Executable.
For example, ("-lxxx") and the object file (".o") or library file (".a") will be specified in this section. The options specified in this section are applied only at link time not at compile time (*.c -> *.o).
Note: The maximum number of Library which can be defined in one IDL file is 100.
FortranFormat "
...";
The Ninf-G stub is output as a C program.
When functions that are written in FORTRAN are called from that
program, the name must be converted to a particular format
("_%s_"
, where %s
is a function name).
That conversion format is shown below.
The following character strings have special meanings; they are replaced by particular character strings at processing time.
%s
: Original function name
%l
: All-uppercase function name
DefClass
class_name
["
description"
]
[Required
"
files-or-libs"
]
[Backend
"MPI"
| "BLACS"
]
[Language
"C"
| "C++"
| "FORTRAN"
]
[Shrink
"yes"
| "no"
]
{
[DefState{
... }
]
DefMethod
method_name
(
arg1, arg2, ... )
{
...}
... }
Defines a remote class.
One DefState
section and one or more remote methods
can be defined for the Ninf-G Executable.
The DefState
section can be omitted.
The attribute values that can be set are described below.
description | A character string that explains this Ninf-G Executable. |
Any character string may be used. | |
Required |
The remote function object file (".o"). |
This specifies the object file (".o") that stores the functions used by the remote function. | |
Backend |
This specifies the backend at run time. |
"MPI" or "BLACS" can be specified.If omitted, no backend is used. |
|
Language |
The programming language in which the remote method is written. |
"C" , "C++" or "FORTRAN"
can be specified.
If omitted, the default value is "C" .
|
|
Shrink |
Specify whether or not shrinking is enabled. |
If "yes" is specified, shrinking is applied
to the array elements.If omitted, shrinking is not done. |
DefState {
... C descriptions ... }
The variables maintained by Ninf-G Executable are defined in C.
Those values can be shared by multiple remote methods of the same Ninf-G Executable.
DefMethod
["
description"
]
[CalcOrder
exp]
{
{
C descriptions }
| Calls
lang-spec function_name
(
arg1, arg2, ...);
}
Defines a remote method.
A C program can be written in the remote method,
and functions can be called from within the program or
by using the Calls
keyword to specify the
functions to be called.
Note: following keywords are reserved by Ninf-G. So you can't use these keywords in your remote function.
"ng_stub_end"
, "ng_stub_mpi_end"
"ng_stub_rank"
The language in which the function that is called from
the remote method is written can be specified in the
lang-spec argument that comes right after the Calls
keyword.
Currently, "C"
, "C++"
or "FORTRAN"
can be specified.
If omitted, the default "C"
is used.
If "FORTRAN"
is specified here,
the called function must be converted to the format
specified by FortranFormat
before it is called.
The attribute values that can be set are described below.
"description" | A character string that explains this remote method. |
Any character string can be used. | |
CalcOrder |
Calculation order. |
The cost of executing the remote method can be specified here in arbitrary expression form. |
If argumentless remote methods are defined with the following names, those remote methods will be executed automatically when the Ninf-G Executable starts up and ends.
_initialize() |
Executed at startup |
_finalize() |
Executed at end |
Define
function_name
(
parameter1, parameter2, ... )
["
description"
]
[Required
"
files-or-libs"
]
[CalcOrder
exp]
[Backend
"MPI"
| "BLACS"
]
[Language
"C"
| "C++"
| "FORTRAN"
]
[Shrink
"yes"
| "no"
]
{
{
C descriptions }
| Calls
lang-spec function_name
(
arg1, arg2, ...);
}
Defines a remote function.
This remote function is a method that is exclusive
to the Ninf-G Executable.
A C program can be written in the remote function,
and functions can be called from within the program or
by using the Calls
keyword to specify
the functions to be called.
Note: following keywords are reserved by Ninf-G. So you can't use these keywords in your remote function.
"ng_stub_end"
, "ng_stub_mpi_end"
"ng_stub_rank"
The language in which the function that is called from
the remote method can be specified in the lang-spec argument
that comes right after the Calls
keyword.
Currently, "C"
, "C++"
or "FORTRAN"
can be specified.
If omitted, the default "C"
is used.
If "FORTRAN"
is specified here,
the called function must be converted to the format
specified by FortranFormat
before it is called.
The attribute values that can be set are described below.
"description" | A character string that explains this remote function. |
Any character string can be used. | |
Required |
The remote function object file (".o"). |
This specifies the object file (".o") that stores the functions used by the remote function. | |
CalcOrder |
Calculation order. |
The cost of executing the remote function can be specified here in arbitrary expression form. | |
Backend |
This specifies the backend at run time. |
"MPI" or "BLACS" can be specified.If omitted, no backend is used. |
|
Language |
The programming language in which the remote function is written. |
"C" , "C++" or "FORTRAN"
can be specified.If omitted, the default value is "C" .
|
|
Shrink |
Specify whether or not shrinking is enabled. |
If "yes" is specified, shrinking is applied
to the array elements.If omitted, shrinking is not done. |
The arguments passed to the remote function or remote method are written with the following syntax.
[mode-spec] [type-spec] parameter_name [[dimension[:range]]+
Note: A scalar variable cannot be used for the parameter of callback function.
Note: The maximum number of the parameter which can be defined as callback function is 32.
"mode-spec" | parameter mode |
Note: The mode cannot be specified for Callback.
A scalar variable cannot be used for the parameter
that specifies the Note: "allocate" and "broadcast" can be written before or after the mode keywords("IN", "INOUT", "OUT", "WORK"). If "allocate" and "broadcast" are omitted, nothing will be done. Note: "allocate" and "broadcast" are ignored if the backend of the remote method is neither "MPI" nor "BLACS". |
|
"type-spec" | Parameter type |
Note: The Note: There is the example program for filename type variable in Ninf-G package. ( < package directory > /diag/file_test ) |
|
parameter_name | any character string |
Array specification | The specification of an array of parameters |
If the parameter is an array, it is written as "[" + expression + "]" and its size is specified. A multidimensional array can be defined with multiple "[" + expression + "]". Also, the variables used by the argument can be used in the expression. It is also possible to specify the starting position, ending position and shrinking interval within "[" + expression + "]" as shown below to define arrays.
"[" + expression (size) + ":" + expression (start position) + "]" If a shrinking interval is specified and "Shrink" is enabled, shrinking of variable values is done for transmission and saving. Note: If "starting positon" is omitted,
then it's set to the value of "0". |
Expressions can be used to specify the calculation order and the size of parameter arrays.
It can include constants, other IN
mode
scalar parameter in the function definition, and some operators.
We provide some operators (+
, -
,
*
, /
, %
...).
Priority among these operators is same as ANSI C.
You can also use parentheses in expressions.
Examples)
Arithmetic operations | 10 / 2 * 5 |
Three term calculation | n % 10 ? 5: 2 |
/* program toplevel */
program: /* empty */
| declaration_list
;
declaration_list:
declaration
| declaration_list declaration
;
declaration:
"Module" IDENTIFIER ';'
| "CompileOptions" STRING ';'
| "Globals" globals_body
| "Library" STRING ';'
| "FortranFormat" STRING ';'
| "FortranStringConvention" IDENTIFIER ';'
| "Define" interface_definition opt_string option_list interface_body
| "DefClass" IDENTIFIER opt_string defclass_option_list '{' define_list '}'
| "Compiler" STRING ';'
| "Linker" STRING ';'
;
define_list:
/* empty */
| define_item
| define_list define_item
;
define_item:
"DefState" '{'
| "DefMethod" interface_definition opt_string
defmethod_option_list interface_body
;
defmethod_option_list:
/* empty */
| defmethod_option
| defmethod_option_list defmethod_option
;
defmethod_option:
calcorder
;
defclass_option_list:
/* empty */
| defclass_option
| defclass_option_list defclass_option
;
defclass_option:
required
| backend
| shrink
| language
;
option_list:
/* empty */
| decl_option
| option_list decl_option
;
decl_option:
required
| backend
| shrink
| calcorder
| language
;
interface_definition:
IDENTIFIER '(' parameter_list ')'
| IDENTIFIER '(' parameter_callback_list ')'
| IDENTIFIER '(' callback_list ')'
;
callback_list:
callback
| callback_list ',' callback
;
parameter_callback_list:
parameter_list ',' callback
| parameter_callback_list ',' callback
;
parameter_list:
/* empty */
| parameter
| parameter_list ',' parameter
;
callback:
IDENTIFIER '(' parameter_list ')'
;
parameter:
decl_specifier declarator
;
decl_specifier:
mode_specifier type_specifier
| type_specifier mode_specifier
| type_specifier mode_specifier type_specifier
;
type_specifier:
TYPE
| TYPE TYPE
| TYPE TYPE TYPE
;
mode_specifier:
MODE
| MODE DISTMODE
| DISTMODE MODE
;
declarator:
IDENTIFIER
| '(' declarator ')'
| declarator '['expr_or_null ']'
| declarator '['expr_or_null ':' range_spec ']'
| '*' declarator
;
range_spec:
expr /* upper limit */
| expr ',' expr /* lower limit and upper limit */
| expr ',' expr ',' expr /* lower, upper and step */
;
opt_string:
/* empty */
| STRING
;
required:
"Required" STRING
;
backend:
"Backend" STRING
;
shrink:
"Shrink" STRING
;
language:
"Language" STRING
;
calcorder:
"CalcOrder" expr
;
interface_body:
'{' /* C statements */ '}'
| "Calls" opt_string IDENTIFIER '(' id_list ')' ';'
;
globals_body:
'{' /* C statements */ '}'
;
id_list: IDENTIFIER
| id_list ',' IDENTIFIER
| /* empty */
;
/* index description */
expr_or_null:
expr
| /* empty */
;
expr:
unary_expr
| expr '/' expr
| expr '%' expr
| expr '+' expr
| expr '-' expr
| expr '*' expr
| expr '^' expr
| expr '<' expr
| expr "<=" expr
| expr ">' expr
| expr ">=" expr
| expr "!=" expr
| expr "==" expr
| expr '?' expr ':' expr
;
unary_expr:
primary_expr
| '*' expr
| '-' expr
;
primary_expr:
primary_expr '[' expr ']'
| IDENTIFIER
| CONSTANT
| '(' expr ')'
;
/* TYPE = int, char, short, long, long float, double string scomplex dcomplex filename */
/* MODE = IN, OUT, INOUT, WORK */
/* DISTMODE = allocate broadcast */
/* IDENTIFIER = name */
/* CONSTANT = integer literals, floating point literals */
/* STRING = "..." */
"PI" is a sample program in Ninf-G package.
Followings are IDL files used by Ninf-G users.
idl-sample/function/sample.mak(Makefile) |
idl-sample/function/_stub_sin.c |
idl-sample/function/_stub_mmul.c |
idl-sample/function/_stub_mmul2.c |
idl-sample/function/_stub_FFT.c |
idl-sample/object/sample_object.mak(Makefile) |
idl-sample/object/_stub_sample_object.c |