Main Page | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Globals

file.h

Go to the documentation of this file.
00001 
00008 template<class _InIt> inline
00009 void binary_read(_InIt _First, _InIt _Last, const string _Filename, const int _Seek)
00010 {
00011         ifstream is(_Filename.c_str(), ios::binary);
00012         is.seekg(_Seek * sizeof(*_First));
00013         is.read((char*)&*_First, streamsize(_Last - _First) * sizeof(*_First));
00014         is.close();
00015 }
00016 
00023 template<class _InIt> inline
00024 void binary_write(_InIt _First, _InIt _Last, const string _Filename)
00025 {
00026         ofstream os(_Filename.c_str(), ios::binary);
00027         os.write((char*)&*_First, streamsize(_Last - _First) * sizeof(*_First));
00028         os.close();
00029 }
00030 
00036 template<class T>
00037 void read_header(const string &_root, vector<T> &_hdr)
00038 {
00039         _hdr.assign(8, 0);
00040         binary_read(_hdr.begin(), _hdr.end(), _root + "Header.bin", 0);
00041 
00042         T magic = _hdr[0];
00043         T version = _hdr[1];
00044         T gnumelem = _hdr[2];
00045         T elemsize = _hdr[3];
00046         T gnumnode = _hdr[4];
00047         T nodesize = _hdr[5];
00048         T gnumdir = _hdr[6];
00049         T dirsize = _hdr[7];
00050 
00051         int rank;
00052         network::rank(rank);
00053         if(rank == 0)
00054         {
00055                 cout << "Magic: " << magic << " Version: " << version << endl;
00056                 cout << "Elements: " << gnumelem << " Size: " << elemsize << endl;
00057                 cout << "Nodes: " << gnumnode << " Size: " << nodesize << endl;
00058                 cout << "Dirichlet: " << gnumdir << " Size: " << dirsize << endl;
00059         }
00060 }
00061 
00068 template<class T>
00069 void read_partition(const string &_root, const vector<T> &_hdr, vector<T> &_par)
00070 {
00071         T gnumelem = _hdr[2];
00072 
00073         int size, rank;
00074         network::size(size);
00075         network::rank(rank);
00076         int poselem = (rank * gnumelem)/size;
00077         int numelem = (rank * gnumelem + gnumelem)/size - poselem;
00078 
00079         _par.assign(numelem, 0);
00080         stringstream s;
00081         s << _root << "Partition" << size << ".bin";
00082         binary_read(_par.begin(), _par.end(), s.str(), poselem);
00083 }
00084 
00092 template<class T>
00093 void read_connection(const string &_root, const vector<T> &_hdr, const vector<T> &_par, vector<T> &_con)
00094 {
00095         T gnumelem = _hdr[2];
00096         T elemsize = _hdr[3];
00097 
00098         int size, rank;
00099         network::size(size);
00100         network::rank(rank);
00101         int poselem = (rank * gnumelem)/size;
00102         int numelem = (rank * gnumelem + gnumelem)/size - poselem;
00103         vector<T> con(numelem * elemsize);
00104         binary_read(con.begin(), con.end(), _root + "Connection.bin", poselem * elemsize);
00105 
00106         vector<int> slen(size);
00107         vector<int> soff(size);
00108         vector<T> scon(numelem * elemsize);
00109         bucket_sort_count(_par, slen);
00110         bucket_sort_offset(slen, soff);
00111         bucket_sort_copy(_par, con, scon, soff, elemsize);
00112 
00113         vector<int> rlen(size);
00114         vector<int> roff(size);
00115         network::alltoall(&slen[0], sizeof(int), &rlen[0], sizeof(int));
00116         bucket_sort_offset(rlen, roff);
00117         int rnumelem = bucket_sort_size(rlen);
00118         _con.assign(rnumelem * elemsize, 0);
00119 
00120         for(int i = 0; i < (int)slen.size(); i++) slen[i] *= elemsize * sizeof(T), soff[i] *= elemsize * sizeof(T);
00121         for(int i = 0; i < (int)slen.size(); i++) rlen[i] *= elemsize * sizeof(T), roff[i] *= elemsize * sizeof(T);
00122         network::alltoallv(&scon[0], &slen[0], &soff[0], &_con[0], &rlen[0], &roff[0]);
00123 }
00124 
00132 template<class T, class S>
00133 void read_element(const string &_root, const vector<T> &_hdr, const vector<T> &_par, vector<S> &_ele)
00134 {
00135         T gnumelem = _hdr[2];
00136         T elemsize = _hdr[3];
00137 
00138         int size, rank;
00139         network::size(size);
00140         network::rank(rank);
00141         int poselem = (rank * gnumelem)/size;
00142         int numelem = (rank * gnumelem + gnumelem)/size - poselem;
00143         vector<S> ele(numelem * elemsize * elemsize);
00144         binary_read(ele.begin(), ele.end(), _root + "Element.bin", poselem * elemsize * elemsize);
00145 
00146         vector<int> slen(size);
00147         vector<int> soff(size);
00148         vector<S> sele(numelem * elemsize * elemsize);
00149         bucket_sort_count(_par, slen);
00150         bucket_sort_offset(slen, soff);
00151         bucket_sort_copy(_par, ele, sele, soff, elemsize * elemsize);
00152 
00153         vector<int> rlen(size);
00154         vector<int> roff(size);
00155         network::alltoall(&slen[0], sizeof(int), &rlen[0], sizeof(int));
00156         bucket_sort_offset(rlen, roff);
00157         int rnumelem = bucket_sort_size(rlen);
00158         _ele.assign(rnumelem * elemsize * elemsize, 0.0);
00159 
00160         for(int i = 0; i < (int)slen.size(); i++) slen[i] *= elemsize * elemsize * sizeof(S), soff[i] *= elemsize * elemsize * sizeof(S);
00161         for(int i = 0; i < (int)slen.size(); i++) rlen[i] *= elemsize * elemsize * sizeof(S), roff[i] *= elemsize * elemsize * sizeof(S);
00162         network::alltoallv(&sele[0], &slen[0], &soff[0], &_ele[0], &rlen[0], &roff[0]);
00163 }

Generated on Wed Apr 26 17:41:45 2006 for Parallel Toolbox by  doxygen 1.4.2