fastlib/thor compiles now, except for allnn.cc.

Things in here are still very broken, even if the compiler doesn't complain.
This commit is contained in:
James Cline
2010-06-09 16:48:25 +00:00
parent cb0f94e748
commit 58d10b265b
22 changed files with 115 additions and 118 deletions
@@ -27,7 +27,7 @@ set(DIRS
math
mmanager ## not yet
par
#thor # requires pthread linking
thor # requires pthread linking
tree
# sparse
) #!!
@@ -185,7 +185,7 @@ class Thread {
* Mutual exclusion lock to protect shared data.
*/
class Mutex {
FORBID_ACCIDENTAL_COPIES(Mutex);
// FORBID_ACCIDENTAL_COPIES(Mutex); // safe to remove?
friend class WaitCondition;
public:
@@ -46,13 +46,13 @@ set(FASTLIB_SRCS ${FASTLIB_SRCS} ${DIR_SRCS} PARENT_SCOPE)
#add_dependencies(col base) # depends on base library
# test executable
add_executable(allnn_thor
allnn.cc
)
#add_executable(allnn_thor
# allnn.cc
#)
# link col_test against col and base libraries
target_link_libraries(allnn_thor
fastlib
)
#target_link_libraries(allnn_thor
# fastlib
#)
#add_executable(allnnbfs_thor
# allnnbfs.cc
@@ -28,8 +28,10 @@ void RandomAccessFile::Init(const char *fname, BlockDevice::mode_t mode) {
DEBUG_ASSERT_MSG(mode == BlockDevice::M_TEMP,
"Null filenames are only valid for temporary files.");
const char *tmpdir = fx_param_str(fx_root, "tmpdir", "/tmp");
fname_.InitSprintf("%s/thor_gnp_XXXXXXXXX", tmpdir);
fd_ = mkstemp(fname_.c_str());
// fname_.InitSprintf("%s/thor_gnp_", tmpdir);
fname = tmpdir;
fname_ += "/thor_gnp_XXXXXXXXX"; // Aren't there only supposed to be 6 Xs?
fd_ = mkstemp(const_cast<char*> (fname_.c_str()));
} else {
int octal_mode;
@@ -46,7 +48,7 @@ void RandomAccessFile::Init(const char *fname, BlockDevice::mode_t mode) {
}
fd_ = open(fname, octal_mode, 0666);
fname_.Copy(fname);
fname_ = fname;
}
if (mode == BlockDevice::M_TEMP) {
@@ -9,10 +9,11 @@
#include "../base/base.h"
#include "../col/intmap.h"
#include "../col/col_string.h"
#include "../fx/fx.h"
#include "../par/thread.h"
#include <string>
/**
* An abstracted block device.
*
@@ -248,7 +249,7 @@ class RandomAccessFile {
/** The BlockDevice mode of the file. */
mode_t mode_;
/** The filename open. */
String fname_;
std::string fname_;
/** Mutex to protect the lseek-read sequence. */
Mutex mutex_;
@@ -8,6 +8,7 @@
#define THOR_CACHE_H
#include "blockdev.h"
#include <vector>
/**
* Handles events associated with a cache pulling blocks in and out of memory.
@@ -19,9 +20,9 @@ class BlockHandler {
virtual ~BlockHandler() {}
/** Save state. */
virtual void Serialize(ArrayList<char>* data) const = 0;
virtual void Serialize(std::vector<char>* data) const = 0;
/** Initialize from state. */
virtual void Deserialize(const ArrayList<char>& data) = 0;
virtual void Deserialize(const std::vector<char>& data) = 0;
/** Initialize a chunk in frozen state. */
virtual void BlockInitFrozen(BlockDevice::blockid_t blockid,
BlockDevice::offset_t begin,
@@ -19,7 +19,7 @@ class CacheArrayBlockHandler : public BlockHandler {
FORBID_ACCIDENTAL_COPIES(CacheArrayBlockHandler);
private:
ArrayList<char> default_elem_;
std::vector<char> default_elem_;
public:
CacheArrayBlockHandler() {}
@@ -33,9 +33,9 @@ class CacheArrayBlockHandler : public BlockHandler {
*/
void Init(const T& default_obj);
void Serialize(ArrayList<char>* data) const;
void Serialize(std::vector<char>* data) const;
void Deserialize(const ArrayList<char>& data);
void Deserialize(const std::vector<char>& data);
void BlockInitFrozen(BlockDevice::blockid_t blockid,
BlockDevice::offset_t begin, BlockDevice::offset_t bytes, char *block);
@@ -106,7 +106,7 @@ class CacheArray {
unsigned int n_block_elems_mask_;
/** The metadatas array. */
ArrayList<Metadata> metadatas_;
std::vector<Metadata> metadatas_;
/** The circular fixed-size FIFO queue of blocks that are locked in memory. */
BlockDevice::blockid_t *fifo_;
@@ -2,18 +2,18 @@
template<typename T>
void CacheArrayBlockHandler<T>::Init(const T& default_obj) {
default_elem_.Init(ot::FrozenSize(default_obj));
default_elem_.reserve(ot::FrozenSize(default_obj));
ot::Freeze(default_elem_.begin(), default_obj);
}
template<typename T>
void CacheArrayBlockHandler<T>::Serialize(ArrayList<char>* data) const {
data->InitCopy(default_elem_);
void CacheArrayBlockHandler<T>::Serialize(std::vector<char>* data) const {
data->assign(default_elem_.begin(), default_elem_.end());
}
template<typename T>
void CacheArrayBlockHandler<T>::Deserialize(const ArrayList<char>& data) {
default_elem_.InitCopy(data);
void CacheArrayBlockHandler<T>::Deserialize(const std::vector<char>& data) {
default_elem_.assign(data.begin(), data.end());
}
template<typename T>
@@ -22,7 +22,7 @@ void CacheArrayBlockHandler<T>::BlockInitFrozen(BlockDevice::blockid_t blockid,
DEBUG_ASSERT((begin % default_elem_.size()) == 0);
index_t elems = bytes / default_elem_.size();
for (index_t i = 0; i < elems; i++) {
mem::CopyBytes(block, default_elem_.begin(), default_elem_.size());
mem::CopyBytes(block, &default_elem_.front(), default_elem_.size() );
block += default_elem_.size();
}
}
@@ -54,8 +54,8 @@ void CacheArrayBlockHandler<T>::BlockThaw(BlockDevice::blockid_t blockid,
template<typename T>
void CacheArrayBlockHandler<T>::GetDefaultElement(T *default_element_out) {
ArrayList<char> tmp;
tmp.InitCopy(default_elem_);
std::vector<char> tmp;
tmp.assign(default_elem_.begin(), default_elem_.end());
const T* source = ot::SemiThaw<T>(tmp.begin());
ot::InitCopy(default_element_out, *source);
}
@@ -95,7 +95,6 @@ void DistributedCache::InitCommon_(int channel_num_in) {
n_fifo_locks_ = 0;
world_n_fifo_locks_ = 0;
blocks_.Init();
handler_ = NULL;
overflow_free_ = -1;
@@ -121,7 +120,7 @@ void DistributedCache::InitCache_(size_t total_ram) {
} else {
DEBUG_ASSERT(n_sets_ * ASSOC * n_block_bytes_ <= total_ram);
}
slots_.Init(n_sets_ << LOG_ASSOC);
slots_.reserve(n_sets_ << LOG_ASSOC);
}
char *DistributedCache::AllocBlock_() {
@@ -161,7 +160,7 @@ void DistributedCache::HandleSyncInfo_(const SyncInfo& info) {
}
void DistributedCache::HandleStatusInformation_(
const ArrayList<BlockStatus>& statuses) {
const std::vector<BlockStatus>& statuses) {
// This method is only called after a sync.
// However, it is possible that some other machines might have started
// writing stuff, so we'll have to take this information with a grain of
@@ -170,7 +169,7 @@ void DistributedCache::HandleStatusInformation_(
if (n_blocks_ != statuses.size()) {
n_blocks_ = statuses.size();
blocks_.Resize(n_blocks_);
blocks_.reserve(n_blocks_);
}
for (index_t i = 0; i < n_blocks_; i++) {
@@ -203,10 +202,10 @@ void DistributedCache::HandleStatusInformation_(
}
void DistributedCache::ComputeStatusInformation_(
ArrayList<BlockStatus> *statuses) const {
std::vector<BlockStatus> *statuses) const {
mutex_.Lock();
DEBUG_ASSERT(n_blocks_ == blocks_.size());
statuses->Init(n_blocks_);
statuses->reserve(n_blocks_);
for (index_t i = 0; i < statuses->size(); i++) {
BlockStatus *status = &(*statuses)[i];
const BlockMetadata *block = &blocks_[i];
@@ -223,10 +222,10 @@ void DistributedCache::ComputeStatusInformation_(
void DistributedCache::BestEffortWriteback(double portion) {
mutex_.Lock();
Slot *slot = slots_.begin();
std::vector<Slot>::iterator slot = slots_.begin();
index_t i = slots_.size();
int start_col = math::RoundInt(ASSOC * (1 - portion));
BlockMetadata *blocks = blocks_.begin();
std::vector<BlockMetadata>::iterator blocks = blocks_.begin();
// Might want to software-pipeline this loop, because of the really nasty
// indirect load going on.
@@ -251,9 +250,9 @@ void DistributedCache::BestEffortWriteback(double portion) {
void DistributedCache::StartSync() {
// We'll assume everything we have locally is no longer valid.
mutex_.Lock();
Slot *slot = slots_.begin();
std::vector<Slot>::iterator slot = slots_.begin();
index_t i = slots_.size();
BlockMetadata *blocks = blocks_.begin();
std::vector<BlockMetadata>::iterator blocks = blocks_.begin();
size_t unflushed_bytes = 0;
DEBUG_ASSERT_MSG(!syncing_, "Called StartSync twice before WaitSync!");
@@ -410,7 +409,7 @@ void DistributedCache::RemoteWrite(blockid_t blockid,
if (unlikely(blockid >= n_blocks_)) {
n_blocks_ = blockid + 1;
// the default constructor for BlockMetadata should mark the block as new
blocks_.Resize(n_blocks_);
blocks_.reserve(n_blocks_);
}
BlockMetadata *block = &blocks_[blockid];
if (!block->is_owner()) {
@@ -450,7 +449,7 @@ BlockDevice::blockid_t DistributedCache::RemoteAllocBlocks(
}
n_blocks_ = blockid + n_blocks_to_alloc;
blocks_.GrowTo(n_blocks_);
blocks_.resize(n_blocks_, *(new BlockMetadata));
// these blocks are marked as NOT_DIRTY_NEW
MarkOwner_(owner, blockid, n_blocks_);
@@ -506,7 +505,7 @@ void DistributedCache::HandleRemoteOwner_(blockid_t block, blockid_t end,
int new_owner) {
mutex_.Lock();
n_blocks_ = std::max(n_blocks_, end);
blocks_.Resize(n_blocks_);
blocks_.reserve(n_blocks_);
MarkOwner_(new_owner, block, end);
mutex_.Unlock();
}
@@ -980,7 +979,8 @@ void DistributedCache::SyncInfo::MergeWith(const SyncInfo& other) {
}
}
if (old_size < other.statuses.size()) {
statuses.Resize(other.statuses.size());
// WARNING: This is broken!
statuses.reserve(other.statuses.size());
mem::BitCopy(&statuses[old_size], &other.statuses[old_size],
statuses.size() - old_size);
}
@@ -7,9 +7,10 @@
#ifndef THOR_DISTRIBCACHE_H
#define THOR_DISTRIBCACHE_H
#include "../col/arraylist.h"
#include "../col/rangeset.h"
#include <vector>
#include "rpc.h"
#include "cache.h"
#include "blockdev.h"
@@ -140,7 +141,7 @@ class DistributedCache : public BlockDevice {
* Information the block handler (or "schema") needs to initialize itself
* with.
*/
ArrayList<char> block_handler_data;
std::vector<char> block_handler_data;
OT_DEF(ConfigResponse) {
OT_MY_OBJECT(n_block_bytes);
@@ -171,7 +172,7 @@ class DistributedCache : public BlockDevice {
IoStats net_stats;
int64 n_locks;
int64 n_fifo_locks;
ArrayList<BlockStatus> statuses;
std::vector<BlockStatus> statuses;
OT_DEF(SyncInfo) {
OT_MY_OBJECT(disk_stats);
@@ -458,7 +459,7 @@ class DistributedCache : public BlockDevice {
private:
/** A block-to-metadata mapping, keeping track of each block's status. */
ArrayList<BlockMetadata> blocks_;
std::vector<BlockMetadata> blocks_;
/** A schema that regards how to freeze, thaw, and initialize blocks. */
BlockHandler *handler_;
@@ -466,7 +467,7 @@ class DistributedCache : public BlockDevice {
Mutex mutex_;
/** The associtive cache. */
ArrayList<Slot> slots_;
std::vector<Slot> slots_;
/** The number of cache sets, same as slots_.size() / ASSOC. */
unsigned n_sets_;
@@ -693,7 +694,7 @@ class DistributedCache : public BlockDevice {
* After a sync point, handles the change in ownership info.
* This is one of the most important parts of our coherency mechanisms.
*/
void HandleStatusInformation_(const ArrayList<BlockStatus>& statuses);
void HandleStatusInformation_(const std::vector<BlockStatus>& statuses);
/**
* After a sync point, handles synchronization information.
*/
@@ -701,7 +702,7 @@ class DistributedCache : public BlockDevice {
/**
* Marks me as owner of blocks I own and marks other blocks as null.
*/
void ComputeStatusInformation_(ArrayList<BlockStatus>* statuses) const;
void ComputeStatusInformation_(std::vector<BlockStatus>* statuses) const;
/**
* Tries to grab a block from cache, if it fails, this pulls it from the
* proper source by calling HandleMiss_.
@@ -19,7 +19,6 @@
#include "../file/textfile.h"
#include "../data/dataset.h"
#include "../tree/bounds.h"
#include "../col/arraylist.h"
#include "../fx/fx.h"
/**
@@ -24,7 +24,7 @@ class DualTreeRecursiveBreadth {
};
struct Queue {
ArrayList<QueueItem> q;
std::vector<QueueItem> q;
typename GNP::QSummaryResult summary_result;
typename GNP::QPostponed postponed;
@@ -193,7 +193,7 @@ void DualTreeRecursiveBreadth<GNP>::DivideReferences_(
Queue child_queue;
child_queue.Init(param_);
ArrayList<typename GNP::QSummaryResult> summaries;
std::vector<typename GNP::QSummaryResult> summaries;
summaries.Init(parent_queue->q.size());
summaries[0].Init(param_);
@@ -11,12 +11,12 @@
#define THOR_RPC_H
#include "../base/base.h"
#include <vector>
#include "blockdev.h"
#include "rpc_base.h"
#include "rpc_sock.h"
#include "../col/arraylist.h"
//--------------------------------------------------------------------------
@@ -209,7 +209,7 @@ class ReduceChannel : public Channel {
FORBID_ACCIDENTAL_COPIES(ReduceTransaction);
private:
ArrayList<Message*> received_;
std::vector<Message*> received_;
int n_received_;
TData *data_;
const TReductor *reductor_;
@@ -243,7 +243,7 @@ class ReduceChannel : public Channel {
void Init(int channel_num, const TReductor *reductor_in, TData *data_inout) {
Transaction::Init(channel_num);
reductor_ = reductor_in;
received_.Init(rpc::n_children());
received_.reserve(rpc::n_children());
for (index_t i = 0; i < received_.size(); i++) {
received_[i] = NULL;
}
@@ -8,6 +8,7 @@
#define THOR_RPC_BASE_H
#include "../base/base.h"
#include <vector>
/**
* A Message is the fundamental unit of message-passing in our RPC system.
@@ -134,7 +135,7 @@ class Transaction {
int channel;
int transaction_id;
};
ArrayList<PeerInfo> peers_;
std::vector<PeerInfo> peers_;
public:
/** Create a message of a specified size, which you will later Send(). */
@@ -113,7 +113,6 @@ RpcSockImpl *RpcSockImpl::instance = NULL;
void RpcSockImpl::Init() {
channels_.Init();
channels_.default_value() = NULL;
unknown_connections_.Init();
live_pings_ = 0;
peer_from_fd_.Init();
peer_from_fd_.default_value() = -1;
@@ -175,7 +174,7 @@ void RpcSockImpl::Done() {
WakeUpPollingLoop();
polling_thread_.WaitStop();
close(listen_fd_);
peers_.Resize(0); // automatically calls their destructors
peers_.clear(); // automatically calls their destructors
}
}
@@ -259,12 +258,13 @@ int RpcSockImpl::AssignTransaction(int peer_num, Transaction *transaction) {
peer->outgoing_free = peer->outgoing_freelist[id];
} else {
id = peer->outgoing_transactions.size();
peer->outgoing_transactions.Resize(id + 1);
peer->outgoing_freelist.Resize(id + 1);
// peer->outgoing_transactions.resize(id + 1);
// peer->outgoing_freelist.Resize(id + 1);
}
//fprintf(stderr, "%d to %d: registering %d\n", rpc::rank(), peer_num, id);
DEBUG_ONLY(peer->outgoing_freelist[id] = -1);
peer->outgoing_transactions[id] = transaction;
// peer->outgoing_transactions[id] = transaction;
peer->outgoing_transactions.push_back(transaction);
peer->mutex.Unlock();
return id;
}
@@ -276,7 +276,7 @@ int RpcSockImpl::AssignTransaction(int peer_num, Transaction *transaction) {
void RpcSockImpl::CreatePeers_() {
peers_.Init(n_peers_);
peers_.reserve(n_peers_);
if (n_peers_ == 1) {
Peer *peer = &peers_[0];
@@ -300,8 +300,6 @@ void RpcSockImpl::CalcChildren_() {
unsigned((~rank_) & (rank_-1)));
int i;
children_.Init();
// okay, all peers between my rank and my rank + m - 1 are my direct or
// indirect children. the ones that have a power of two difference from
// me are my direct children.
@@ -311,7 +309,7 @@ void RpcSockImpl::CalcChildren_() {
while (i > 1) {
i /= 2;
children_.PushBack() = rank_ + i;
children_.push_back(rank_ + i);
}
parent_ = rank_ - ((~rank_) & (rank_-1)) - 1;
@@ -370,14 +368,12 @@ void RpcSockImpl::StartPollingThread_() {
}
void RpcSockImpl::PollingLoop_() {
ArrayList<WorkItem> work_items;
std::vector<WorkItem> work_items;
fd_set read_fds;
fd_set write_fds;
fd_set error_fds;
int initialization_seconds = 0;
work_items.Init();
while (status_ != STOP) {
index_t j = 0;
@@ -439,7 +435,7 @@ void RpcSockImpl::PollingLoop_() {
unknown_connections_[j++] = unknown_connections_[i];
}
}
unknown_connections_.Resize(j);
unknown_connections_.reserve(j);
}
bool errors_ok = (status_ == STOP) || (status_ == STOP_SYNC);
@@ -503,7 +499,7 @@ void RpcSockImpl::PollingLoop_() {
// Accept incoming connections
int new_fd;
while ((new_fd = accept(listen_fd_, NULL, NULL)) >= 0) {
unknown_connections_.PushBack() = new_fd;
unknown_connections_.push_back(new_fd);
RegisterReadFd(-1, new_fd);
}
}
@@ -684,8 +680,6 @@ void RpcSockImpl::DeactivateWriteFd(int fd) {
RpcSockImpl::Peer::Peer() {
incoming_transactions.Init();
incoming_transactions.default_value() = NULL;
outgoing_transactions.Init();
outgoing_freelist.Init();
outgoing_free = -1;
is_pending = false;
}
@@ -698,7 +692,6 @@ RpcSockImpl::Peer::~Peer() {
void Transaction::Init(int channel_in) {
// Set up our internal data.
channel_ = channel_in;
peers_.Init();
}
Message *Transaction::CreateMessage(int peer, size_t size) {
@@ -717,11 +710,12 @@ Message *Transaction::CreateMessage(int peer, size_t size) {
if (i == peers_.size()) {
// We haven't sent or received from this peer, so we need to send the
// channel number to it so that the channel can create a new transaction.
peers_.PushBack();
PeerInfo peer_info;
transaction_id = RpcSockImpl::instance->AssignTransaction(peer, this);
peers_[i].peer = peer;
peers_[i].channel = channel();
peers_[i].transaction_id = transaction_id;
peer_info.peer = peer;
peer_info.channel = channel();
peer_info.transaction_id = transaction_id;
peers_.push_back(peer_info);
}
// Create a message we can send!
@@ -737,10 +731,11 @@ void Transaction::TransactionHandleNewSender_(Message *message) {
// We'll reply to this with channel -1, meaning that it was the other end
// who initiated the transaction ID, i.e., the transaction ID lives in
// their namespace.
PeerInfo &peer_info = peers_.PushBack();
PeerInfo peer_info;
peer_info.peer = message->peer();
peer_info.channel = -1;
peer_info.transaction_id = message->transaction_id();
peers_.push_back(peer_info);
}
void Transaction::Send(Message *message) {
@@ -753,7 +748,7 @@ void Transaction::Done() {
RpcSockImpl::instance->UnregisterTransaction(
peers_[i].peer, peers_[i].channel, peers_[i].transaction_id);
}
peers_.Clear();
peers_.clear();
}
void Transaction::Done(int peer) {
@@ -763,7 +758,7 @@ void Transaction::Done(int peer) {
RpcSockImpl::instance->UnregisterTransaction(
peers_[i].peer, peers_[i].channel, peers_[i].transaction_id);
peers_[i] = peers_[peers_.size()-1];
peers_.PopBack();
peers_.pop_back();
break;
}
}
@@ -9,7 +9,6 @@
#include "rpc_base.h"
#include "../col/arraylist.h"
#include "../math/math_lib.h"
#include <deque>
@@ -34,7 +33,7 @@
* be protected by a mutex.
*/
class SockConnection {
FORBID_ACCIDENTAL_COPIES(SockConnection);
//FORBID_ACCIDENTAL_COPIES(SockConnection); // ok to remove? =/
public:
enum { MAGIC = 314159265 };
@@ -188,11 +187,11 @@ class RpcSockImpl {
* a non-negative channel number and incoming messages have a negative
* channel number.
*/
ArrayList<Transaction*> outgoing_transactions;
std::vector<Transaction*> outgoing_transactions;
/**
* Free list of outgoing transactions ready for reuse.
*/
ArrayList<int> outgoing_freelist;
std::vector<int> outgoing_freelist;
/**
* An available outgoing transaction, or -1 if none.
*/
@@ -261,12 +260,12 @@ class RpcSockImpl {
int port_;
int parent_;
ArrayList<int> children_;
std::vector<int> children_;
int listen_fd_;
ArrayList<Peer> peers_;
std::vector<Peer> peers_;
ArrayList<int> unknown_connections_;
std::vector<int> unknown_connections_;
DenseIntMap<Channel*> channels_;
@@ -331,7 +330,7 @@ class RpcSockImpl {
int rank() const { return rank_; }
int n_peers() const { return n_peers_; }
const ArrayList<int>& children() const { return children_; }
const std::vector<int>& children() const { return children_; }
bool is_root() const { return parent_ == rank_; }
int parent() const { return parent_; }
@@ -29,10 +29,10 @@ void RemoteScheduler::Init(int channel, int destination) {
}
void RemoteScheduler::GetWork(
int rank, ArrayList<Grain> *work_items) {
int rank, std::vector<Grain>& work_items) {
WorkRequest request;
request.operation = WorkRequest::GIVE_ME_WORK;
request.rank = rank;
Rpc<WorkResponse> response(channel_, destination_, request);
work_items->InitCopy(response->work_items);
work_items.assign(response->work_items.begin(), response->work_items.end());
}
@@ -13,10 +13,11 @@
#include "thortree.h"
#include "../col/heap.h"
#include "../col/arraylist.h"
#include "../la/uselapack.h"
#include "../tree/bounds.h"
#include <vector>
//------------------------------------------------------------------------
/**
@@ -45,7 +46,7 @@ class SchedulerInterface {
* @param rank the rank of the machine requesting work
* @param work where the work will be stored
*/
virtual void GetWork(int rank, ArrayList<Grain> *work) = 0;
virtual void GetWork(int rank, std::vector<Grain> *work) = 0;
/**
* Report any relevant statistics to fastexec.
@@ -75,7 +76,7 @@ class LockedScheduler : public SchedulerInterface {
LockedScheduler(SchedulerInterface *inner) : inner_(inner) {}
virtual ~LockedScheduler() { delete inner_; }
virtual void GetWork(int rank, ArrayList<Grain> *work) {
virtual void GetWork(int rank, std::vector<Grain> *work) {
mutex_.Lock();
inner_->GetWork(rank, work);
mutex_.Unlock();
@@ -126,7 +127,7 @@ class CentroidScheduler
private:
CacheArray<Node> *tree_;
ArrayList<ProcessScheduler> rankes_;
std::vector<ProcessScheduler> rankes_;
InternalNode *root_;
int n_threads_;
double granularity_;
@@ -157,7 +158,7 @@ class CentroidScheduler
return n_grains_;
}
virtual void GetWork(int rank_num, ArrayList<Grain> *work);
virtual void GetWork(int rank_num, std::vector<Grain> *work);
/**
* Gets the number of grains that were not assigned to the original machine.
@@ -199,7 +200,7 @@ struct WorkRequest {
};
struct WorkResponse {
ArrayList<SchedulerInterface::Grain> work_items;
std::vector<SchedulerInterface::Grain> work_items;
OT_DEF_BASIC(WorkResponse) {
OT_MY_OBJECT(work_items);
@@ -232,7 +233,7 @@ class RemoteScheduler
void Init(int channel, int destination);
void GetWork(int rank, ArrayList<Grain> *work_items);
void GetWork(int rank, std::vector<Grain>& work_items);
};
//------------------------------------------------------------------------
@@ -52,7 +52,7 @@ void CentroidScheduler<Node>::DistributeInitialWork_(
}
ProcessScheduler *queue = &rankes_[begin_rank];
ArrayList<InternalNode*> node_stack;
std::vector<InternalNode*> node_stack;
node_stack.Init();
node_stack.PushBack() = node;
@@ -82,7 +82,7 @@ void CentroidScheduler<Node>::DistributeInitialWork_(
}
template<typename Node>
void CentroidScheduler<Node>::GetWork(int rank_num, ArrayList<Grain> *work) {
void CentroidScheduler<Node>::GetWork(int rank_num, std::vector<Grain> *work) {
InternalNode *found_node;
ProcessScheduler *queue = &rankes_[rank_num];
@@ -133,9 +133,7 @@ void CentroidScheduler<Node>::GetWork(int rank_num, ArrayList<Grain> *work) {
n_preferred_++;
}
if (found_node == NULL) {
work->Init();
} else {
if (found_node != NULL) {
// Show user-friendly status messages every 5% increment
index_t count = found_node->count();
n_assigned_points_ += count;
@@ -144,17 +142,17 @@ void CentroidScheduler<Node>::GetWork(int rank_num, ArrayList<Grain> *work) {
n_assigned_points_ * 100 / root_->count());
// Mark all children as complete (non-recursive version)
ArrayList<InternalNode*> stack;
stack.Init();
stack.PushBack() = found_node;
std::vector<InternalNode*> stack;
stack.push_back(found_node);
while (stack.size() != 0) {
InternalNode *c;
stack.PopBackInit(&c);
c = stack.back();
stack.pop_back();
c->info() = ALL;
for (index_t k = 0; k < Node::CARDINALITY; k++) {
InternalNode *c_child = c->child(k);
if (c_child) {
stack.PushBack() = c_child;
stack.push_back(c_child);
}
}
}
@@ -171,12 +169,12 @@ void CentroidScheduler<Node>::GetWork(int rank_num, ArrayList<Grain> *work) {
}
}
work->Init(1);
Grain *grain = &(*work)[0];
grain->node_index = found_node->index();
grain->node_end_index = found_node->end_index();
grain->point_begin_index = found_node->node().begin();
grain->point_end_index = found_node->node().end();
Grain grain;
grain.node_index = found_node->index();
grain.node_end_index = found_node->end_index();
grain.point_begin_index = found_node->node().begin();
grain.point_end_index = found_node->node().end();
work->push_back(grain);
Vector midpoint;
found_node->node().bound().CalculateMidpoint(&midpoint);
@@ -21,11 +21,10 @@ void thor::ThreadedDualTreeSolver<GNP, Solver>::Doit(
stats_.Init();
if (n_threads > 1) {
ArrayList<Thread> threads;
threads.Init(n_threads);
std::vector<Thread> threads;
threads.resize(n_threads, new WorkerTask(this));
for (index_t i = 0; i < n_threads; i++) {
threads[i].Init(new WorkerTask(this));
// Set these threads to low priority to make sure the network thread
// gets full priority.
threads[i].Start(Thread::LOW_PRIORITY);
@@ -42,7 +41,7 @@ void thor::ThreadedDualTreeSolver<GNP, Solver>::Doit(
template<typename GNP, typename Solver>
void thor::ThreadedDualTreeSolver<GNP, Solver>::ThreadBody_() {
while (1) {
ArrayList<SchedulerInterface::Grain> work;
std::vector<SchedulerInterface::Grain> work;
mutex_.Lock();
work_queue_->GetWork(rank_, &work);
@@ -106,7 +106,7 @@ class ThorTreeDecomposition {
* The tree decomposition.
*/
DecompNode *root_;
ArrayList<TreeGrain> grain_by_owner_;
std::vector<TreeGrain> grain_by_owner_;
OT_DEF(ThorTreeDecomposition) {
OT_PTR(root_);
@@ -122,7 +122,7 @@ class ThorTreeDecomposition {
DEBUG_ASSERT(root_->info().begin_rank == 0);
DEBUG_ASSERT(root_->info().end_rank == rpc::n_peers());
DEBUG_ASSERT(root_in != NULL);
grain_by_owner_.Init(rpc::n_peers());
grain_by_owner_.reserve(rpc::n_peers());
for (int i = 0; i < grain_by_owner_.size(); i++) {
grain_by_owner_[i].InitInvalid();
}