Skip to content

Commit

Permalink
Merge pull request #333 from dash-project/feat-globptr
Browse files Browse the repository at this point in the history
GlobPtr and global memory space concept (GlobHeapMem, GlobStaticMem, ...)
  • Loading branch information
fuchsto authored Mar 24, 2017
2 parents 289b880 + 8727b3c commit 15c107e
Show file tree
Hide file tree
Showing 52 changed files with 1,692 additions and 785 deletions.
6 changes: 5 additions & 1 deletion dash/examples/app.01.mindeg/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ int read_adj(
int read_mtx(const std::string & fname,
nodearray_t & nodes);

#if 0
int init_nodes(
nodearray_t & nodes,
std::deque<int> & xadj,
std::deque<int> & local_adj);
#endif

void get_reach(
nodearray_t & nodes,
Expand Down Expand Up @@ -283,7 +285,9 @@ int read_mtx(const std::string & fname,

// allocate memory of adjacency list in parallel
for (size_t i = 0; i < nodes.lsize(); ++i) {
nodes.local[i].adj = dash::memalloc<int>(nodes.local[i].adj_sz);
nodes.local[i].adj = dash::memalloc<int>(
nodes.globmem(),
nodes.local[i].adj_sz);
}

nodes.barrier();
Expand Down
13 changes: 8 additions & 5 deletions dash/examples/bench.04.histo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ int main(int argc, char **argv)
dash::Array<int> key_array(NUM_KEYS, dash::BLOCKED);
dash::Array<int> key_histo(MAX_KEY, dash::BLOCKED);

dash::Array<dash::GlobPtr<int>> work_buffers(size, dash::CYCLIC);
using glob_ptr_t = dash::GlobPtr< int, dash::GlobUnitMem<int> >;

dash::Array<glob_ptr_t> work_buffers(size, dash::CYCLIC);

work_buffers[myid] = dash::memalloc<int>(MAX_KEY);

dash::GlobPtr<int> gptr = work_buffers[myid];
int* work_buf = (int*) gptr;
glob_ptr_t gptr = work_buffers[myid];
int * work_buf = static_cast<int *>(gptr);

if(myid==0) {
for(int i=0; i<key_array.size(); i++ ) {
Expand Down Expand Up @@ -72,10 +75,10 @@ int main(int argc, char **argv)
}

for(int unit=1; unit<size; unit++ ) {
dash::GlobPtr<int> remote = work_buffers[(myid+unit)%size];
glob_ptr_t remote = work_buffers[(myid+unit)%size];

for(int i=0; i<key_histo.lsize(); i++ ) {
key_histo.local[i] += remote[goffs+i];
key_histo.local[i] += static_cast<int *>(remote)[goffs+i];
}
}
dash::barrier();
Expand Down
18 changes: 8 additions & 10 deletions dash/examples/ex.04.memalloc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,23 @@ int main(int argc, char* argv[])

dash::Array< dash::GlobPtr<int> > arr(size);

arr[myid] = dash::memalloc<int>(SIZE);
arr[myid] = dash::memalloc<int>(arr.globmem(), SIZE);

for(int i=0; i<SIZE; i++ ) {
for (int i = 0; i < SIZE; i++) {
dash::GlobPtr<int> ptr = arr[myid];
ptr[i]=myid;
ptr[i] = myid;
}

dash::barrier();

cout<<myid<<": ";
for(int i=0; i<SIZE; i++ ) {
dash::GlobPtr<int> ptr = arr[(myid+1)%size];
cout<<(int)ptr[i]<<" ";
cout << myid << ": ";
for (int i = 0; i < SIZE; i++) {
dash::GlobPtr<int> ptr = arr[(myid+1) % size];
cout << (int)ptr[i] << " ";
}
cout<<endl;
cout << endl;

dash::barrier();

//dash::memfree(arr[myid]);

dash::finalize();
}
4 changes: 2 additions & 2 deletions dash/include/dash/Allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define DASH__ALLOCATOR_H__INCLUDED

#include <dash/allocator/LocalAllocator.h>
#include <dash/allocator/CollectiveAllocator.h>
#include <dash/allocator/DynamicAllocator.h>
#include <dash/allocator/SymmetricAllocator.h>
#include <dash/allocator/EpochSynchronizedAllocator.h>

namespace dash {

Expand Down
15 changes: 12 additions & 3 deletions dash/include/dash/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <dash/Exception.h>
#include <dash/Cartesian.h>
#include <dash/Dimensional.h>
#include <dash/GlobMem.h>
#include <dash/memory/GlobStaticMem.h>
#include <dash/GlobRef.h>
#include <dash/GlobAsyncRef.h>
#include <dash/Shared.h>
Expand Down Expand Up @@ -621,7 +621,7 @@ class ArrayRef
* \concept{DashArrayConcept}
*
* \todo Add template parameter:
* <tt>class GlobMemType = dash::GlobMem<ElementType></tt>
* <tt>class GlobMemType = dash::GlobStaticMem<ElementType></tt>
*
* \note: Template parameter IndexType could be deduced from pattern
* type <tt>PatternT::index_type</tt>
Expand Down Expand Up @@ -662,7 +662,7 @@ class Array
typedef GlobIter< value_type, PatternType> pointer;
typedef GlobIter<const value_type, PatternType> const_pointer;

typedef dash::GlobMem<value_type> glob_mem_type;
typedef dash::GlobStaticMem<value_type> glob_mem_type;

public:
template<
Expand Down Expand Up @@ -928,6 +928,15 @@ class Array
return View(this, ViewSpec<1>(pattern().block(block_gindex)));
}

/**
* The instance of \c GlobStaticMem used by this iterator to resolve addresses
* in global memory.
*/
constexpr const glob_mem_type & globmem() const noexcept
{
return *m_globmem;
}

/**
* Global const pointer to the beginning of the array.
*/
Expand Down
46 changes: 23 additions & 23 deletions dash/include/dash/GlobAsyncRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <dash/GlobPtr.h>
#include <dash/Allocator.h>
#include <dash/GlobMem.h>
#include <dash/memory/GlobStaticMem.h>

#include <iostream>

Expand Down Expand Up @@ -47,12 +47,12 @@ class GlobAsyncRef
private:
typedef GlobAsyncRef<T>
self_t;
typedef GlobMem<T, dash::allocator::CollectiveAllocator<T> >
GlobMem_t;
typedef GlobStaticMem<T, dash::allocator::SymmetricAllocator<T> >
GlobStaticMem_t;

private:
/// Instance of GlobMem that issued this global reference
GlobMem_t * _globmem;
/// Instance of GlobStaticMem that issued this global reference
GlobStaticMem_t * _globmem;
/// Value of the referenced element, initially not loaded
mutable T _value;
/// Pointer to referenced element in global memory
Expand All @@ -72,8 +72,8 @@ class GlobAsyncRef
* global memory.
*/
GlobAsyncRef(
/// Instance of GlobMem that issued this global reference
GlobMem_t * globmem,
/// Instance of GlobStaticMem that issued this global reference
GlobStaticMem_t * globmem,
/// Pointer to referenced object in global memory
T * lptr)
: _value(*lptr),
Expand All @@ -99,15 +99,15 @@ class GlobAsyncRef
* Conctructor, creates an GlobRefAsync object referencing an element in
* global memory.
*/
template<class PatternT>
template<class MemSpaceT>
GlobAsyncRef(
/// Instance of GlobMem that issued this global reference
GlobMem_t * globmem,
/// Instance of GlobStaticMem that issued this global reference
GlobStaticMem_t * globmem,
/// Pointer to referenced object in global memory
GlobPtr<T, PatternT> & gptr)
: _gptr(gptr.dart_gptr()),
_is_local(gptr.is_local())
GlobPtr<T, MemSpaceT> & gptr)
: _gptr(gptr.dart_gptr())
{
_is_local = gptr.is_local();
if (_is_local) {
_value = *gptr;
_lptr = (T*)(gptr);
Expand All @@ -119,13 +119,13 @@ class GlobAsyncRef
* Conctructor, creates an GlobRefAsync object referencing an element in
* global memory.
*/
template<class PatternT>
template<class MemSpaceT>
GlobAsyncRef(
/// Pointer to referenced object in global memory
GlobPtr<T, PatternT> & gptr)
: _gptr(gptr.dart_gptr()),
_is_local(gptr.is_local())
GlobPtr<T, MemSpaceT> & gptr)
: _gptr(gptr.dart_gptr())
{
_is_local = gptr.is_local();
if (_is_local) {
_value = *gptr;
_lptr = (T*)(gptr);
Expand All @@ -138,13 +138,13 @@ class GlobAsyncRef
* global memory.
*/
GlobAsyncRef(
/// Instance of GlobMem that issued this global reference
GlobMem_t * globmem,
/// Instance of GlobStaticMem that issued this global reference
GlobStaticMem_t * globmem,
/// Pointer to referenced object in global memory
dart_gptr_t dart_gptr)
: _gptr(dart_gptr)
{
GlobPtr<T> gptr(dart_gptr);
GlobConstPtr<T> gptr(dart_gptr);
_is_local = gptr.is_local();
if (_is_local) {
_value = *gptr;
Expand All @@ -162,7 +162,7 @@ class GlobAsyncRef
dart_gptr_t dart_gptr)
: _gptr(dart_gptr)
{
GlobPtr<T> gptr(dart_gptr);
GlobConstPtr<T> gptr(dart_gptr);
_is_local = gptr.is_local();
if (_is_local) {
_value = *gptr;
Expand All @@ -176,8 +176,8 @@ class GlobAsyncRef
* global memory.
*/
GlobAsyncRef(
/// Instance of GlobMem that issued this global reference
GlobMem_t * globmem,
/// Instance of GlobStaticMem that issued this global reference
GlobStaticMem_t * globmem,
/// Pointer to referenced object in global memory
GlobRef<T> & gref)
: GlobAsyncRef(globmem, gref.gptr())
Expand Down
Loading

0 comments on commit 15c107e

Please sign in to comment.