Skip to content
Snippets Groups Projects
Commit b81d0784 authored by Cristian Lalescu's avatar Cristian Lalescu
Browse files

remove unused code

parent e282a27a
No related branches found
No related tags found
No related merge requests found
/**********************************************************************
* *
* Copyright 2015 Max Planck Institute *
* for Dynamics and Self-Organization *
* *
* This file is part of bfps. *
* *
* bfps is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published *
* by the Free Software Foundation, either version 3 of the License, *
* or (at your option) any later version. *
* *
* bfps 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with bfps. If not, see <http://www.gnu.org/licenses/> *
* *
* Contact: Cristian.Lalescu@ds.mpg.de *
* *
**********************************************************************/
#include "Morton_shuffler.hpp"
#include <iostream>
Morton_shuffler::Morton_shuffler(
int N0, int N1, int N2,
int d,
int nfiles)
{
this->d = d;
if ((nprocs % nfiles != 0) &&
(nfiles % nprocs != 0))
{
std::cerr <<
"Number of output files incompatible with number of processes.\n"
"Aborting.\n" << std::endl;
exit(EXIT_FAILURE);
}
if ((N0/8 % nprocs != 0) &&
(N1/8 % nprocs != 0) &&
(N2/8 % nprocs != 0))
{
std::cerr <<
"Number of cpus incompatible with z-index representation.\n"
"Aborting.\n" << std::endl;
exit(EXIT_FAILURE);
}
int n[4];
// various descriptions for the real data
n[0] = N0;
n[1] = N1;
n[2] = N2;
n[3] = this->d;
this->dinput = new field_descriptor<float>(4, n, MPI_FLOAT, MPI_COMM_WORLD);
n[0] = N0/8;
n[1] = N1/8;
n[2] = N2/8;
n[3] = 8*8*8*this->d;
this->drcubbie = new field_descriptor<float>(4, n, MPI_FLOAT, MPI_COMM_WORLD);
n[0] = (N0/8) * (N1/8) * (N2/8);
n[1] = 8*8*8*this->d;
this->dzcubbie = new field_descriptor<float>(2, n, MPI_FLOAT, MPI_COMM_WORLD);
//set up output file descriptor
int out_rank, out_nprocs;
out_nprocs = nprocs/nfiles;
if (out_nprocs == 0)
{
out_nprocs = 1;
this->files_per_proc = nfiles / nprocs;
}
else
this->files_per_proc = 1;
this->out_group = myrank / out_nprocs;
out_rank = myrank % out_nprocs;
n[0] = ((N0/8) * (N1/8) * (N2/8)) / nfiles;
n[1] = 8*8*8*this->d;
MPI_Comm_split(MPI_COMM_WORLD, this->out_group, out_rank, &this->out_communicator);
this->doutput = new field_descriptor<float>(2, n, MPI_FLOAT, this->out_communicator);
}
Morton_shuffler::~Morton_shuffler()
{
delete this->dinput;
delete this->drcubbie;
delete this->dzcubbie;
delete this->doutput;
MPI_Comm_free(&this->out_communicator);
}
int Morton_shuffler::shuffle(
float *a,
const char *base_fname)
{
// TODO: can this be done in-place?
// shuffle into z order
ptrdiff_t z, zz;
int rid, zid;
int kk;
ptrdiff_t cubbie_size = 8*8*8*this->d;
ptrdiff_t cc;
float *rz = fftwf_alloc_real(cubbie_size);
float *rtmp = fftwf_alloc_real(this->dzcubbie->local_size);
for (int k = 0; k < this->drcubbie->sizes[0]; k++)
{
rid = this->drcubbie->rank[k];
kk = k - this->drcubbie->starts[0];
for (int j = 0; j < this->drcubbie->sizes[1]; j++)
for (int i = 0; i < this->drcubbie->sizes[2]; i++)
{
z = regular_to_zindex(k, j, i);
zid = this->dzcubbie->rank[z];
zz = z - this->dzcubbie->starts[0];
if (myrank == rid || myrank == zid)
{
// first, copy data into cubbie
if (myrank == rid)
for (int tk = 0; tk < 8; tk++)
for (int tj = 0; tj < 8; tj++)
{
cc = (((kk*8+tk)*this->dinput->sizes[1] + (j*8+tj)) *
this->dinput->sizes[2] + i*8)*this->d;
std::copy(
a + cc,
a + cc + 8*this->d,
rz + (tk*8 + tj)*8*this->d);
}
// now copy or send/receive to zindexed array
if (rid == zid) std::copy(
rz,
rz + cubbie_size,
rtmp + zz*cubbie_size);
else
{
if (myrank == rid) MPI_Send(
rz,
cubbie_size,
MPI_FLOAT,
zid,
z,
MPI_COMM_WORLD);
else MPI_Recv(
rtmp + zz*cubbie_size,
cubbie_size,
MPI_FLOAT,
rid,
z,
MPI_COMM_WORLD,
MPI_STATUS_IGNORE);
}
}
}
}
fftwf_free(rz);
char temp_char[200];
for (int fcounter = 0; fcounter < this->files_per_proc; fcounter++)
{
sprintf(temp_char,
"%s_z%.7x",
base_fname,
(this->files_per_proc*this->out_group + fcounter)*this->doutput->sizes[0]);
this->doutput->write(
temp_char,
rtmp + fcounter*this->doutput->local_size);
}
fftwf_free(rtmp);
return EXIT_SUCCESS;
}
/**********************************************************************
* *
* Copyright 2015 Max Planck Institute *
* for Dynamics and Self-Organization *
* *
* This file is part of bfps. *
* *
* bfps is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published *
* by the Free Software Foundation, either version 3 of the License, *
* or (at your option) any later version. *
* *
* bfps 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with bfps. If not, see <http://www.gnu.org/licenses/> *
* *
* Contact: Cristian.Lalescu@ds.mpg.de *
* *
**********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include "field_descriptor.hpp"
#include "fftw_tools.hpp"
#ifndef MORTON_SHUFFLER
#define MORTON_SHUFFLER
extern int myrank, nprocs;
inline ptrdiff_t part1by2(ptrdiff_t x)
{
ptrdiff_t n = x & 0x000003ff;
n = (n ^ (n << 16)) & 0xff0000ff;
n = (n ^ (n << 8)) & 0x0300f00f;
n = (n ^ (n << 4)) & 0x030c30c3;
n = (n ^ (n << 2)) & 0x09249249;
return n;
}
inline ptrdiff_t unpart1by2(ptrdiff_t z)
{
ptrdiff_t n = z & 0x09249249;
n = (n ^ (n >> 2)) & 0x030c30c3;
n = (n ^ (n >> 4)) & 0x0300f00f;
n = (n ^ (n >> 8)) & 0xff0000ff;
n = (n ^ (n >> 16)) & 0x000003ff;
return n;
}
inline ptrdiff_t regular_to_zindex(
ptrdiff_t x0, ptrdiff_t x1, ptrdiff_t x2)
{
return part1by2(x0) | (part1by2(x1) << 1) | (part1by2(x2) << 2);
}
inline void zindex_to_grid3D(
ptrdiff_t z,
ptrdiff_t &x0, ptrdiff_t &x1, ptrdiff_t &x2)
{
x0 = unpart1by2(z );
x1 = unpart1by2(z >> 1);
x2 = unpart1by2(z >> 2);
}
class Morton_shuffler
{
public:
/* members */
int d; // number of components of the field
// descriptor for N0 x N1 x N2 x d
field_descriptor<float> *dinput;
// descriptor for (N0/8) x (N1/8) x (N2/8) x 8 x 8 x 8 x d
field_descriptor<float> *drcubbie;
// descriptor for NZ x 8 x 8 x 8 x d
field_descriptor<float> *dzcubbie;
// descriptor for (NZ/nfiles) x 8 x 8 x 8 x d
field_descriptor<float> *doutput;
// communicator to use for output
MPI_Comm out_communicator;
int out_group, files_per_proc;
/* methods */
Morton_shuffler(
int N0, int N1, int N2,
int d,
int nfiles);
~Morton_shuffler();
int shuffle(
float *regular_data,
const char *base_fname);
};
#endif//MORTON_SHUFFLER
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment