MPQC 2.3.1
|
00001 // 00002 // file.h 00003 // 00004 // Copyright (C) 1996 Limit Point Systems, Inc. 00005 // 00006 // Author: Curtis Janssen <cljanss@limitpt.com> 00007 // Maintainer: LPS 00008 // 00009 // This file is part of the SC Toolkit. 00010 // 00011 // The SC Toolkit is free software; you can redistribute it and/or modify 00012 // it under the terms of the GNU Library General Public License as published by 00013 // the Free Software Foundation; either version 2, or (at your option) 00014 // any later version. 00015 // 00016 // The SC Toolkit is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU Library General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU Library General Public License 00022 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to 00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 00024 // 00025 // The U.S. Government is granted a limited license as per AL 91-7. 00026 // 00027 00028 #ifdef __GNUC__ 00029 #pragma interface 00030 #endif 00031 00032 #ifndef _util_group_file_h 00033 #define _util_group_file_h 00034 00035 #include <iostream> 00036 00037 #include <scconfig.h> 00038 #include <util/class/class.h> 00039 #include <util/group/thread.h> 00040 #include <util/group/memory.h> 00041 00042 namespace sc { 00043 00055 class FileGrp: public DescribedClass { 00056 private: 00057 int datafile_; 00058 char *filename_; 00059 00060 Ref<ThreadLock> *locks_; 00061 int nlock_; 00062 00063 void init_locks(); 00064 00065 00066 protected: 00067 00068 // derived classes must fill in all these 00069 // ~FileGrp deletes the arrays 00070 int me_; 00071 int n_; 00072 distsize_t *offsets_; // offsets_[n_] is the fence for all data 00073 00074 // set to nonzero for debugging information 00075 int debug_; 00076 00077 void obtain_local_lock(size_t start, size_t fence); 00078 void release_local_lock(size_t start, size_t fence); 00079 public: 00080 FileGrp(); 00081 FileGrp(const Ref<KeyVal>&); 00082 virtual ~FileGrp(); 00083 00085 void open(); 00087 void close(); 00089 void set_filename(char *name); 00091 const char* get_filename() const { return datafile_; }; 00092 00094 int me() const { return me_; } 00096 int n() const { return n_; } 00097 00101 virtual void set_localsize(size_t) = 0; 00103 size_t localsize() { return distsize_to_size(offsets_[me_+1]-offsets_[me_]); } 00105 distsize_t localoffset() { return offsets_[me_]; } 00107 int size(int node) 00108 { return distsize_to_size(offsets_[node+1] - offsets_[node]); } 00110 distsize_t offset(int node) { return offsets_[node]; } 00112 distsize_t totalsize() { return offsets_[n_]; } 00113 00115 virtual void activate(); 00117 virtual void deactivate(); 00118 00120 virtual void *obtain_writeonly(distsize_t offset, int size) = 0; 00126 virtual void *obtain_readwrite(distsize_t offset, int size) = 0; 00128 virtual void *obtain_readonly(distsize_t offset, int size) = 0; 00130 virtual void release_readonly(void *data, distsize_t offset, int size) = 0; 00132 virtual void release_writeonly(void *data, distsize_t offset, int size)=0; 00135 virtual void release_readwrite(void *data, distsize_t offset, int size)=0; 00136 00137 virtual void sum_reduction(double *data, distsize_t doffset, int dsize); 00138 virtual void sum_reduction_on_node(double *data, size_t doffset, int dsize, 00139 int node = -1); 00140 00143 virtual void sync() = 0; 00144 00151 virtual void catchup(); 00152 00154 virtual void print(std::ostream &o = ExEnv::out0()) const; 00155 00163 static FileGrp* initial_filegrp(int &argc, char** argv); 00164 static FileGrp* initial_filegrp(); 00167 static void set_default_filegrp(const Ref<FileGrp>&); 00169 static FileGrp* get_default_filegrp(); 00171 virtual FileGrp* clone() =0; 00172 }; 00173 00174 } 00175 00176 #endif 00177 00178 // Local Variables: 00179 // mode: c++ 00180 // c-file-style: "CLJ" 00181 // End: