45 #ifndef DOXYGEN_SHOULD_SKIP_THIS
54 const char* material,
const char* timelevel,
55 const char* mfile_pre = NULL,
const MPI_Comm* pComm = NULL,
56 const int* pane_id = NULL,
int append = -1,
74 #define SwitchOnDataType(dType, funcCall) \
81 case COM_UNSIGNED_CHAR: \
82 { typedef unsigned char TT; \
89 case COM_UNSIGNED_SHORT: \
90 { typedef unsigned short TT; \
98 { typedef unsigned int TT; \
105 case COM_UNSIGNED_LONG: \
106 { typedef unsigned long TT; \
110 { typedef float TT; \
114 { typedef double TT; \
117 case COM_LONG_DOUBLE: \
118 { typedef long double TT; \
123 #define ERROR_MSG(msg) \
124 { if (_options["errorhandle"] != "ignore") { \
125 std::cerr << msg << std::endl; \
126 if (_options["errorhandle"] == "abort") { \
127 if (COMMPI_Initialized()) \
128 MPI_Abort(MPI_COMM_WORLD, 0); \
137 #endif // USE_PTHREADS
155 rout->
_options[
"errorhandle"] =
"abort";
157 rout->
_options[
"ghosthandle"] =
"write";
161 std::string glb=mname+
".global";
172 glb.c_str(),
"biiiiIII", types);
175 glb.c_str(),
"biiiiIII", types);
178 glb.c_str(),
"biiiiIII", types);
180 (Member_func_ptr)&Rocout::write_attribute,
181 glb.c_str(),
"biiiiIII", types);
187 glb.c_str(),
"biii", types);
192 glb.c_str(),
"b", types);
197 glb.c_str(),
"bii", types);
203 glb.c_str(),
"biiI", types);
208 glb.c_str(),
"bi", types);
215 std::string glb=mname+
".global";
224 std::vector<pthread_t>::iterator p = rout->_writers.begin();
225 while (p != rout->_writers.end()) {
226 pthread_join(*p, &ret);
229 # endif // USE_PTHREADS
247 const Attribute* attr,
const char* material,
248 const char* timelevel,
const char* mfile_pre,
249 const MPI_Comm* pComm,
const int* pane_id)
255 #endif // USE_PTHREADS
256 pWAI =
new WriteAttrInfo(
this, filename_pre, attr, material, timelevel,
257 mfile_pre, pComm, pane_id);
261 pWAI =
new WriteAttrInfo(
this, filename_pre, attr, material, timelevel,
262 mfile_pre, pComm, pane_id, -1,
true);
264 pthread_attr_init(&attr);
265 pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
269 pthread_attr_destroy(&attr);
270 _writers.push_back(
id);
272 #endif // USE_PTHREADS
287 const Attribute* attr,
const char* material,
288 const char* timelevel,
const char* mfile_pre,
289 const MPI_Comm* pComm,
const int* pane_id)
298 #endif // USE_PTHREADS
299 pWAI =
new WriteAttrInfo(
this, filename_pre, attr, material, timelevel,
300 mfile_pre, pComm, pane_id, 0);
304 pWAI =
new WriteAttrInfo(
this, filename_pre, attr, material, timelevel,
305 mfile_pre, pComm, pane_id, 0,
true);
307 pthread_attr_init(&attr);
308 pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
312 pthread_attr_destroy(&attr);
313 _writers.push_back(
id);
315 #endif // USE_PTHREADS
330 const Attribute* attr,
const char* material,
331 const char* timelevel,
const char* mfile_pre,
332 const MPI_Comm* pComm,
const int* pane_id)
341 #endif // USE_PTHREADS
342 pWAI =
new WriteAttrInfo(
this, filename_pre, attr, material, timelevel,
343 mfile_pre, pComm, pane_id, 1);
347 pWAI =
new WriteAttrInfo(
this, filename_pre, attr, material, timelevel,
348 mfile_pre, pComm, pane_id, 1,
true);
350 pthread_attr_init(&attr);
351 pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
355 pthread_attr_destroy(&attr);
356 _writers.push_back(
id);
358 #endif // USE_PTHREADS
362 const char* file_prefixes,
363 const char* control_file_name)
366 const MPI_Comm comm_null = MPI_COMM_NULL;
371 int flag = 0,
rank = 0, size = 1;
372 MPI_Initialized(&flag);
375 MPI_Comm_rank(*myComm, &
rank);
376 MPI_Comm_size(*myComm, &size);
380 std::vector<std::vector<int> >
paneIds(size);
384 for (i=0; i<size; ++
i)
429 std::ofstream fout(control_file_name);
431 (std::string(
"Rocout cannot open control file:")+control_file_name+
" for writing.\n").c_str());
433 const std::string fmt =
_options[
"format"];
434 for (i=0; i<size; i++) {
435 fout <<
"@Proc: " << i << std::endl;
436 if ( !paneIds[i].
empty()) {
437 std::ostringstream sout;
441 std::istringstream
sin(file_prefixes);
451 std::ostringstream rank_prefix;
452 rank_prefix << i <<
"/";
453 sout << rank_prefix.str();
457 sout <<
"%0" << rw <<
'p';
461 sout <<
"%0" << pw <<
'i';
464 if ( fmt ==
"HDF4" || fmt ==
"HDF")
466 else if (fmt ==
"HDF5")
468 else if (fmt ==
"CGNS")
471 fout << sout.str() << std::endl;
474 fout <<
"@Files: " << std::endl;
479 std::vector<int>::iterator p;
480 for (p=paneIds[i].begin(); p!=paneIds[
i].end(); ++p)
482 fout <<
'\n' << std::endl;
495 std::vector<pthread_t>::iterator p = _writers.begin();
496 while (p != _writers.end()) {
497 pthread_join(*p, &ret);
501 #endif // USE_PTHREADS
508 return (name ==
"format" || name ==
"async" || name ==
"mode"
509 || name ==
"localdir" || name ==
"rankwidth" || name ==
"pnidwidth"
510 || name ==
"separator" || name ==
"errorhandle" || name ==
"rankdir"
511 || name ==
"ghosthandle");
520 std::istringstream
sin(s);
523 return (i >= 0 && sin.eof());
530 return ((name ==
"format"
531 && (val ==
"HDF" || val ==
"HDF4" || val ==
"HDF5" || val ==
"CGNS"))
533 && (val ==
"on" || val ==
"off"))
535 && (val ==
"w" || val ==
"a"))
536 || (name ==
"localdir" )
537 || ((name ==
"rankwidth" || name ==
"pnidwidth") &&
is_whole(val))
538 || (name ==
"rankdir"
539 && (val ==
"on" || val ==
"off"))
540 || (name ==
"errorhandle"
541 && (val ==
"abort" || val ==
"ignore" || val ==
"warn"))
542 || (name ==
"ghosthandle"
543 && (val ==
"write" || val ==
"ignore")));
554 const std::string name(option_name);
555 const std::string val(option_val);
558 ERROR_MSG(
"Rocout::set_option(): unknown option name \"" << name <<
"\".");
563 ERROR_MSG(
"Rocout::set_option(): invalid value \"" << val
564 <<
"\" for option \"" << name <<
"\".");
570 "Roccom not built with option CGNS=1.\n");
583 std::ifstream fin(filename);
584 if (!fin.is_open()) {
585 ERROR_MSG(
"Rocout::read_control_file(): could not open file \""
586 << filename <<
"\".");
596 std::string line, name, val;
597 std::string::size_type eq;
601 fin.getline(buffer,
sizeof(buffer));
605 if (line.empty() || line.find_first_not_of(
" \t\n") == std::string::npos
606 || line[line.find_first_not_of(
" \t\n")] ==
'#')
611 if (eq == std::string::npos) {
612 ERROR_MSG(
"Rocout::read_control_file(): option without value at line "
613 << lineNum <<
" of " << filename <<
'.');
618 name = line.substr(0, eq);
619 val = line.substr(eq + 1);
622 if (name.find_first_not_of(
" \t\n") != 0)
623 name.erase(0, name.find_first_not_of(
" \t\n"));
627 ERROR_MSG(
"Rocout::read_control_file(): missing option name at line "
628 << lineNum <<
" of " << filename <<
'.');
633 if (name.find_last_not_of(
" \t\n") != name.length() - 1)
634 name.erase(name.find_last_not_of(
" \t\n") + 1);
638 ERROR_MSG(
"Rocout::read_control_file(): unknown option name \"" << name
639 <<
"\" at line " << lineNum <<
" of " << filename <<
'.');
644 if (val.find_first_not_of(
" \t\n") != 0)
645 val.erase(0, val.find_first_not_of(
" \t\n"));
649 ERROR_MSG(
"Rocout::read_control_file(): option without value at line "
650 << lineNum <<
" of " << filename <<
'.');
655 if (val.find_last_not_of(
" \t\n") != val.length() - 1)
656 val.erase(val.find_last_not_of(
" \t\n") + 1);
660 ERROR_MSG(
"Rocout::read_control_file(): invalid value \"" << val
661 <<
"\" for option \"" << name <<
"\" at line " << lineNum
662 <<
" of " << filename <<
'.');
679 #endif // USE_PTHREADS
682 attr = tempWin->
inherit(const_cast<Attribute*>(attr), attr->
name(),
686 int flag = 0; MPI_Initialized(&flag);
692 const MPI_Comm* pComm;
701 if (*pComm != MPI_COMM_NULL)
702 MPI_Comm_rank(*pComm, &rank);
723 std::vector<int>::iterator begin = paneIds.begin(), end = paneIds.end(), p;
725 begin = std::find(begin, end, *(ai->
m_pPaneId));
776 std::set<std::string> written;
777 for (p=begin; p!=end; ++p) {
780 std::string fname, mfile;
786 int ap = append + written.count(fname);
787 written.insert(fname);
790 if ( fmt ==
"HDF4" || fmt ==
"HDF") {
796 }
else if ( fmt ==
"CGNS") {
810 #endif // USE_PTHREADS
831 std::string pre(
_options[
"localdir"]);
834 if (prefix[0] ==
'/') {
835 if (pre[pre.length()-1] ==
'/')
836 pre.erase(pre.length() - 1);
838 if (pre[pre.length()-1] !=
'/')
845 std::ostringstream rank_prefix;
846 rank_prefix <<
"/" <<
rank;
847 std::string::size_type
s = pre.find_last_of(
'/');
848 if (s != std::string::npos)
849 pre.insert(s, rank_prefix.str());
854 std::string::size_type
s = pre.find(
'/', 1);
855 while (s != std::string::npos) {
856 result = mkdir(pre.substr(0, s).c_str(), 0755);
857 s = pre.find(
'/', s + 1);
859 if (result < 0 && errno != EEXIST) {
860 ERROR_MSG(
"Rocout::write_attribute(): could not create directory '"
861 << pre.substr(0, pre.rfind(
'/') + 1) <<
"'.");
864 if ( pre.find(
".hdf") == pre.size()-4) {
868 else if (pre.find(
".cgns") == pre.size()-5) {
875 MPI_Initialized(&flag);
895 std::ostringstream sout;
898 sout << std::setw(rw) << std::setfill(
'0') <<
rank;
899 if (pw > 0 && paneId > 0) {
902 sout << std::setw(pw) << std::setfill(
'0') << paneId;
905 const std::string fmt =
_options[
"format"];
906 if ( fmt ==
"HDF" || fmt ==
"HDF4")
908 else if (fmt ==
"HDF5")
910 else if (fmt ==
"CGNS")
917 if ((f =
std::fopen(name.c_str(),
"r")) != NULL)
919 else if ((f =
std::fopen(name.c_str(),
"w")) != NULL) {
921 std::remove(name.c_str());
924 std::string::size_type
n = name.rfind(
'/');
925 if (n != std::string::npos)
926 name.erase(0, n + 1);
940 #ifndef DOXYGEN_SHOULD_SKIP_THIS
943 extern "C" void COM_F_FUNC2(rocout_load_module, ROCOUT_LOAD_MODULE)(
const char *name,
long int length)
945 extern "C" void COM_F_FUNC2(rocout_unload_module, ROCOUT_UNLOAD_MODULE)(
const char *name,
long int length)
948 #endif // DOXYGEN_SHOULD_SKIP_THIS
std::string get_fname(const std::string &pre, int rank=-1, const int paneId=0, bool check=false)
Builds a filename from the given prefix and rank.
int COM_Type
Indices for derived data types.
static void finalize(const std::string &mname)
Finalize the module by deregistering it from Roccom.
here we put it at the!beginning of the common block The point to point and collective!routines know about but MPI_TYPE_STRUCT as yet does not!MPI_STATUS_IGNORE and MPI_STATUSES_IGNORE are similar objects!Until the underlying MPI library implements the C version of these are declared as arrays of MPI_STATUS_SIZE!The types and are OPTIONAL!Their values are zero if they are not available Note that!using these reduces the portability of MPI_IO INTEGER MPI_BOTTOM INTEGER MPI_DOUBLE_PRECISION INTEGER MPI_LOGICAL INTEGER MPI_2REAL INTEGER MPI_2DOUBLE_COMPLEX INTEGER MPI_LB INTEGER MPI_WTIME_IS_GLOBAL INTEGER MPI_COMM_WORLD
void write_parameter_file(const char *file_name, const char *window_name, const MPI_Comm *comm=NULL)
Write out the parameters defined in the fiven window into a parameter file.
void set_option(const char *option_name, const char *option_val)
Set an option for Rocout, such as controlling the output format.
Pass write_attribute arguments to the background worker thread.
here we put it at the!beginning of the common block The point to point and collective!routines know about but MPI_TYPE_STRUCT as yet does not!MPI_STATUS_IGNORE and MPI_STATUSES_IGNORE are similar objects!Until the underlying MPI library implements the C version of these are declared as arrays of MPI_STATUS_SIZE!The types and are OPTIONAL!Their values are zero if they are not available Note that!using these reduces the portability of MPI_IO INTEGER MPI_BOTTOM INTEGER MPI_DOUBLE_PRECISION INTEGER MPI_LOGICAL INTEGER MPI_2REAL INTEGER MPI_2DOUBLE_COMPLEX INTEGER MPI_LB INTEGER MPI_WTIME_IS_GLOBAL INTEGER MPI_COMM_SELF
const std::string m_timelevel
static bool is_whole(const std::string &s)
An Attribute object is a data member of a window.
void COM_delete_window(const char *wname)
#define COM_assertion_msg(EX, msg)
void put_attribute(const char *filename_pre, const COM::Attribute *attr, const char *material, const char *timelevel, const char *mfile_pre=NULL, const MPI_Comm *comm=NULL, const int *pane_id=NULL)
Write a (possibly aggregate) attribute to a new file.
Declaration of Rocout CGNS routines.
A Window object contains multiple panes and multiple data attributes.
static void * write_attr_internal(void *attrInfo)
Does the actual writing to file.
boolean empty(T_VertexSet s)
const std::string m_prefix
void add_attribute(const char *filename_pre, const COM::Attribute *attr, const char *material, const char *timelevel, const char *mfile_pre=NULL, const MPI_Comm *comm=NULL, const int *pane_id=NULL)
Append a (possibly aggregate) attribute to a file.
const std::string & name() const
Obtain the window's name.
void COM_set_object(const char *wa_str, int pane_id, Type *addr)
WriteAttrInfo(Rocout *rout, const char *filename_pre, const Attribute *attr, const char *material, const char *timelevel, const char *mfile_pre=NULL, const MPI_Comm *pComm=NULL, const int *pane_id=NULL, int append=-1, bool cloned=false)
int fclose(std::FILE *file)
Close a file, and check for possible errors.
const Window * window() const
Obtain a constant pointer to the parent window of the attribute.
static bool is_option_name(const std::string &name)
Return true if the given string is the name of a Rocout option.
void write_attr_CGNS(const std::string &fname, const std::string &mfile, const COM::Attribute *attr, const char *material, const char *timelevel, int pane_id, const std::string &ghosthandle, const std::string &errorhandle, int mode)
Write the data for the given attribute to file.
#define COM_F_FUNC2(lowcase, uppercase)
void write_attribute(const char *filename_pre, const COM::Attribute *attr, const char *material, const char *timelevel, const char *mfile_pre=NULL, const MPI_Comm *comm=NULL, const int *pane_id=NULL)
Write a (possibly aggregate) attribute to a file.
double length(Vector3D *const v, int n)
void COM_get_object(const char *wa_str, int pane_id, Type **addr)
Rocout creates a series of Roccom windows by reading in a list of files.
static void init()
Create and start the I/O thread.
MPI_Comm get_communicator() const
Obtain the communicator of the window.
void sync()
Wait for the completion of an asychronous write operation.
std::map< std::string, std::string > _options
void COM_window_init_done(const char *w_str, int pane_changed=true)
static bool is_option_value(const std::string &name, const std::string &val)
Return true if the given Rocout option name/value pair is valid.
static void init(const std::string &mname)
Initialize the module by registering it to Roccom with the given module name.
void COM_new_window(const char *wname, MPI_Comm c=MPI_COMM_NULL)
void write_rocin_control_file(const char *window_name, const char *file_prefixes, const char *control_file_name)
Generate a control file for Rocin.
static void finalize()
Destroy the I/O thread.
void Rocout_load_module(const char *name)
Load the module Rocout into Roccom using the given module name.
unsigned long id(const Leda_like_handle &x)
void COM_new_attribute(const char *wa_str, const char loc, const int type, int ncomp, const char *unit)
Registering an attribute type.
void COM_get_panes(const char *wname, std::vector< int > &pane_ids, int rank=-2)
void COM_set_member_function(const char *wf_str, Member_func_ptr func, const char *wa_str, const char *intents, const COM_Type *types)
MPI_Comm COM_get_default_communicator()
void write_attr_HDF4(const std::string &fname, const std::string &mfile, const COM::Attribute *attr, const char *material, const char *timelevel, int pane_id, const std::string &errorhandle, int mode)
void read_control_file(const char *filename)
Set options for Rocout via a control file.
static USE_COM_NAME_SPACE const int MAX_ASYNC_WRITES
const std::string m_material
const std::string m_meshPrefix
std::FILE * fopen(const char *const path, const char *const mode)
Open a file, and check for possible errors.
void Rocout_unload_module(const char *name)
Unload the module Rocout from Roccom.
Attribute * inherit(Attribute *from, const std::string &aname, int inherit_mode, bool withghost, const Attribute *cond, int val)
Inherit the attributes of another window with a different name.
std::vector< int > paneIds
Array of paneIds.