Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing issue #157 (block size/forall) #158

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions system/New_loop_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,64 @@ void test_forall_here() {

}

struct OneBlock {
int64_t x;
} GRAPPA_BLOCK_ALIGNED;
struct TwoBlocks {
int64_t y;
char stuff[BLOCK_SIZE-sizeof(int64_t)];
int64_t a,b,c,d;
} GRAPPA_BLOCK_ALIGNED;

void test_forall_large_data() {
BOOST_MESSAGE("Testing forall on array of large structs");
{
size_t c = 7;
auto arr = global_alloc<OneBlock>(c);
// initialize
forall(arr, c, [] (int64_t i, OneBlock& two) {
two.x = 10*i;
});

// check without forall
for (int i=0; i<c; i++) {
auto res = delegate::read( arr + i );
BOOST_CHECK_EQUAL( res.x, 10*i );
}
}
{
size_t c = 7;
auto arr = global_alloc<TwoBlocks>(c);
// initialize
/*
forall(arr, c, [] (int64_t i, TwoBlocks& two) {
two.y = i;
two.a = 10*i;
two.b = 100*i;
two.c = 1000*i;
two.d = 10000*i;
});
*/

for (int i=0; i<c; i++) {
TwoBlocks b = { i, "", 10*i, 100*i, 1000*i, 10000*i };
delegate::write( arr + i, b );
}


// check without forall
for (int i=0; i<c; i++) {
auto res = delegate::read( arr + i );
BOOST_MESSAGE( "check " << i );
BOOST_CHECK_EQUAL( res.y, i );
BOOST_CHECK_EQUAL( res.a, 10*i );
//BOOST_CHECK_EQUAL( res.b, 1000*i );
}
}
}



void test_forall_global_private() {
BOOST_MESSAGE("Testing forall_global...");
const int64_t N = 1 << 8;
Expand Down Expand Up @@ -317,6 +375,8 @@ BOOST_AUTO_TEST_CASE( test1 ) {
test_forall_localized();

test_forall_here_async();

test_forall_large_data();

Metrics::merge_and_dump_to_file();
});
Expand Down
4 changes: 3 additions & 1 deletion system/ParallelLoop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "Collective.hpp"
#include "function_traits.hpp"

#include <algorithm>

/// Flag: loop_threshold
///
/// Iterations of `forall` loops *may* be run in parallel. A complete loop is decomposed into
Expand Down Expand Up @@ -333,7 +335,7 @@ namespace Grappa {
auto end = base+nelem;
if (nelem > 0) { fc = 1; }

size_t block_elems = block_size / sizeof(T);
size_t block_elems = std::max<size_t>(1, block_size / sizeof(T));
int64_t nfirstcore = base.block_max() - base;
int64_t n = nelem - nfirstcore;

Expand Down