MPQC 3.0.0-alpha
Loading...
Searching...
No Matches
file.h
1//
2// file.h
3//
4// Copyright (C) 1996 Limit Point Systems, Inc.
5//
6// Author: Curtis Janssen <cljanss@limitpt.com>
7// Maintainer: LPS
8//
9// This file is part of the SC Toolkit.
10//
11// The SC Toolkit is free software; you can redistribute it and/or modify
12// it under the terms of the GNU Library General Public License as published by
13// the Free Software Foundation; either version 2, or (at your option)
14// any later version.
15//
16// The SC Toolkit is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Library General Public License for more details.
20//
21// You should have received a copy of the GNU Library General Public License
22// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24//
25// The U.S. Government is granted a limited license as per AL 91-7.
26//
27
28#ifndef _util_group_file_h
29#define _util_group_file_h
30
31#include <iostream>
32
33#include <mpqc_config.h>
34#include <util/class/class.h>
35#include <util/group/thread.h>
36#include <util/group/memory.h>
37
38namespace sc {
39
51class FileGrp: public DescribedClass {
52 private:
53 int datafile_;
54 char *filename_;
55
56 Ref<ThreadLock> *locks_;
57 int nlock_;
58
59 void init_locks();
60
61
62 protected:
63
64 // derived classes must fill in all these
65 // ~FileGrp deletes the arrays
66 int me_;
67 int n_;
68 distsize_t *offsets_; // offsets_[n_] is the fence for all data
69
70 // set to nonzero for debugging information
71 int debug_;
72
73 void obtain_local_lock(size_t start, size_t fence);
74 void release_local_lock(size_t start, size_t fence);
75 public:
76 FileGrp();
77 FileGrp(const Ref<KeyVal>&);
78 virtual ~FileGrp();
79
81 void open();
83 void close();
85 void set_filename(char *name);
87 const char* get_filename() const { return datafile_; };
88
90 int me() const { return me_; }
92 int n() const { return n_; }
93
97 virtual void set_localsize(size_t) = 0;
99 size_t localsize() { return distsize_to_size(offsets_[me_+1]-offsets_[me_]); }
101 distsize_t localoffset() { return offsets_[me_]; }
103 int size(int node)
104 { return distsize_to_size(offsets_[node+1] - offsets_[node]); }
106 distsize_t offset(int node) { return offsets_[node]; }
108 distsize_t totalsize() { return offsets_[n_]; }
109
111 virtual void activate();
113 virtual void deactivate();
114
116 virtual void *obtain_writeonly(distsize_t offset, int size) = 0;
122 virtual void *obtain_readwrite(distsize_t offset, int size) = 0;
124 virtual void *obtain_readonly(distsize_t offset, int size) = 0;
126 virtual void release_readonly(void *data, distsize_t offset, int size) = 0;
128 virtual void release_writeonly(void *data, distsize_t offset, int size)=0;
131 virtual void release_readwrite(void *data, distsize_t offset, int size)=0;
132
133 virtual void sum_reduction(double *data, distsize_t doffset, int dsize);
134 virtual void sum_reduction_on_node(double *data, size_t doffset, int dsize,
135 int node = -1);
136
139 virtual void sync() = 0;
140
147 virtual void catchup();
148
150 virtual void print(std::ostream &o = ExEnv::out0()) const;
151
159 static FileGrp* initial_filegrp(int &argc, char** argv);
160 static FileGrp* initial_filegrp();
167 virtual FileGrp* clone() =0;
168};
169
170}
171
172#endif
173
174// Local Variables:
175// mode: c++
176// c-file-style: "CLJ"
177// End:
Classes which need runtime information about themselves and their relationship to other classes can v...
Definition class.h:233
static std::ostream & out0()
Return an ostream that writes from node 0.
The FileGrp abstract class provides a way of accessing distributed file in a parallel machine.
Definition file.h:51
virtual void release_readonly(void *data, distsize_t offset, int size)=0
This is called when read access is no longer needed.
static FileGrp * initial_filegrp(int &argc, char **argv)
Create a file group.
virtual void release_writeonly(void *data, distsize_t offset, int size)=0
This is called when write access is no longer needed.
virtual void deactivate()
Deactivate is called after the data has been used.
virtual void * obtain_readonly(distsize_t offset, int size)=0
This gives read access to the file location. No locking is done.
virtual void * obtain_writeonly(distsize_t offset, int size)=0
This gives write access to the data location. No locking is done.
distsize_t totalsize()
Returns the sum of all data allocated on all nodes.
Definition file.h:108
int n() const
Returns how many nodes there are.
Definition file.h:92
virtual FileGrp * clone()=0
Clones the given FileGrp. The new FileGrp may need to be initialized additionally.
void open()
Opens the files.
static FileGrp * get_default_filegrp()
Returns the default file group.
int size(int node)
Returns the amount of data residing on node.
Definition file.h:103
const char * get_filename() const
Returns the filename for the FileGrp.
Definition file.h:87
static void set_default_filegrp(const Ref< FileGrp > &)
The default file group contains the primary file group to be used by an application.
virtual void sync()=0
Synchronizes all the nodes.
virtual void activate()
Activate is called before the data is to be used.
virtual void print(std::ostream &o=ExEnv::out0()) const
Prints out information about the object.
void set_filename(char *name)
Sets the filename for the FileGrp.
size_t localsize()
Returns the amount of data residing locally on me().
Definition file.h:99
distsize_t localoffset()
Returns the global offset to this node's data.
Definition file.h:101
void close()
Closes the files.
distsize_t offset(int node)
Returns the global offset to node's data.
Definition file.h:106
int me() const
Returns who I am.
Definition file.h:90
virtual void catchup()
Processes outstanding requests.
virtual void * obtain_readwrite(distsize_t offset, int size)=0
Only one thread can have an unreleased obtain_readwrite at a time.
virtual void set_localsize(size_t)=0
Set the size of locally held data.
virtual void release_readwrite(void *data, distsize_t offset, int size)=0
This is called when read/write access is no longer needed.
A template class that maintains references counts.
Definition ref.h:361
Contains all MPQC code up to version 3.
Definition mpqcin.h:14

Generated at Wed Sep 25 2024 02:45:30 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.12.0.