11 #include <stk_util/parallel/ParallelInputStream.hpp> 18 #if defined( STK_HAS_MPI ) 21 { MPI_Bcast( buf , n , MPI_BYTE , 0 , comm ); }
39 class ParInBuf :
public std::streambuf {
41 enum { BUFFER_LENGTH = 0x010000 };
42 enum { BUFFER_PUTBACK = 0x000010 };
43 enum { MAX_READ = BUFFER_LENGTH - BUFFER_PUTBACK };
48 virtual int underflow();
49 virtual int overflow(
int c = EOF );
51 virtual std::streambuf * setbuf(
char * , std::streamsize );
58 std::FILE * m_root_fp ;
59 char m_buffer[ BUFFER_LENGTH ];
62 ParInBuf::ParInBuf(
ParallelMachine comm ,
const char *
const file_name )
63 : m_comm( comm ), m_root_fp( NULL )
68 result = NULL != ( m_root_fp = std::fopen( file_name ,
"r" ) );
71 broadcast( m_comm , & result ,
sizeof(
int) );
75 msg.append(
"stk_classic::ParallelInputStream( " );
77 msg.append( file_name );
80 msg.append(
"<NULL>" );
82 msg.append(
" ) FAILED" );
83 throw std::runtime_error(msg);
87 void ParInBuf::close()
89 if ( NULL != m_root_fp ) { std::fclose( m_root_fp ); m_root_fp = NULL ; }
96 int ParInBuf::underflow()
98 char *
const buf = m_buffer + BUFFER_PUTBACK ;
101 if ( gptr() == NULL || egptr() <= gptr() ) {
102 if ( NULL != m_root_fp ) { nread = std::fread(buf,1,MAX_READ,m_root_fp); }
103 broadcast( m_comm , & nread ,
sizeof(
int) );
107 broadcast( m_comm , buf , nread );
108 setg( m_buffer , buf , buf + nread );
114 return 0 < nread ? *buf : EOF ;
119 void throw_overflow()
122 msg.append(
"stk_classic::ParallelInputStream::overflow CALL IS ERRONEOUS" );
123 throw std::runtime_error(msg);
128 int ParInBuf::overflow(
int )
129 { throw_overflow();
return EOF ; }
134 std::streambuf * ParInBuf::setbuf(
char * , std::streamsize )
144 ParallelInputStream::ParallelInputStream(
146 const char *
const file_name )
147 :
std::istream( new ParInBuf( comm , file_name ) )
150 ParallelInputStream::~ParallelInputStream()
unsigned parallel_machine_rank(ParallelMachine parallel_machine)
Member function parallel_machine_rank ...