Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dtk
dtk
Commits
1006d34f
Commit
1006d34f
authored
Feb 07, 2013
by
KLOCZKO Thibaud
Browse files
Global iterator.
parent
0a75b7b2
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/dtkDistributed/dtkDistributedCommunicator.cpp
View file @
1006d34f
...
...
@@ -60,13 +60,13 @@ void dtkDistributedCommunicator::uninitialize(void)
int
dtkDistributedCommunicator
::
rank
(
void
)
{
// DTK_DEFAULT_IMPLEMENTATION;
return
-
1
;
return
0
;
}
int
dtkDistributedCommunicator
::
size
(
void
)
{
// DTK_DEFAULT_IMPLEMENTATION;
return
0
;
return
1
;
}
qlonglong
dtkDistributedCommunicator
::
allocate
(
qlonglong
count
,
qlonglong
size
,
void
*
buffer
)
...
...
@@ -74,7 +74,12 @@ qlonglong dtkDistributedCommunicator::allocate(qlonglong count, qlonglong size,
return
-
1
;
}
QByteArray
dtkDistributedCommunicator
::
get
(
qint32
from
,
qlonglong
position
,
qlonglong
size
,
qlonglong
buffer_id
)
void
dtkDistributedCommunicator
::
get
(
qint32
from
,
qlonglong
position
,
void
*
array
,
qlonglong
buffer_id
)
{
}
QByteArray
dtkDistributedCommunicator
::
get
(
qint32
from
,
qlonglong
position
,
qlonglong
size
,
qlonglong
buffer_id
)
{
return
QByteArray
();
}
...
...
src/dtkDistributed/dtkDistributedCommunicator.h
View file @
1006d34f
...
...
@@ -20,7 +20,6 @@
// class dtkDistributedCommunicatorPrivate;
class
dtkDistributedCommunicator
:
public
QObject
{
Q_OBJECT
...
...
@@ -45,7 +44,10 @@ public:
public:
virtual
qlonglong
allocate
(
qlonglong
count
,
qlonglong
size
,
void
*
buffer
);
virtual
QByteArray
get
(
qint32
from
,
qlonglong
position
,
qlonglong
size
,
qlonglong
buffer_id
);
virtual
void
get
(
qint32
from
,
qlonglong
position
,
void
*
array
,
qlonglong
buffer_id
);
virtual
QByteArray
get
(
qint32
from
,
qlonglong
position
,
qlonglong
size
,
qlonglong
buffer_id
);
virtual
void
put
(
qint32
dest
,
qlonglong
position
,
qlonglong
size
,
const
QByteArray
&
data
,
qlonglong
buffer_id
);
// public:
...
...
src/dtkDistributed/dtkDistributedContainer.h
View file @
1006d34f
...
...
@@ -3,9 +3,9 @@
* Author: Thibaud Kloczko
* Created: Tue Feb 5 14:08:23 2013 (+0100)
* Version:
* Last-Updated: 2013 Thu Feb 7 1
5:06
:2
9
(+0100)
* Last-Updated: 2013 Thu Feb 7 1
7:13
:2
1
(+0100)
* By: Thibaud Kloczko
* Update #:
29
* Update #:
56
*/
/* Change Log:
...
...
@@ -26,6 +26,23 @@ template<typename T> class dtkDistributedContainer;
// dtkDistributedLocalIterator
// ///////////////////////////////////////////////////////////////////
template
<
typename
T
>
class
dtkDistributedGlobalIterator
{
public:
qlonglong
globalIndex
(
void
)
const
{
return
0
;}
public:
bool
hasNext
(
void
)
{
return
false
;}
public:
const
T
&
next
(
void
)
{
return
*
new
T
();}
};
// ///////////////////////////////////////////////////////////////////
// dtkDistributedLocalIterator
// ///////////////////////////////////////////////////////////////////
template
<
typename
T
>
class
dtkDistributedLocalIterator
{
public:
...
...
@@ -75,25 +92,37 @@ public:
public:
~
dtkDistributedContainer
(
void
);
private:
void
allocate
(
void
);
public:
void
resize
(
const
qlonglong
&
size
);
qlonglong
size
(
void
)
const
;
public:
void
set
(
const
qlonglong
&
index
,
const
T
&
value
);
void
set
(
const
qlonglong
&
global_id
,
const
T
&
value
);
void
setLocal
(
const
qlonglong
&
local_id
,
const
T
&
value
);
public:
const
T
&
at
(
const
qlonglong
&
index
);
T
at
(
const
qlonglong
&
global_id
);
const
T
&
localAt
(
const
qlonglong
&
local_id
);
public:
dtkDistributedLocalIterator
<
T
>&
localIterator
(
void
);
dtkDistributedGlobalIterator
<
T
>&
globalIterator
(
void
)
{
return
*
new
dtkDistributedGlobalIterator
<
T
>
();}
private:
dtkDistributedMapper
*
m_mapper
;
dtkDistributedCommunicator
*
m_comm
;
private:
T
*
m_buffer
;
qlonglong
m_buffer_id
;
T
*
m_temp
;
QVector
<
T
>
m_array
;
dtkDistributedLocalIterator
<
T
>
*
m_iterator
;
...
...
src/dtkDistributed/dtkDistributedContainer.tpp
View file @
1006d34f
...
...
@@ -3,9 +3,9 @@
* Author: Thibaud Kloczko
* Created: Tue Feb 5 14:12:49 2013 (+0100)
* Version:
* Last-Updated: 2013 Thu Feb 7 1
5:07:57
(+0100)
* Last-Updated: 2013 Thu Feb 7 1
7:05:30
(+0100)
* By: Thibaud Kloczko
* Update #:
56
* Update #:
139
*/
/* Change Log:
...
...
@@ -15,6 +15,7 @@
#pragma once
#include
"dtkDistributedMapper.h"
#include
"dtkDistributedCommunicator.h"
// /////////////////////////////////////////////////////////////////
// dtkDistributedLocalIterator implementation
...
...
@@ -91,16 +92,20 @@ template <typename T> qlonglong dtkDistributedLocalIterator<T>::globalIndex(void
// dtkDistributedContainer implementation
// /////////////////////////////////////////////////////////////////
template
<
typename
T
>
dtkDistributedContainer
<
T
>::
dtkDistributedContainer
(
void
)
:
m_iterator
(
0
),
m_mapper
(
new
dtkDistributedMapper
),
m_comm
(
0
)
template
<
typename
T
>
dtkDistributedContainer
<
T
>::
dtkDistributedContainer
(
void
)
:
m_buffer
(
0
),
m_iterator
(
0
),
m_mapper
(
new
dtkDistributedMapper
),
m_comm
(
0
)
,
m_temp
(
0
)
{
};
template
<
typename
T
>
dtkDistributedContainer
<
T
>::
dtkDistributedContainer
(
const
qlonglong
&
size
,
dtkDistributedCommunicator
*
communicator
)
:
m_iterator
(
0
),
m_mapper
(
new
dtkDistributedMapper
),
m_comm
(
communicator
)
template
<
typename
T
>
dtkDistributedContainer
<
T
>::
dtkDistributedContainer
(
const
qlonglong
&
size
,
dtkDistributedCommunicator
*
communicator
)
:
m_buffer
(
0
),
m_temp
(
0
),
m_iterator
(
0
),
m_mapper
(
new
dtkDistributedMapper
),
m_comm
(
communicator
)
{
this
->
resize
(
size
);
//m_mapper->setMapping(size, m_comm->size());
m_comm
->
initialize
();
m_mapper
->
setMapping
(
size
,
m_comm
->
size
());
this
->
allocate
();
};
template
<
typename
T
>
dtkDistributedContainer
<
T
>::~
dtkDistributedContainer
(
void
)
...
...
@@ -109,8 +114,17 @@ template<typename T> dtkDistributedContainer<T>::~dtkDistributedContainer(void)
delete
m_mapper
;
};
template
<
typename
T
>
void
dtkDistributedContainer
<
T
>::
allocate
(
void
)
{
qDebug
()
<<
__func__
;
m_buffer
=
new
T
[
m_mapper
->
count
(
m_comm
->
rank
())];
// m_buffer_id = m_comm->allocate(m_mapper->count(m_comm->rank()), sizeof(T), m_buffer);
};
template
<
typename
T
>
void
dtkDistributedContainer
<
T
>::
resize
(
const
qlonglong
&
size
)
{
m_mapper
->
setMapping
(
size
,
1
);
m_buffer
=
new
T
[
size
];
m_array
.
resize
(
size
);
};
...
...
@@ -119,14 +133,40 @@ template <typename T> qlonglong dtkDistributedContainer<T>::size(void) const
return
m_array
.
size
();
};
template
<
typename
T
>
void
dtkDistributedContainer
<
T
>::
set
(
const
qlonglong
&
index
,
const
T
&
value
)
template
<
typename
T
>
void
dtkDistributedContainer
<
T
>::
set
(
const
qlonglong
&
global_id
,
const
T
&
value
)
{
m_buffer
[
m_mapper
->
globalToLocal
(
global_id
)]
=
value
;
//m_array.replace(global_id, value);
};
template
<
typename
T
>
void
dtkDistributedContainer
<
T
>::
setLocal
(
const
qlonglong
&
local_id
,
const
T
&
value
)
{
m_
array
.
replace
(
index
,
value
)
;
m_
buffer
[
local_id
]
=
value
;
};
template
<
typename
T
>
const
T
&
dtkDistributedContainer
<
T
>::
at
(
const
qlonglong
&
index
)
template
<
typename
T
>
T
dtkDistributedContainer
<
T
>::
at
(
const
qlonglong
&
global_id
)
{
qint32
me
=
m_comm
->
rank
();
qint32
owner
=
static_cast
<
qint32
>
(
m_mapper
->
owner
(
global_id
));
qlonglong
pos
=
m_mapper
->
globalToLocal
(
global_id
);
if
(
me
==
owner
)
{
return
m_buffer
[
pos
];
}
else
{
if
(
!
m_temp
)
m_temp
=
new
T
[
1
];
m_comm
->
get
(
owner
,
pos
,
m_temp
,
m_buffer_id
);
return
m_temp
[
0
];
}
}
;
template
<
typename
T
>
const
T
&
dtkDistributedContainer
<
T
>::
localAt
(
const
qlonglong
&
local_id
)
{
return
m_
array
.
at
(
index
)
;
return
m_
buffer
[
local_id
]
;
};
template
<
typename
T
>
dtkDistributedLocalIterator
<
T
>&
dtkDistributedContainer
<
T
>::
localIterator
(
void
)
...
...
src/dtkDistributed/dtkDistributedMapper.cpp
View file @
1006d34f
...
...
@@ -59,13 +59,19 @@ void dtkDistributedMapperPrivate::setMapping(const qlonglong& id_number, const q
this
->
map
.
reserve
(
this
->
pu_count
);
this
->
step
=
qRound
(
this
->
id_count
/
(
1.
*
this
->
pu_count
));
qlonglong
remain
=
this
->
id_count
-
this
->
step
*
(
this
->
pu_count
-
1
);
for
(
qlonglong
i
=
0
;
i
<
this
->
pu_count
-
1
;
++
i
)
this
->
map
<<
i
*
this
->
step
;
this
->
map
<<
(
this
->
map
.
at
(
this
->
pu_count
-
2
)
+
remain
);
if
(
this
->
pu_count
==
1
)
{
this
->
map
<<
0
;
}
else
{
this
->
step
=
qRound
(
this
->
id_count
/
(
1.
*
this
->
pu_count
));
qlonglong
remain
=
this
->
id_count
-
this
->
step
*
(
this
->
pu_count
-
1
);
for
(
qlonglong
i
=
0
;
i
<
this
->
pu_count
-
1
;
++
i
)
this
->
map
<<
i
*
this
->
step
;
this
->
map
<<
(
this
->
map
.
at
(
this
->
pu_count
-
2
)
+
remain
);
}
}
qlonglong
dtkDistributedMapperPrivate
::
localToGlobal
(
const
qlonglong
&
local_id
,
const
qlonglong
&
pu_id
)
const
...
...
test/dtkDistributed/dtkDistributedContainerTest.cpp
View file @
1006d34f
...
...
@@ -13,6 +13,7 @@
*/
#include
"dtkDistributedContainerTest.h"
#include
<dtkDistributed/dtkDistributedCommunicator.h>
#include
<dtkDistributed/dtkDistributedContainer.h>
void
dtkDistributedContainerTestCase
::
initTestCase
(
void
)
...
...
@@ -27,64 +28,58 @@ void dtkDistributedContainerTestCase::init(void)
void
dtkDistributedContainerTestCase
::
test1
(
void
)
{
qlonglong
N
=
1001
;
//
qlonglong N = 1001;
qlonglong
sum
=
0
;
for
(
qlonglong
i
=
0
;
i
<
N
;
++
i
)
sum
+=
i
;
//
qlonglong sum = 0;
//
for (qlonglong i = 0; i < N; ++i)
//
sum += i;
dtkDistributedContainer
<
qlonglong
>
c
;
c
.
resize
(
N
);
//
dtkDistributedContainer<qlonglong> c;
//
c.resize(N);
QVERIFY
(
N
==
c
.
size
());
//
QVERIFY(N == c.size());
dtkDistributedLocalIterator
<
qlonglong
>&
it
=
c
.
localIterator
();
//
dtkDistributedLocalIterator<qlonglong>& it = c.localIterator();
while
(
it
.
hasNext
())
{
c
.
set
(
it
.
globalIndex
(),
it
.
localIndex
());
it
.
next
();
}
//
while(it.hasNext()) {
//
c.set(it.globalIndex(), it.localIndex());
//
it.next();
//
}
qlonglong
check_sum
=
0
;
//
qlonglong check_sum = 0;
it
.
toFront
();
while
(
it
.
hasNext
())
{
check_sum
+=
c
.
at
(
it
.
localIndex
());
it
.
next
();
}
//
it.toFront();
//
while(it.hasNext()) {
//
check_sum += c.at(it.localIndex());
//
it.next();
//
}
QVERIFY
(
sum
==
check_sum
);
//
QVERIFY(sum == check_sum);
}
void
dtkDistributedContainerTestCase
::
test2
(
void
)
{
qlonglong
N
=
1001
;
qlonglong
W
=
9
;
qlonglong
sum
=
0
;
for
(
qlonglong
i
=
0
;
i
<
N
;
++
i
)
sum
+=
i
;
dtkDistributedCommunicator
comm
;
dtkDistributedContainer
<
qlonglong
>
c
;
//
= dtkDistributedContainer<qlonglong>(N,
W
);
dtkDistributedContainer
<
qlonglong
>
c
=
dtkDistributedContainer
<
qlonglong
>
(
N
,
&
comm
);
QVERIFY
(
N
==
c
.
size
());
dtkDistributed
Loc
alIterator
<
qlonglong
>&
it
=
c
.
lo
c
alIterator
();
dtkDistributed
Glob
alIterator
<
qlonglong
>&
g_
it
=
c
.
g
lo
b
alIterator
();
while
(
it
.
hasNext
())
{
c
.
set
(
it
.
globalIndex
(),
it
.
lo
c
alIndex
());
it
.
next
();
while
(
g_
it
.
hasNext
())
{
c
.
set
(
g_
it
.
globalIndex
(),
g_
it
.
g
lo
b
alIndex
());
g_
it
.
next
();
}
qlonglong
check_sum
=
0
;
dtkDistributedLocalIterator
<
qlonglong
>&
it
=
c
.
localIterator
()
;
it
.
toFront
();
while
(
it
.
hasNext
())
{
c
heck_sum
+=
c
.
a
t
(
it
.
localIndex
());
c
.
setLocal
(
it
.
localIndex
(),
2
*
c
.
localA
t
(
it
.
localIndex
())
)
;
it
.
next
();
}
QVERIFY
(
sum
==
check_sum
);
}
void
dtkDistributedContainerTestCase
::
cleanupTestCase
(
void
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment