You should allocate large chunks of memory on the heap instead of the stack:
int array[2*P][2*P][2*P]; // placed on the stack
int* array = new int[8*P*P*P]; // placed on the heap
vector<int> array(8*P*P*P); // vector uses heap storage
On the stack you are basically limited to some megabytes of memory, while on the heap you have a good share of you computer RAM (e.g. several GB) available.
Just keep in mind: a 3D array of 1000*1000*1000 ints requires 4 GB of memory!
Additionally I would suggest to build a small class for your 3D array:
template<typename K>
class Array3D
{
public:
Array3D(int size) // beware, data is not initialized!
: size_(size), data_(size*size*size) {}
int size() { return size_; }
size_t index(int x, int y, int z) const {
return x + size_*(y + size_*z);
}
K& operator(int x, int y, int z) {
return data_[index(x,y,z)];
}
private:
size_t size_;
vector<K> data_;
};
You can use it like that:
Array3D arr(1000);
arr(12,43,745) = 15;
This snippet is missing a lot of useful features, but it shows the basic principles of how to build a 3D array. Either build upon something similar, or use one of the libraries out there.
In my opinion, in C++ I would always use a data type for arrays (1D, 2D, ...) to store the array memory and the array size together and to provide at least some kind of boundary information.