file.h
//
// file.h
//
// Copyright (C) 1996 Limit Point Systems, Inc.
//
// Author: Curtis Janssen <cljanss@limitpt.com>
// Maintainer: LPS
//
// This file is part of the SC Toolkit.
//
// The SC Toolkit is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
//
// The SC Toolkit is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
//
// The U.S. Government is granted a limited license as per AL 91-7.
//
#ifdef __GNUC__
#pragma interface
#endif
#ifndef _util_group_file_h
#define _util_group_file_h
#include <iostream>
#include <scconfig.h>
#include <util/class/class.h>
#include <util/group/thread.h>
#include <util/group/memory.h>
namespace sc {
class FileGrp: public DescribedClass {
private:
int datafile_;
char *filename_;
Ref<ThreadLock> *locks_;
int nlock_;
void init_locks();
protected:
// derived classes must fill in all these
// ~FileGrp deletes the arrays
int me_;
int n_;
distsize_t *offsets_; // offsets_[n_] is the fence for all data
// set to nonzero for debugging information
int debug_;
void obtain_local_lock(size_t start, size_t fence);
void release_local_lock(size_t start, size_t fence);
public:
FileGrp();
FileGrp(const Ref<KeyVal>&);
virtual ~FileGrp();
void open();
void close();
void set_filename(char *name);
const char* get_filename() const { return datafile_; };
int me() const { return me_; }
int n() const { return n_; }
virtual void set_localsize(size_t) = 0;
size_t localsize() { return distsize_to_size(offsets_[me_+1]-offsets_[me_]); }
distsize_t localoffset() { return offsets_[me_]; }
int size(int node)
{ return distsize_to_size(offsets_[node+1] - offsets_[node]); }
distsize_t offset(int node) { return offsets_[node]; }
distsize_t totalsize() { return offsets_[n_]; }
virtual void activate();
virtual void deactivate();
virtual void *obtain_writeonly(distsize_t offset, int size) = 0;
virtual void *obtain_readwrite(distsize_t offset, int size) = 0;
virtual void *obtain_readonly(distsize_t offset, int size) = 0;
virtual void release_readonly(void *data, distsize_t offset, int size) = 0;
virtual void release_writeonly(void *data, distsize_t offset, int size)=0;
virtual void release_readwrite(void *data, distsize_t offset, int size)=0;
virtual void sum_reduction(double *data, distsize_t doffset, int dsize);
virtual void sum_reduction_on_node(double *data, size_t doffset, int dsize,
int node = -1);
virtual void sync() = 0;
virtual void catchup();
virtual void print(std::ostream &o = ExEnv::out0()) const;
static FileGrp* initial_filegrp(int &argc, char** argv);
static FileGrp* initial_filegrp();
static void set_default_filegrp(const Ref<FileGrp>&);
static FileGrp* get_default_filegrp();
virtual FileGrp* clone() =0;
};
}
#endif
// Local Variables:
// mode: c++
// c-file-style: "CLJ"
// End: