Singleton
For use as a singleton (the same object for all modules):
Place these lines in your project's .config:
<singleton-services>
<service name="SimpleCsvOutput" need="required" />
</singleton-services>
And in your module(s):
#include <arcane/core/ISimpleTableOutput.h>
table->
init(
"Example_Name",
"example");
table->writeFile();
Interface representing a simple table output.
virtual bool init()=0
Method to initialize the table.
Utility class for instantiating a service of a given interface.
InterfaceType * getSingleton(eServiceBuilderProperties properties=SB_None)
Singleton instance of the service implementing the InterfaceType interface.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Service
For use as a service (a different object for each module):
Place these lines in your module's .axl:
<service-instance name="simple-table-output" type="Arcane::ISimpleTableOutput">
<description>Service implementing ISimpleTableOutput</description>
</service-instance>
In the .arc, you can configure the service options. For example:
<simple-table-output name="SimpleCsvOutput">
<tableDir>example_dir</tableDir>
<tableName>Results_Example</tableName>
</simple-table-output>
And in your module:
#include <arcane/ISimpleTableOutput.h>
options()->simpleCsvOutput()->init();
options()->simpleCsvOutput()->writeFile();
You can also use the service in both ways at the same time, depending on your needs.
(For a more concrete example, see the following pages)
Naming Symbols for Parallel Execution (CSV Implementation)
In the directory name or the table name, whether in singleton mode or service mode, it is possible to add symbols that will be replaced during execution.
The available symbols are:
- @proc_id@: Will be replaced by the process rank.
- @num_procs@: Will be replaced by the total number of processes.
For example, if we have:
<tableDir>N_@num_procs@</tableDir>
<tableName>Results_P@proc_id@</tableName>
or when initializing the service:
...
table->init("Results_P@proc_id@", "N_@num_procs@");
...
And if we run the program with 2 processes (ID = 0 and 1), we will get two CSV files with the path:
- ./output/csv/N_2/Results_P0.csv
- ./output/csv/N_2/Results_P1.csv
(sequentially, we will have ./output/csv/N_1/Results_P0.csv)
This allows, among other things, to:
- create a table per process and name them easily,
- create "generic" .arc files where the number of processes does not matter,
- have a different name for each table, in the case where a cat is performed (reminder: tableName gives the name of the csv file but is also placed in the first cell of the table).