Commit d5daef8b authored by Victor Lopez's avatar Victor Lopez

Replace macros by functions in slicer tests

parent 3ef3bf9a
/*************************************************************************************/
/* Copyright 2009-2018 Barcelona Supercomputing Center */
/* */
/* This file is part of the NANOS++ library. */
/* */
/* NANOS++ is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU Lesser General Public License as published by */
/* the Free Software Foundation, either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* NANOS++ is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU Lesser General Public License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with NANOS++. If not, see <https://www.gnu.org/licenses/>. */
/*************************************************************************************/
#ifndef _SLICER_FOR_H
#define _SLICER_FOR_H
#ifdef INVERT_LOOP_BOUNDARIES
#define EXECUTE(get_slicer,slicer_data,upper2,lower2,k_offset,step2,chunk2)\
for ( i = 0; i < NUM_ITERS; i++ ) {\
_loop_data.offset = -k_offset; \
sys.loadPlugin( "slicer-" + std::string(get_slicer) ); \
Slicer *slicer = sys.getSlicer ( get_slicer ); \
WD * wd = new WorkDescriptor( new SMPDD( main__loop_1 ), sizeof( _loop_data ), __alignof__(nanos_loop_info_t),( void * ) &_loop_data, 0, NULL, NULL );\
wd->setSlicer(slicer);\
_loop_data.loop_info.lower = lower2 + k_offset; \
_loop_data.loop_info.upper = upper2 + k_offset; \
_loop_data.loop_info.step = step2; \
_loop_data.loop_info.chunk = chunk2; \
WD *wg = getMyThreadSafe()->getCurrentWD();\
wg->addWork( *wd );\
if ( sys.getPMInterface().getInternalDataSize() > 0 ) { \
char *idata = NEW char[sys.getPMInterface().getInternalDataSize()]; \
sys.getPMInterface().initInternalData( idata ); \
wd->setInternalData( idata ); \
} \
sys.setupWD( *wd, (nanos::WD *) wg );\
sys.submit( *wd );\
wg->waitCompletion();\
if (step2 > 0 ) for ( int j = lower2+k_offset; j <= upper2+k_offset; j+= step2 ) A[j+_loop_data.offset]--; \
else if ( step2 < 0 ) for ( int j = lower2+k_offset; j >= upper2+k_offset; j+= step2 ) A[j+_loop_data.offset]--; \
}
#else
#define EXECUTE(get_slicer,slicer_data,lower2,upper2,k_offset,step2,chunk2)\
for ( i = 0; i < NUM_ITERS; i++ ) {\
_loop_data.offset = -k_offset; \
sys.loadPlugin( "slicer-" + std::string(get_slicer) ); \
Slicer *slicer = sys.getSlicer ( get_slicer ); \
WD * wd = new WorkDescriptor( new SMPDD( main__loop_1 ), sizeof( _loop_data ), __alignof__(nanos_loop_info_t),( void * ) &_loop_data, 0, NULL, NULL );\
wd->setSlicer(slicer);\
_loop_data.loop_info.lower = lower2 + k_offset; \
_loop_data.loop_info.upper = upper2 + k_offset; \
_loop_data.loop_info.step = step2; \
_loop_data.loop_info.chunk = chunk2; \
WD *wg = getMyThreadSafe()->getCurrentWD();\
wg->addWork( *wd );\
if ( sys.getPMInterface().getInternalDataSize() > 0 ) { \
char *idata = NEW char[sys.getPMInterface().getInternalDataSize()]; \
sys.getPMInterface().initInternalData( idata ); \
wd->setInternalData( idata ); \
} \
sys.setupWD( *wd, (nanos::WD *) wg );\
sys.submit( *wd );\
wg->waitCompletion();\
if (step2 > 0 ) for ( int j = lower2+k_offset; j <= upper2+k_offset; j+= step2 ) A[j+_loop_data.offset]--; \
else if ( step2 < 0 ) for ( int j = lower2+k_offset; j >= upper2+k_offset; j+= step2 ) A[j+_loop_data.offset]--; \
}
#endif
#define FINALIZE(type,lower,upper,offset,step,chunk)\
print_vector();\
if ( I[0] == STEP_ERROR ) { step_error = true; I[0] = 0;}\
for ( i = 0; i < VECTOR_SIZE+2*VECTOR_MARGIN; i++ )\
if ( I[i] != 0 ) {\
if ( (i < VECTOR_MARGIN) || (i > (VECTOR_SIZE + VECTOR_MARGIN))) out_of_range = true;\
if ( (I[i] != NUM_ITERS) && (I[i] != -NUM_ITERS)) race_condition = true;\
I[i] = 0; check = false; p_check = false;\
}\
fprintf(stderr, "%s, lower (%s), upper (%s), offset (%s), step(%+03d), chunk(%02d): %s %s %s %s\n",\
type, lower, upper, offset, step, chunk,\
p_check?" successful":"unsuccessful",\
out_of_range?" - Out of Range":"",\
race_condition?" - Race Condition":"",\
step_error?" - Step Error":""\
);\
p_check = true; out_of_range = false; race_condition = false; step_error = false;
#define TEST(test_type,test_slicer_data,test_step,test_chunk)\
EXECUTE(test_type, test_slicer_data, 0, VECTOR_SIZE, 0, +test_step, test_chunk)\
FINALIZE (test_type,"0","+","+0000",+test_step,test_chunk)\
EXECUTE(test_type, test_slicer_data, VECTOR_SIZE-1, -1, 0, -test_step, test_chunk)\
FINALIZE (test_type,"+","0","+0000",-test_step,test_chunk)\
EXECUTE(test_type, test_slicer_data, 0, VECTOR_SIZE, -VECTOR_SIZE, +test_step, test_chunk)\
FINALIZE (test_type,"-","0","-VS ",+test_step,test_chunk)\
EXECUTE(test_type, test_slicer_data, VECTOR_SIZE-1, -1, -VECTOR_SIZE, -test_step, test_chunk)\
FINALIZE (test_type,"0","-","-VS ",-test_step,test_chunk)\
EXECUTE(test_type, test_slicer_data, 0, VECTOR_SIZE, VECTOR_SIZE/2, +test_step, test_chunk)\
FINALIZE (test_type,"+","+","+VS/2",+test_step,test_chunk)\
EXECUTE(test_type, test_slicer_data, VECTOR_SIZE-1, -1, VECTOR_SIZE/2, -test_step, test_chunk)\
FINALIZE (test_type,"+","+","+VS/2",-test_step,test_chunk)\
EXECUTE(test_type, test_slicer_data, 0, VECTOR_SIZE, -(VECTOR_SIZE/2), +test_step, test_chunk)\
FINALIZE (test_type,"-","+","-VS/2",+test_step,test_chunk)\
EXECUTE(test_type, test_slicer_data, VECTOR_SIZE-1, -1, -(VECTOR_SIZE/2), -test_step, test_chunk)\
FINALIZE (test_type,"+","-","-VS/2",-test_step,test_chunk)\
EXECUTE(test_type, test_slicer_data, 0, VECTOR_SIZE, -(2*VECTOR_SIZE), +test_step, test_chunk)\
FINALIZE (test_type,"-","-","-VS ",+test_step,test_chunk)\
EXECUTE(test_type, test_slicer_data, VECTOR_SIZE-1, -1, -(2*VECTOR_SIZE), -test_step, test_chunk)\
FINALIZE (test_type,"-","-","-VS ",-test_step,test_chunk)
#define TEST_SLICER(test_slicer_type, test_slicer_slicer_data) \
TEST(test_slicer_type, test_slicer_slicer_data, NUM_A, NUM_A)\
TEST(test_slicer_type, test_slicer_slicer_data, NUM_B, NUM_A)\
TEST(test_slicer_type, test_slicer_slicer_data, NUM_C, NUM_A)\
TEST(test_slicer_type, test_slicer_slicer_data, NUM_A, NUM_B)\
TEST(test_slicer_type, test_slicer_slicer_data, NUM_B, NUM_B)\
TEST(test_slicer_type, test_slicer_slicer_data, NUM_C, NUM_B)\
TEST(test_slicer_type, test_slicer_slicer_data, NUM_A, NUM_C)\
TEST(test_slicer_type, test_slicer_slicer_data, NUM_B, NUM_C)\
TEST(test_slicer_type, test_slicer_slicer_data, NUM_C, NUM_C)
#endif
/*************************************************************************************/
/* Copyright 2009-2018 Barcelona Supercomputing Center */
/* */
/* This file is part of the NANOS++ library. */
/* */
/* NANOS++ is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU Lesser General Public License as published by */
/* the Free Software Foundation, either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* NANOS++ is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU Lesser General Public License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with NANOS++. If not, see <https://www.gnu.org/licenses/>. */
/*************************************************************************************/
#ifndef _SLICER_FOR_H
#define _SLICER_FOR_H
#if !defined(NUM_ITERS) || \
!defined(VECTOR_SIZE) || \
!defined(VECTOR_MARGIN)
#error "Define NUM_ITERS, VECTOR_SIZE and VECTOR_MARGIN before including worksharing.hpp"
#endif
#ifndef NUM_ITERS
#error Define NUM_ITERS before including __FILE__
#endif
#include "nanos.h"
#include "system_decl.hpp"
#include "slicer_decl.hpp"
#include "smpprocessor.hpp"
#include "plugin.hpp"
#include <stdio.h>
#include <string>
using namespace nanos;
using namespace nanos::ext;
enum { STEP_ERR = -17 };
typedef struct {
nanos_loop_info_t loop_info;
int offset;
} main__loop_1_data_t;
void main__loop_1(void *args);
void execute(std::string slicer_name, int lower, int upper, int offset, int step, int chunk);
int check(const char *desc, const char *lower, const char *upper,
const char *offset, int step, int chunk);
int slicer_test(std::string slicer, const char *desc, int step, int chunk);
void print_vector();
static int I[VECTOR_SIZE+2*VECTOR_MARGIN] = {0};
static int *A = &I[VECTOR_MARGIN];
void main__loop_1 ( void *args )
{
main__loop_1_data_t *hargs = (main__loop_1_data_t*) args;
int lower = hargs->loop_info.lower;
int upper = hargs->loop_info.upper;
int step = hargs->loop_info.step;
int offset = hargs->offset;
#ifdef VERBOSE
fprintf(stderr,"[%d..%d:%d/%d]", lower, upper, step, offset);
#endif
if ( step > 0 ) {
for ( int i = lower; i <= upper; i += step) {
A[i+offset]++;
}
}
else if ( step < 0 ) {
for ( int i = lower; i >= upper; i += step) {
A[i+offset]++;
}
}
else {
A[-VECTOR_MARGIN] = STEP_ERR;
}
}
void execute(std::string slicer_name, int lower, int upper, int offset, int step, int chunk)
{
#ifdef INVERT_LOOP_BOUNDARIES
int _lower = lower;
lower = upper;
upper = _lower;
#endif
for (int i = 0; i < NUM_ITERS; i++) {
/* Load plugin */
sys.loadPlugin( "slicer-" + slicer_name );
Slicer *slicer = sys.getSlicer ( slicer_name );
/* set up Work Descriptor */
main__loop_1_data_t _loop_data;
_loop_data.offset = -offset;
WD * wd = new WorkDescriptor( new SMPDD( main__loop_1 ), sizeof( _loop_data ),
__alignof__(nanos_loop_info_t),( void * ) &_loop_data, 0, NULL, NULL );
wd->setSlicer( slicer );
_loop_data.loop_info.lower = lower + offset;
_loop_data.loop_info.upper = upper + offset;
_loop_data.loop_info.step = step;
_loop_data.loop_info.chunk = chunk;
/* Submit and wait completion */
WD *wg = getMyThreadSafe()->getCurrentWD();
wg->addWork( *wd );
if ( sys.getPMInterface().getInternalDataSize() > 0 ) {
char *idata = NEW char[sys.getPMInterface().getInternalDataSize()];
sys.getPMInterface().initInternalData( idata );
wd->setInternalData( idata );
}
sys.setupWD( *wd, (nanos::WD *) wg );
sys.submit( *wd );
wg->waitCompletion();
/* Undo increment done by the worksharing */
if (step > 0)
for (int j = lower+offset; j <= upper+offset; j+= step)
A[j-offset]--;
else if (step < 0)
for (int j = lower+offset; j >= upper+offset; j+= step)
A[j-offset]--;
}
}
int check(const char *desc, const char *lower, const char *upper,
const char *offset, int step, int chunk)
{
int error = 0;
bool out_of_range = false, race_condition = false, step_error = false;
if (I[0] == STEP_ERR) {
step_error = true;
I[0] = 0;
}
for (int i = 0; i < VECTOR_SIZE+2*VECTOR_MARGIN; i++) {
if (I[i] != 0) {
if ((i < VECTOR_MARGIN) || (i > (VECTOR_SIZE + VECTOR_MARGIN))) out_of_range = true;
if ((I[i] != NUM_ITERS) && (I[i] != -NUM_ITERS)) race_condition = true;
I[i] = 0;
error++;
}
}
fprintf(stderr,
"%s, lower (%s), upper (%s), offset (%s), step(%+03d), chunk(%02d): %s%s%s%s\n",
desc, lower, upper, offset, step, chunk,
error == 0 ? " successful" : " unsuccessful",
out_of_range ? " - Out of Range" : "",
race_condition ? " - Race Condition" : "",
step_error ? " - Step Error" : ""
);
return error;
}
int slicer_test(std::string slicer, const char *desc, int step, int chunk)
{
int error = 0;
execute(slicer, 0, VECTOR_SIZE, 0, +step, chunk);
error += check(desc, "0", "+", "+0000", +step, chunk);
execute(slicer, VECTOR_SIZE-1, -1, 0, -step, chunk);
error += check(desc, "+", "0", "+0000", -step, chunk);
execute(slicer, 0, VECTOR_SIZE, -VECTOR_SIZE, +step, chunk);
error += check(desc, "-", "0", "-VS ", +step, chunk);
execute(slicer, VECTOR_SIZE-1, -1, -VECTOR_SIZE, -step, chunk);
error += check(desc, "0", "-", "-VS ", -step, chunk);
execute(slicer, 0, VECTOR_SIZE, VECTOR_SIZE/2, +step, chunk);
error += check(desc, "+", "+", "+VS/2", +step, chunk);
execute(slicer, VECTOR_SIZE-1, -1, VECTOR_SIZE/2, -step, chunk);
error += check(desc, "+", "+", "+VS/2", -step, chunk);
execute(slicer, 0, VECTOR_SIZE, -(VECTOR_SIZE/2), +step, chunk);
error += check(desc, "-", "+", "-VS/2", +step, chunk);
execute(slicer, VECTOR_SIZE-1, -1, -(VECTOR_SIZE/2), -step, chunk);
error += check(desc, "+", "-", "-VS/2", -step, chunk);
execute(slicer, 0, VECTOR_SIZE, -(2*VECTOR_SIZE), +step, chunk);
error += check(desc, "-", "-", "-VS ", +step, chunk);
execute(slicer, VECTOR_SIZE-1, -1, -(2*VECTOR_SIZE), -step, chunk);
error += check(desc, "-", "-", "-VS ", -step, chunk);
return error;
}
void print_vector()
{
#ifdef EXTRA_VERBOSE
for (int i = -VECTOR_MARGIN; i < 0; i++) fprintf(stderr,"%d:",A[i]);
fprintf(stderr,"[");
for (int i = 0; i < VECTOR_SIZE; i++) fprintf(stderr,"%d:",A[i]);
fprintf(stderr,"]");
for (int i = VECTOR_SIZE; i < VECTOR_SIZE+VECTOR_MARGIN; i++ ) fprintf(stderr,"%d:",A[i]);
fprintf(stderr,"\n");
#endif
}
#endif /* SLICER_FOR_HPP */
......@@ -23,24 +23,6 @@ test_generator=gens/core-generator
</testinfo>
*/
#include "config.hpp"
#include <nanos.h>
#include <iostream>
#include "smpprocessor.hpp"
#include "system.hpp"
#include "slicer.hpp"
#include "plugin.hpp"
#include "slicer_for.h"
using namespace std;
using namespace nanos;
using namespace nanos::ext;
#define NUM_ITERS 1
#define VECTOR_SIZE 1000
#define VECTOR_MARGIN 20
// The program will create all possible permutation using NUM_{A,B,C}
// for step and chunk. For a complete testing purpose they have to be:
// - single step/chunk: 1 ('one')
......@@ -50,86 +32,39 @@ using namespace nanos::ext;
#define NUM_B 5
#define NUM_C 13
#define STEP_ERROR 17
// Mandatory definitions before including "slicer_for.hpp"
#define NUM_ITERS 1
#define VECTOR_SIZE 1000
#define VECTOR_MARGIN 20
// Output information level:
// Optional definitions before including "slicer_for.hpp"
//#define VERBOSE
//#define EXTRA_VERBOSE
//#define INVERT_LOOP_BOUNDARIES
int *A;
void print_vector();
typedef struct {
nanos_loop_info_t loop_info;
int offset;
} main__loop_1_data_t;
void main__loop_1 ( void *args );
void main__loop_1 ( void *args )
{
int i;
main__loop_1_data_t *hargs = (main__loop_1_data_t * ) args;
#ifdef VERBOSE
fprintf(stderr,"[%d..%d:%d/%d]",
hargs->loop_info.lower, hargs->loop_info.upper, hargs->loop_info.step, hargs->offset);
#endif
if ( hargs->loop_info.step > 0 )
{
for ( i = hargs->loop_info.lower; i <= hargs->loop_info.upper; i += hargs->loop_info.step) {
A[i+hargs->offset]++;
}
}
else if ( hargs->loop_info.step < 0 )
{
for ( i = hargs->loop_info.lower; i >= hargs->loop_info.upper; i += hargs->loop_info.step) {
A[i+hargs->offset]++;
}
}
else {A[-VECTOR_MARGIN] = STEP_ERROR; }
}
void print_vector ()
{
#ifdef EXTRA_VERBOSE
for ( int j = -5; j < 0; j++ ) fprintf(stderr,"%d:",A[j]);
fprintf(stderr,"[");
for ( int j = 0; j <= VECTOR_SIZE; j++ ) fprintf(stderr,"%d:",A[j]);
fprintf(stderr,"]");
for ( int j = VECTOR_SIZE+1; j < VECTOR_SIZE+6; j++ ) fprintf(stderr,"%d:",A[j]);
fprintf(stderr,"\n");
#endif
}
#include "slicer_for.hpp"
#include <iostream>
int main ( int argc, char **argv )
{
int i;
bool check = true;
bool p_check = true, out_of_range = false, race_condition = false, step_error= false;
int I[VECTOR_SIZE+2*VECTOR_MARGIN];
main__loop_1_data_t _loop_data;
A = &I[VECTOR_MARGIN];
int error = 0;
#ifdef VERBOSE
fprintf(stderr,"SLICER_FOR: Initializing vector.\n");
#endif
// initialize vector
for ( i = 0; i < VECTOR_SIZE+2*VECTOR_MARGIN; i++ ) I[i] = 0;
// omp for: dynamic policy (chunk != 0)
#ifdef VERBOSE
fprintf(stderr,"SLICER_FOR: dynamic_for begins.\n");
#endif
TEST_SLICER("dynamic_for", SlicerDataFor)
error += slicer_test("dynamic_for", "sched_dynamic (A,A)", NUM_A, NUM_A);
error += slicer_test("dynamic_for", "sched_dynamic (B,A)", NUM_B, NUM_A);
error += slicer_test("dynamic_for", "sched_dynamic (C,A)", NUM_C, NUM_A);
error += slicer_test("dynamic_for", "sched_dynamic (A,B)", NUM_A, NUM_B);
error += slicer_test("dynamic_for", "sched_dynamic (B,B)", NUM_B, NUM_B);
error += slicer_test("dynamic_for", "sched_dynamic (C,B)", NUM_C, NUM_B);
error += slicer_test("dynamic_for", "sched_dynamic (A,C)", NUM_A, NUM_C);
error += slicer_test("dynamic_for", "sched_dynamic (B,C)", NUM_B, NUM_C);
error += slicer_test("dynamic_for", "sched_dynamic (C,C)", NUM_C, NUM_C);
#ifdef VERBOSE
fprintf(stderr,"SLICER_FOR: dynamic_for ends.\n");
#endif
// final result
//fprintf(stderr, "%s : %s\n", argv[0], check ? " successful" : "unsuccessful");
if (check) { return 0; } else { return -1; }
std::cout << argv[0] << (!error ? ": successful" : ": unsuccessful") << std::endl;
return error ? EXIT_FAILURE : EXIT_SUCCESS;
}
......@@ -23,25 +23,6 @@ test_generator=gens/core-generator
</testinfo>
*/
#include "config.hpp"
#include <nanos.h>
#include <iostream>
#include "smpprocessor.hpp"
#include "system.hpp"
#include "slicer.hpp"
#include "plugin.hpp"
#define INVERT_LOOP_BOUNDARIES
#include "slicer_for.h"
using namespace std;
using namespace nanos;
using namespace nanos::ext;
#define NUM_ITERS 20
#define VECTOR_SIZE 1000
#define VECTOR_MARGIN 20
// The program will create all possible permutation using NUM_{A,B,C}
// for step and chunk. For a complete testing purpose they have to be:
// - single step/chunk: 1 ('one')
......@@ -51,86 +32,39 @@ using namespace nanos::ext;
#define NUM_B 5
#define NUM_C 13
#define STEP_ERROR 17
// Mandatory definitions before including "slicer_for.hpp"
#define NUM_ITERS 20
#define VECTOR_SIZE 1000
#define VECTOR_MARGIN 20
// Output information level:
// Optional definitions before including "slicer_for.hpp"
//#define VERBOSE
//#define EXTRA_VERBOSE
#define INVERT_LOOP_BOUNDARIES
int *A;
void print_vector();
typedef struct {
nanos_loop_info_t loop_info;
int offset;
} main__loop_1_data_t;
void main__loop_1 ( void *args );
void main__loop_1 ( void *args )
{
int i;
main__loop_1_data_t *hargs = (main__loop_1_data_t * ) args;
#ifdef VERBOSE
fprintf(stderr,"[%d..%d:%d/%d]",
hargs->loop_info.lower, hargs->loop_info.upper, hargs->loop_info.step, hargs->offset);
#endif
if ( hargs->loop_info.step > 0 )
{
for ( i = hargs->loop_info.lower; i <= hargs->loop_info.upper; i += hargs->loop_info.step) {
A[i+hargs->offset]++;
}
}
else if ( hargs->loop_info.step < 0 )
{
for ( i = hargs->loop_info.lower; i >= hargs->loop_info.upper; i += hargs->loop_info.step) {
A[i+hargs->offset]++;
}
}
else {A[-VECTOR_MARGIN] = STEP_ERROR; }
}
void print_vector ()
{
#ifdef EXTRA_VERBOSE
for ( int j = -5; j < 0; j++ ) fprintf(stderr,"%d:",A[j]);
fprintf(stderr,"[");
for ( int j = 0; j <= VECTOR_SIZE; j++ ) fprintf(stderr,"%d:",A[j]);
fprintf(stderr,"]");
for ( int j = VECTOR_SIZE+1; j < VECTOR_SIZE+6; j++ ) fprintf(stderr,"%d:",A[j]);
fprintf(stderr,"\n");
#endif
}
#include "slicer_for.hpp"
#include <iostream>
int main ( int argc, char **argv )
{
int i;
bool check = true;
bool p_check = true, out_of_range = false, race_condition = false, step_error= false;
int I[VECTOR_SIZE+2*VECTOR_MARGIN];
main__loop_1_data_t _loop_data;
A = &I[VECTOR_MARGIN];
int error = 0;
#ifdef VERBOSE
fprintf(stderr,"SLICER_FOR: Initializing vector.\n");
#endif
// initialize vector
for ( i = 0; i < VECTOR_SIZE+2*VECTOR_MARGIN; i++ ) I[i] = 0;
// omp for: dynamic policy (chunk != 0)
#ifdef VERBOSE
fprintf(stderr,"SLICER_FOR: dynamic_for begins.\n");
#endif
TEST_SLICER("dynamic_for", SlicerDataFor)
error += slicer_test("dynamic_for", "sched_dynamic (A,A)", NUM_A, NUM_A);
error += slicer_test("dynamic_for", "sched_dynamic (B,A)", NUM_B, NUM_A);
error += slicer_test("dynamic_for", "sched_dynamic (C,A)", NUM_C, NUM_A);
error += slicer_test("dynamic_for", "sched_dynamic (A,B)", NUM_A, NUM_B);
error += slicer_test("dynamic_for", "sched_dynamic (B,B)", NUM_B, NUM_B);
error += slicer_test("dynamic_for", "sched_dynamic (C,B)", NUM_C, NUM_B);
error += slicer_test("dynamic_for", "sched_dynamic (A,C)", NUM_A, NUM_C);
error += slicer_test("dynamic_for", "sched_dynamic (B,C)", NUM_B, NUM_C);
error += slicer_test("dynamic_for", "sched_dynamic (C,C)", NUM_C, NUM_C);
#ifdef VERBOSE
fprintf(stderr,"SLICER_FOR: dynamic_for ends.\n");
#endif
// final result
//fprintf(stderr, "%s : %s\n", argv[0], check ? " successful" : "unsuccessful");
if (check) { return 0; } else { return -1; }
std::cout << argv[0] << (!error ? ": successful" : ": unsuccessful") << std::endl;
return error ? EXIT_FAILURE : EXIT_SUCCESS;
}
......@@ -23,24 +23,6 @@ test_generator=gens/core-generator
</testinfo>
*/
#include "config.hpp"
#include <nanos.h>
#include <iostream>
#include "smpprocessor.hpp"
#include "system.hpp"
#include "slicer.hpp"
#include "plugin.hpp"
#include "slicer_for.h"
using namespace std;
using namespace nanos;
using namespace nanos::ext;
#define NUM_ITERS 20
#define VECTOR_SIZE 1000
#define VECTOR_MARGIN 20
// The program will create all possible permutation using NUM_{A,B,C}
// for step and chunk. For a complete testing purpose they have to be:
// - single step/chunk: 1 ('one')
......@@ -50,86 +32,39 @@ using namespace nanos::ext;
#define NUM_B 5
#define NUM_C 13
#define STEP_ERROR 17
// Mandatory definitions before including "slicer_for.hpp"
#define NUM_ITERS 20
#define VECTOR_SIZE 1000
#define VECTOR_MARGIN 20
// Output information level:
// Optional definitions before including "slicer_for.hpp"
//#define VERBOSE
//#define EXTRA_VERBOSE
//#define INVERT_LOOP_BOUNDARIES
int *A;
void print_vector();
typedef struct {
nanos_loop_info_t loop_info;
int offset;
} main__loop_1_data_t;
void main__loop_1 ( void *args );
void main__loop_1 ( void *args )
{
int i;
main__loop_1_data_t *hargs = (main__loop_1_data_t * ) args;
#ifdef VERBOSE
fprintf(stderr,"[%d..%d:%d/%d]",
hargs->loop_info.lower, hargs->loop_info.upper, hargs->loop_info.step, hargs->offset);
#endif
if ( hargs->loop_info.step > 0 )
{
for ( i = hargs->loop_info.lower; i <= hargs->loop_info.upper; i += hargs->loop_info.step) {
A[i+hargs->offset]++;
}
}
else if ( hargs->loop_info.step < 0 )
{
for ( i = hargs->loop_info.lower; i >= hargs->loop_info.upper; i += hargs->loop_info.step) {
A[i+hargs->offset]++;
}
}
else {A[-VECTOR_MARGIN] = STEP_ERROR; }
}
void print_vector ()
{
#ifdef EXTRA_VERBOSE
for ( int j = -5; j < 0; j++ ) fprintf(stderr,"%d:",A[j]);
fprintf(stderr,"[");
for ( int j = 0; j <= VECTOR_SIZE; j++ ) fprintf(stderr,"%d:",A[j]);
fprintf(stderr,"]");
for ( int j = VECTOR_SIZE+1; j < VECTOR_SIZE+6; j++ ) fprintf(stderr,"%d:",A[j]);
fprintf(stderr,"\n");
#endif
}
#include "slicer_for.hpp"
#include <iostream>
int main ( int argc, char **argv )
{
int i;
bool check = true;
bool p_check = true, out_of_range = false, race_condition = false, step_error= false;
int I[VECTOR_SIZE+2*VECTOR_MARGIN];
main__loop_1_data_t _loop_data;
A = &I[VECTOR_MARGIN];
#ifdef VERBOSE
fprintf(stderr,"SLICER_FOR: Initializing vector.\n");
#endif
// initialize vector