Commit 02c93554 authored by Pietro Incardona's avatar Pietro Incardona

Changing vcluster initialization

parent 8d4d2abd
#include "VCluster.hpp"
Vcluster * global_v_cluster = NULL;
Vcluster * global_v_cluster_private = NULL;
// number of vcluster instances
size_t n_vcluster = 0;
......@@ -975,8 +975,7 @@ public:
// Function to initialize the global VCluster //
extern Vcluster * global_v_cluster;
extern Vcluster * global_v_cluster_private;
/*! \brief Initialize a global instance of Runtime Virtual Cluster Machine
*
......@@ -984,15 +983,47 @@ extern Vcluster * global_v_cluster;
*
*/
static inline void init_global_v_cluster(int *argc, char ***argv)
static inline void init_global_v_cluster_private(int *argc, char ***argv)
{
if (global_v_cluster_private == NULL)
global_v_cluster_private = new Vcluster(argc,argv);
}
static inline void delete_global_v_cluster_private()
{
delete global_v_cluster_private;
}
static inline Vcluster & create_vcluster()
{
#ifdef SE_CLASS1
if (global_v_cluster_private == NULL)
std::cerr << __FILE__ << ":" << __LINE__ << " Error you must call openfpm_init before using any distributed data structures";
#endif
return *global_v_cluster_private;
}
/*! \brief Initialize the library
*
* This function MUST be called before any other function
*
*/
static inline void openfpm_init(int *argc, char ***argv)
{
if (global_v_cluster == NULL)
global_v_cluster = new Vcluster(argc,argv);
init_global_v_cluster_private(argc,argv);
}
static inline void delete_global_v_cluster()
/*! \brief Finalize the library
*
* This function MUST be called at the end of the program
*
*/
static inline void openfpm_finalize()
{
delete global_v_cluster;
delete_global_v_cluster_private();
}
#endif
......
......@@ -22,7 +22,7 @@ BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather)
{
for (size_t i = 0 ; i < 100 ; i++)
{
Vcluster & vcl = *global_v_cluster;
Vcluster & vcl = create_vcluster();
if (vcl.getProcessingUnits() >= 32)
return;
......@@ -56,7 +56,7 @@ BOOST_AUTO_TEST_CASE (Vcluster_semantic_struct_gather)
{
for (size_t i = 0 ; i < 100 ; i++)
{
Vcluster & vcl = *global_v_cluster;
Vcluster & vcl = create_vcluster();
if (vcl.getProcessingUnits() >= 32)
return;
......@@ -99,7 +99,7 @@ BOOST_AUTO_TEST_CASE (Vcluster_semantic_scatter)
{
for (size_t i = 0 ; i < 100 ; i++)
{
Vcluster & vcl = *global_v_cluster;
Vcluster & vcl = create_vcluster();
if (vcl.getProcessingUnits() >= 32)
return;
......@@ -145,7 +145,7 @@ BOOST_AUTO_TEST_CASE (Vcluster_semantic_struct_scatter)
{
for (size_t i = 0 ; i < 100 ; i++)
{
Vcluster & vcl = *global_v_cluster;
Vcluster & vcl = create_vcluster();
if (vcl.getProcessingUnits() >= 32)
return;
......
......@@ -40,8 +40,8 @@ void * msg_alloc(size_t msg_i ,size_t total_msg, size_t total_p, size_t i,size_t
{
openfpm::vector<openfpm::vector<unsigned char>> * v = static_cast<openfpm::vector<openfpm::vector<unsigned char>> *>(ptr);
if (global_v_cluster->getProcessingUnits() <= 8)
{if (totp_check) BOOST_REQUIRE_EQUAL(total_p,global_v_cluster->getProcessingUnits()-1);}
if (create_vcluster().getProcessingUnits() <= 8)
{if (totp_check) BOOST_REQUIRE_EQUAL(total_p,create_vcluster().getProcessingUnits()-1);}
else
{if (totp_check) BOOST_REQUIRE_EQUAL(total_p,(size_t)8);}
......@@ -136,7 +136,7 @@ template <unsigned int ip> std::string method()
template<unsigned int ip> void test_no_send_some_peer()
{
Vcluster & vcl = *global_v_cluster;
Vcluster & vcl = create_vcluster();
size_t n_proc = vcl.getProcessingUnits();
......@@ -228,7 +228,7 @@ template<unsigned int ip> void test_no_send_some_peer()
template<unsigned int ip> void test()
{
Vcluster & vcl = *global_v_cluster;
Vcluster & vcl = create_vcluster();
// send/recv messages
......@@ -325,7 +325,7 @@ template<unsigned int ip> void test()
}
}
std::srand(global_v_cluster->getProcessUnitID());
std::srand(create_vcluster().getProcessUnitID());
std::default_random_engine eg;
std::uniform_int_distribution<int> d(0,n_proc/8);
......
......@@ -21,14 +21,14 @@ BOOST_AUTO_TEST_SUITE( VCluster_test )
BOOST_AUTO_TEST_CASE (Vcluster_robustness)
{
Vcluster & vcl = *global_v_cluster;
Vcluster & vcl = create_vcluster();
vcl.execute();
}
BOOST_AUTO_TEST_CASE( VCluster_use_reductions)
{
Vcluster & vcl = *global_v_cluster;
Vcluster & vcl = create_vcluster();
unsigned char uc = 1;
char c = 1;
......@@ -112,7 +112,7 @@ BOOST_AUTO_TEST_CASE( VCluster_use_reductions)
BOOST_AUTO_TEST_CASE(VCluster_send_recv)
{
Vcluster & vcl = *global_v_cluster;
Vcluster & vcl = create_vcluster();
test_send_recv_complex(N_V_ELEMENTS,vcl);
test_send_recv_primitives<unsigned char>(N_V_ELEMENTS,vcl);
......@@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(VCluster_send_recv)
BOOST_AUTO_TEST_CASE(VCluster_allgather)
{
Vcluster & vcl = *global_v_cluster;
Vcluster & vcl = create_vcluster();
if (vcl.getProcessingUnits() < 256)
test_single_all_gather_primitives<unsigned char>(vcl);
......
......@@ -13,11 +13,11 @@
struct ut_start {
ut_start() {
BOOST_TEST_MESSAGE("Initialize global VCluster");
init_global_v_cluster(&boost::unit_test::framework::master_test_suite().argc,&boost::unit_test::framework::master_test_suite().argv);
openfpm_init(&boost::unit_test::framework::master_test_suite().argc,&boost::unit_test::framework::master_test_suite().argv);
}
~ut_start() { BOOST_TEST_MESSAGE("Delete global VClster");
delete_global_v_cluster(); }
openfpm_finalize(); }
};
//____________________________________________________________________________//
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment