Skip to content

Commit

Permalink
Merge branch 'issue3_missing-phi-diffusion-code'
Browse files Browse the repository at this point in the history
  • Loading branch information
tkphd committed Sep 14, 2017
2 parents dfc3709 + 8362bd6 commit 8e6fb3d
Show file tree
Hide file tree
Showing 7 changed files with 459 additions and 22 deletions.
37 changes: 22 additions & 15 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ performance and optimization of a specific application. CUDA hardware can be
emulated on the CPU using the MCUDA_ framework. Proof-of-concept
trials on GPU and KNL hardware can be run on Amazon's EC2_,
Rescale's ScaleX_, and equivalent HPC cloud computing platforms.
Most of the current generation of research supercomputers contain GPU or KNL
accelerator hardware, including Argonne National Labs'
Bebop_, NERSC Cori_, TACC Stampede2_, and XSEDE_.

===============
Basic Algorithm
Expand Down Expand Up @@ -311,7 +314,7 @@ Work in Progress
- [ ] ripening
- [ ] KNL
- [ ] OpenMP
- [ ] diffusion
- [x] diffusion
- [ ] spinodal
- [ ] dendrite
- [ ] ripening
Expand All @@ -337,43 +340,47 @@ intended to imply that the entities, materials, or equipment are necessarily
the best available for the purpose.

.. _`Trevor Keller`: mailto::[email protected]
.. _`National Institute of Standards and Technology`: http://www.nist.gov
.. _`Source on GitHub`: https://github.com/usnistgov/hiperc
.. _`hiperc_guide.pdf`: doc/hiperc_guide.pdf
.. |`initial conc`| image:: common-diffusion/diffusion.00000.png
.. |`final conc`| image:: common-diffusion/diffusion.10000.png
.. |Source on GitHub| image:: https://assets-cdn.github.com/favicon.ico
.. _`Source on GitHub`: https://github.com/usnistgov/hiperc
.. |Documentation on readthedocs| image:: http://readthedocs.org/projects/hiperc/badge/?version=latest
.. _`Documentation on readthedocs`: http://hiperc.readthedocs.io/en/latest/?badge=latest
.. |Conversation on Gitter| image:: https://badges.gitter.im/usnistgov/hiperc.svg
.. _Bebop: http://www.lcrc.anl.gov/systems/resources/bebop/
.. _ccNUMA: https://en.wikipedia.org/wiki/Non-uniform_memory_access#Cache_coherent_NUMA
.. _`Conversation on Gitter`: https://gitter.im/usnistgov/hiperc?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge
.. |Conversation on Gitter| image:: https://badges.gitter.im/usnistgov/hiperc.svg
.. _`Contributing Guidelines`: CONTRIBUTING.md
.. _`file an issue`: https://github.com/usnistgov/hiperc/issues
.. _OpenACC: https://www.openacc.org/
.. _radeontop: https://github.com/clbr/radeontop
.. _ccNUMA: https://en.wikipedia.org/wiki/Non-uniform_memory_access#Cache_coherent_NUMA
.. _convolution: https://en.wikipedia.org/wiki/Discrete_Laplace_operator#Image_Processing
.. _Cori: http://www.nersc.gov/users/computational-systems/cori/
.. _Cray: http://www.cray.com/
.. _CUDA: https://developer.nvidia.com/cuda-zone
.. |Documentation on readthedocs| image:: http://readthedocs.org/projects/hiperc/badge/?version=latest
.. _`Documentation on readthedocs`: http://hiperc.readthedocs.io/en/latest/?badge=latest
.. _Doxygen: http://www.stack.nl/~dimitri/doxygen/
.. _EC2: https://aws.amazon.com/ec2/Elastic-GPUs/
.. _`file an issue`: https://github.com/usnistgov/hiperc/issues
.. |`final conc`| image:: common-diffusion/diffusion.10000.png
.. _Gitter: https://gitter.im/usnistgov/hiperc
.. _GNU: https://gcc.gnu.org/
.. _`hiperc_guide.pdf`: doc/hiperc_guide.pdf
.. _htop: http://hisham.hm/htop/
.. |`initial conc`| image:: common-diffusion/diffusion.00000.png
.. _`intel_gpu_top`: https://github.com/ChrisCummins/intel-gpu-tools
.. _KNC: https://ark.intel.com/products/codename/57721/Knights-Corner
.. _KNL: https://ark.intel.com/products/codename/48999/Knights-Landing
.. _LaTeX: https://www.latex-project.org/
.. _Make: https://www.gnu.org/software/make/
.. _MCUDA: http://impact.crhc.illinois.edu/mcuda.aspx
.. _MIMD: https://en.wikipedia.org/wiki/MIMD
.. _`National Institute of Standards and Technology`: http://www.nist.gov
.. _nvidia-smi: https://developer.nvidia.com/nvidia-system-management-interface
.. _OpenACC: https://www.openacc.org/
.. _OpenCL: https://www.khronos.org/opencl/
.. _OpenMP: http://www.openmp.org/
.. _PGI: http://www.pgroup.com/
.. _POSIX: http://www.opengroup.org/austin/papers/posix_faq.html
.. _radeontop: https://github.com/clbr/radeontop
.. _ScaleX: http://www.rescale.com/products/
.. _SIMD: https://en.wikipedia.org/wiki/SIMD
.. |Source on GitHub| image:: https://assets-cdn.github.com/favicon.ico
.. _`Source on GitHub`: https://github.com/usnistgov/hiperc
.. _Stampede2: https://www.tacc.utexas.edu/systems/stampede2
.. _`Threading Building Blocks`: https://www.threadingbuildingblocks.org/
.. _`Xeon Phi`: https://www.intel.com/content/www/us/en/products/processors/xeon-phi/xeon-phi-processors.html
.. _XSEDE: https://www.xsede.org/ecosystem/resources

9 changes: 6 additions & 3 deletions common-diffusion/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@
#include "timer.h"

#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
#include <sys/time.h>
#ifndef __USE_BSD
#define __USE_BSD
#endif
#include <sys/time.h>
#endif

/**
Expand Down
53 changes: 53 additions & 0 deletions phi-openmp-diffusion/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Makefile for HiPerC diffusion code
# Xeon Phi implementation

CC = icc
CFLAGS = -O3 -openmp -xmic-avx512 -I../common-diffusion
QOPT = -qopt-prefetch=3 -qopt-report=4 -qopt-report-file="qopt.log"
LINKS = -lpng
# QOFF = -qoffload-arch=mic-avx512 # Only activate if offloading to KNL coprocessor

OBJS = boundaries.o discretization.o mesh.o numerics.o output.o timer.o

# Executable
diffusion: phi_main.c $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -include omp.h $< -o $@ $(QOPT) $(LINKS)

# Xeon Phi objects
boundaries.o: phi_boundaries.c
$(CC) $(CFLAGS) -c $< -o $@

discretization.o: phi_discretization.c
$(CC) $(CFLAGS) -c $< -o $@

# Common objects
mesh.o: ../common-diffusion/mesh.c
$(CC) $(CFLAGS) -c $< -o $@

numerics.o: ../common-diffusion/numerics.c
$(CC) $(CFLAGS) -c $< -o $@

output.o: ../common-diffusion/output.c
$(CC) $(CFLAGS) -c $< -o $@

timer.o: ../common-diffusion/timer.c
$(CC) $(CFLAGS) -c $< -o $@

# Helper scripts
.PHONY: run
run: diffusion
/usr/bin/time -f' Time (%E wall, %U user, %S sys)' ./diffusion ../common-diffusion/params.txt

.PHONY: cleanobjects
cleanobjects:
rm -f diffusion *.o

.PHONY: cleanoutputs
cleanoutputs:
rm -f diffusion.*.csv diffusion.*.png runlog.csv

.PHONY: clean
clean: cleanobjects

.PHONY: cleanall
cleanall: cleanobjects cleanoutputs
16 changes: 12 additions & 4 deletions phi-openmp-diffusion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ To build this code, you must have installed
These are usually available through the package manager. For example,
```apt-get install make libpng12-dev```. The Intel compiler is proprietary,
but available to open-source developers at no cost. Hardware capable of AVX-512
instructions, whether a primary Xeon CPU or a Xeon Phi, is also required.
Proof-of-concept KNL code can be run on [Rescale's ScaleX][_scalex]
and equivalent HPC cloud computing platforms.
instructions, whether a primary Xeon CPU or a [Xeon Phi][_knl], is also required.
Proof-of-concept KNL code can be run on [Rescale's ScaleX][_scalex] and
equivalent HPC cloud computing platforms. [KNL][_knl] nodes are available on
advanced research computing platforms, including Argonne National Labs'
[Bebop][_bebop], NERSC [Cori][_cori], TACC [Stampede2][_tacc], and
[XSEDE][_xsede].

## Customization

Expand All @@ -49,8 +52,13 @@ the [National Institute of Standards and Technology (NIST)](http://www.nist.gov)
nor is it intended to imply that the entities, materials, or equipment are
necessarily the best available for the purpose.

[_make]: https://www.gnu.org/software/make/
[_bebop]: http://www.lcrc.anl.gov/systems/resources/bebop/
[_cori]: http://www.nersc.gov/users/computational-systems/cori/
[_gcc]: https://gcc.gnu.org
[_intel]: https://software.intel.com/en-us/intel-compilers
[_knl]: https://www.intel.com/content/www/us/en/products/processors/xeon-phi/xeon-phi-processors.html
[_make]: https://www.gnu.org/software/make/
[_png]: http://www.libpng.org/pub/png/libpng.html
[_scalex]: http://www.rescale.com/products/
[_tacc]: https://www.tacc.utexas.edu/systems/stampede2
[_xsede]: https://www.xsede.org/ecosystem/resources
106 changes: 106 additions & 0 deletions phi-openmp-diffusion/phi_boundaries.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**********************************************************************************
HiPerC: High Performance Computing Strategies for Boundary Value Problems
written by Trevor Keller and available from https://github.com/usnistgov/hiperc
This software was developed at the National Institute of Standards and Technology
by employees of the Federal Government in the course of their official duties.
Pursuant to title 17 section 105 of the United States Code this software is not
subject to copyright protection and is in the public domain. NIST assumes no
responsibility whatsoever for the use of this software by other parties, and makes
no guarantees, expressed or implied, about its quality, reliability, or any other
characteristic. We would appreciate acknowledgement if the software is used.
This software can be redistributed and/or modified freely provided that any
derivative works bear some notice that they are derived from it, and any modified
versions bear some notice that they have been modified.
Questions/comments to Trevor Keller ([email protected])
**********************************************************************************/


/**
\file phi_boundaries.c
\brief Implementation of boundary condition functions with OpenMP threading
*/

#include <math.h>
#include <omp.h>
#include "boundaries.h"

void set_boundaries(fp_t bc[2][2])
{
fp_t clo = 0.0, chi = 1.0;
bc[0][0] = clo; /* bottom boundary */
bc[0][1] = clo; /* top boundary */
bc[1][0] = chi; /* left boundary */
bc[1][1] = chi; /* right boundary */
}

void apply_initial_conditions(fp_t** conc, int nx, int ny, int nm, fp_t bc[2][2])
{
#pragma omp parallel
{
int i, j;

#pragma omp for collapse(2)
for (j = 0; j < ny; j++)
for (i = 0; i < nx; i++)
conc[j][i] = bc[0][0];

#pragma omp for collapse(2)
for (j = 0; j < ny/2; j++)
for (i = 0; i < 1+nm/2; i++)
conc[j][i] = bc[1][0]; /* left half-wall */

#pragma omp for collapse(2)
for (j = ny/2; j < ny; j++)
for (i = nx-1-nm/2; i < nx; i++)
conc[j][i] = bc[1][1]; /* right half-wall */
}
}

void apply_boundary_conditions(fp_t** conc, int nx, int ny, int nm, fp_t bc[2][2])
{
#pragma omp parallel
{
int i, ihi, ilo, j, jhi, jlo, offset;

/* apply fixed boundary values: sequence does not matter */

#pragma omp for collapse(2) private(i,j)
for (j = 0; j < ny/2; j++) {
for (i = 0; i < 1+nm/2; i++) {
conc[j][i] = bc[1][0]; /* left value */
}
}

#pragma omp for collapse(2) private(i,j)
for (j = ny/2; j < ny; j++) {
for (i = nx-1-nm/2; i < nx; i++) {
conc[j][i] = bc[1][1]; /* right value */
}
}

/* apply no-flux boundary conditions: inside to out, sequence matters */

for (offset = 0; offset < nm/2; offset++) {
ilo = nm/2 - offset;
ihi = nx - 1 - nm/2 + offset;
#pragma omp for private(j)
for (j = 0; j < ny; j++) {
conc[j][ilo-1] = conc[j][ilo]; /* left condition */
conc[j][ihi+1] = conc[j][ihi]; /* right condition */
}
}

for (offset = 0; offset < nm/2; offset++) {
jlo = nm/2 - offset;
jhi = ny - 1 - nm/2 + offset;
#pragma omp for private(i)
for (i = 0; i < nx; i++) {
conc[jlo-1][i] = conc[jlo][i]; /* bottom condition */
conc[jhi+1][i] = conc[jhi][i]; /* top condition */
}
}
}
}
Loading

0 comments on commit 8e6fb3d

Please sign in to comment.