1 #if COMPILATION_INSTRUCTIONS
2 mpic++ -O3 -std=c++14 -Wall -Wextra `#-Wfatal-errors` -I$HOME/prj/alf $0 -o $0x.x && mpirun -n 4 $0x.x $@ && rm -f $0x.x; exit
3 #endif
4 
5 #include "../../mpi3/shm/allocator.hpp"
6 #include "../../mpi3/main.hpp"
7 
8 #include "boost/multi/array.hpp"
9 #include<scoped_allocator>
10 
11 namespace mpi3 = boost::mpi3;
12 namespace multi = boost::multi;
13 using std::cout;
14 
15 namespace boost{namespace mpi3{namespace shm{
16 namespace multi{
17 	template<class T, int D>
18 	using array = boost::multi::array<T, D, mpi3::shm::allocator<T>>;
19 }
20 }}}
21 
main(int,char * [],mpi3::communicator world)22 int mpi3::main(int, char*[], mpi3::communicator world){
23 
24 	mpi3::shared_communicator node = world.split_shared();
25 
26 	multi::array<double, 2, shm::allocator<double>> A({16, 16}, node);
27 	assert(A[2][2] == 0);
28 	node.barrier();
29 	if(node.root()) A[2][2] = 3.14;
30 	node.barrier();
31 	assert(A[2][2] == 3.14);
32 
33 	shm::multi::array<double, 2> B = A;
34 //	multi::array<double, 2, mpi3::shm::allocator<double>> B = A;
35 	assert(A[2][2] == 3.14);
36 	assert(B[2][2] == 3.14);
37 
38 	shm::multi::array<double, 2> C({1, 1}, node);
39 	C.reextent({30,30});
40 	assert(C.size() == 30);
41 //	C = std::move(A);
42 //	assert(C[2][2] == 3.14);
43 //	assert(A.size()==0);
44 	node.barrier();
45 
46 	{
47 		std::vector<shm::multi::array<double, 2>> w;
48 		std::vector<shm::multi::array<double, 2>> v(2, shm::multi::array<double, 2>(shm::allocator<double>{node}));
49 		v.reserve(3);
50 		v.emplace_back(shm::multi::array<double, 2>({10,10}, node));
51 		v.emplace_back(node);
52 		v.emplace_back(shm::multi::array<double, 2>({20,20}, node));
53 		v.emplace_back(shm::multi::array<double, 2>({15,15}, node));
54 
55 
56 		if(world.rank() == 0) v[4][2][3] = 5.;
57 		world.barrier();
58 		if(world.rank() == 1) assert(v[4][2][3] == 5.);
59 		world.barrier();
60 		v[2].reextent({30, 30});
61 		assert( v[2].size() == 30 );
62 		v.pop_back();
63 		assert( v.back().size() == 20 );
64 	}
65 	shm::multi::array<double, 2> AA({0,0}, node);
66 	assert(AA.size() == 0);
67 	{
68 		boost::multi::array<shm::multi::array<double, 2>, 1, shm::allocator<shm::multi::array<double, 2>>> v(std::array<boost::multi::index_extension,1>{{3}}, shm::allocator<shm::multi::array<double, 2>>{node});
69 		v[0].reextent({10, 10});
70 		v[1].reextent({20, 20});
71 		v[2].reextent({30, 30});
72 		if(world.rank() == 1) v[1][2][3] = 5.;
73 		world.barrier();
74 		if(world.rank() == 1) assert(v[1][2][3] == 5.);
75 	}
76 	{
77 		using inner_ma = boost::multi::array<double, 2, shm::allocator<double>>;
78 	//	using dd = inner_ma::allocator_type;
79 		using outter_vec = std::vector<inner_ma, std::allocator<inner_ma>>;
80 		using scoped_alloc = std::scoped_allocator_adaptor<std::allocator<inner_ma>, shm::allocator<double>>;
81 		shm::allocator<double> aaaa{node};
82 		scoped_alloc sa(std::allocator<inner_ma>{}, aaaa );
83 		outter_vec v(sa);
84 	//	std::vector<inner_ma> v;
85 		v.emplace_back(shm::allocator<double>{node});
86 	//	v.emplace_back(std::array<boost::multi::index_extension,2>{{10, 10}});
87 //		v.resize(10, {node});
88 	//	boost::multi::array<shm::multi::array<double, 2>, 1, std::scoped_allocator_adaptor<std::allocator<boost::multi::array<double, 2, shm::allocator<double>>>, shm::allocator<double>> > v(sa);
89 		cout << "fdfsd " << std::uses_allocator<inner_ma, shm::allocator<double>>{} << std::endl;
90 		cout << "fdffddf " << std::is_constructible<inner_ma, shm::allocator<double>&>{} << std::endl;
91 	}
92 	return 0;
93 }
94 
95