MPI使ってるときにルートプロセスだけ cout で情報を出力するように cout をのっとってみた.副作用として iomanip がどうやって処理されているかを身をもって知る羽目になった(一番下のテンプレート定義だけだとうまくコンパイルできなかった...)
class myOstream : public std::ostream {
public:
// for iomanip
myOstream&
operator<<(__ostream_type& (*manip)(__ostream_type&
if(rank==0) std::cout << manip;
return *this;
}
myOstream&
operator<<(__ios_type& (*manip)(__ios_type&)){
if(rank==0) std::cout << manip;
return *this;
}
myOstream&
operator<<(ios_base& (*manip) (ios_base&)){
if(rank==0) std::cout << manip;
return *this;
}
// for other types
template <typename C>
myOstream& operator<<(const C&v){
if(rank==0) std::cout << v;
return *this;
}
};
muOstream cout;
型を決定できないのかねぇ.ちゃんと書いといてやらんと.
- Newer: AWK - はじめ