Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Each line is a file pattern followed by one or more owners.

# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence,
# they will be requested for
# review when someone opens a pull request.
* @JoeOster @pmpeter1 @tomlenth

# This owner owns any files in the given
# directory at the root of the repository and any of its
# subdirectories.
/DirectProgramming/DPC++/ @JoeOster @moushumi-maria, @pmpeter1
/DirectProgramming/Jupyter/ @JoeOster @praveenkk123
/DirectProgramming/C++/ @JoeOster @pmpeter1 @Propanu
/DirectProgramming/Fortran/ @JoeOster @pmpeter1 @Propanu
/Tools/ @JoeOster @Propanu
/Libraries/ @JoeOster @Propanu @mav-intel @JoeOster

# Reviwers for all sample.json modification
*sample.json @pfische1 @mkitez

# Reviewer for all readme files
*/README.md @tomlenth
51 changes: 51 additions & 0 deletions DirectProgramming/C++/MandelbrotOMP/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#==============================================================
#
# SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT,
# http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/
#
# Copyright Intel Corporation
#
# THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT
# NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS.
#
# =============================================================
CXX := icpc
SRCDIR := src
BUILDDIR := release
CFLAGS := -O3 -ipo -qopenmp -std=c++11
EXTRA_CFLAGS :=
LIBFLAGS := -qopenmp

ifdef perf_num
EXTRA_CFLAGS += -D PERF_NUM
endif

TARGET := $(BUILDDIR)/MergeSort

icpc: $(TARGET)

SOURCES := $(wildcard $(SRCDIR)/*.cpp)
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.cpp=.o))

$(TARGET): $(OBJECTS)
@echo " Linking..."
$(CXX) $^ $(LIBFLAGS) -o $(TARGET)

$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp
@mkdir -p $(BUILDDIR)
$(CXX) -c $(CFLAGS) $(EXTRA_CFLAGS) -o $@ $<

run: $(TARGET)
ifeq ($(shell uname -s),Darwin)
@export DYLD_LIBRARY_PATH="$(LIBRARY_PATH)"; ./$(TARGET) $(option)
else
./$(TARGET) $(option)
endif

clean:
@echo " Cleaning..."
@rm -fr $(BUILDDIR) $(TARGET) 2>/dev/null || true
@rm -f *.png

.PHONY: clean
98 changes: 98 additions & 0 deletions DirectProgramming/C++/MandelbrotOMP/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# `Mandelbrot` Sample

Mandelbrot is an infinitely complex fractal patterning that is derived from a simple formula. This sample demonstrates how to accelerate program performance with SIMD and parallelization using OpenMP*, in the context of calculating the mandelbrot set.


| Optimized for | Description
|:--- |:---
| OS | MacOS Catalina or newer; Linux* Ubuntu* 18.04
| Hardware | Skylake with GEN9 or newer
| Software | Intel&reg; C++ Compiler 19.1 or newer
| What you will learn | How to optimize a scalar implementation using OpenMP pragmas
| Time to complete | 15 minutes

Performance number tabulation

| Mandelbrot Version | Performance data
|:--- |:---
| Scalar baseline | 1.0
| OpenMP SIMD | 2x speedup
| OpenMP parallel | 6x speedup
| OpenMP SIMD + parallel | 10x speedup


## Purpose

Mandelbrot is a C++ application that generates a fractal image by tracking how many iterations of the function z_n+1 = z_n^2 + c remain bounded, where c is a coordinate on the complex plane and z_0 = 0. In performing this calculation, complex numbers belonging to the mandelbrot set will take infinite iterations as they will always remain bounded. So a maximum depth of iterations is set so that the program may execute in finite time.

Each point on the complex plane can be calculated independently, which lends the calculation of the mandelbrot image to parallelism. Furthermore, since the calculation on each point is identical, the program can take advantage of SIMD directives to get even greater performance. This code sample demonstrates how to optimize a serial implementation of the mandelbrot image calculation using OpenMP pragmas for SIMD and parallelization.


## Key Implementation Details

The 4 mandelbrot function implementations are identically written, with the only difference being the progressive use of OpenMP pragmas for enabling parallelization and SIMD.


## License

This code sample is licensed under MIT license.


## Building the `Mandelbrot` Program

Perform the following steps:
1. Build the program using the following `make` commands.
```
$ export perf_num=1 *optional, will enable performance tabulation mode
$ make
```

2. Run the program:
```
make run
```

3. Clean the program using:
```
make clean
```


## Running the Sample

### Application Parameters
You can modify the Mandelbrot parameters from within the main() definition near the head. The configurable parameters allow one to modify the dimensions(resolution) of the output image, which will also affect the execution time of the program. max_depth defines the upper limit of iterations the mandelbrot function will take to calculate a single point:
int height = 1024;
int width = 2048;
int max_depth = 100;

In mandelbrot.cpp, the schedule(<static/dynamic>, <chunk_size>) pragmas in the OpenMP parallel for sections can me modified to change the parallelization parameters. changing between static and dynamic affects how work items are distributed between threads, and the chunk_size affects the size of each work item. On line 69, there is a preprocessor definition NUM_THREADS: Changing this value affects the number of threads dedicated to each parallel section. The ideal number of threads will vary based on the device hardware.

### Example of Output
```
This example will check how many iterations of z_n+1 = z_n^2 + c a complex set will remain bounded. Pick which parallel method you would like to use.
[0] all tests
[1] serial/scalar
[2] OpenMP SIMD
[3] OpenMP Parallel
[4] OpenMP Both
> 0

Running all tests

Starting serial, scalar Mandelbrot...
Calculation finished. Processing time was 198ms
Saving image as mandelbrot_serial.png

Starting OMP SIMD Mandelbrot...
Calculation finished. Processing time was 186ms
Saving image as mandelbrot_simd.png

Starting OMP Parallel Mandelbrot...
Calculation finished. Processing time was 33ms
Saving image as mandelbrot_parallel.png

Starting OMP SIMD + Parallel Mandelbrot...
Calculation finished. Processing time was 31ms
Saving image as mandelbrot_simd_parallel.png
```
8 changes: 8 additions & 0 deletions DirectProgramming/C++/MandelbrotOMP/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Copyright 2020 Intel Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

20 changes: 20 additions & 0 deletions DirectProgramming/C++/MandelbrotOMP/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "Mandelbrot OpenMP*",
"description": "Calculates the mandelbrot set and outputs a bmp image representation using OpenMP*",
"categories": ["Toolkit/Intel® oneAPI HPC Toolkit"],
"os": ["linux", "darwin"],
"builder": ["cmake"],
"languages": [{"cpp":{}}],
"toolchain": ["icc"],
"guid": "DD113F58-4D91-41BB-B46E-6CF2C0D9F6F9",
"ciTests": {
"linux": [
{ "id": "standard", "steps": [ "make", "make run", "make clean" ] },
{ "id": "perf_num", "env": [ "export perf_num=1" ], "steps": [ "make", "make run", "make clean" ] }
],
"darwin": [
{ "id": "standard", "steps": [ "make", "make run", "make clean" ] },
{ "id": "perf_num", "env": [ "export perf_num=1" ], "steps": [ "make", "make run", "make clean" ] }
]
}
}
Loading