### OpenCL Kernel Setup2015-01-06

Most of the content in this post used to be a part of another post. I felt that it was important enough to have its own post so I moved it and made some minor changes to the content.

For a working example please see the following github repository

### Compiling PhysBAM using clang2015-01-05

The purpose of this post is to document the process I went through to compile the public PhysBAM library using clang. With clang support XCode should also compile the code properly.

#### Setup

Repository:  https://github.com/hmazhar/physbam_public

OS:  OSX 10.10.1

Compiler:
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix

#### Overview

Most of the compilation errors were not unique and came up quite often. The most prevalent errors were related to the following.

• Missing functions - Usually defined after use, Fix is to move them before use or create prototypes at the top of the file
• Two Phase name lookup - This error manifests itself as the following:
error: call to function 'Foo'
that is neither visible in the template definition nor found by argument-dependent lookup

The problem is caused by the function, in this case “Foo” being defined in the base class of the templated child class. There are two ways to fix this error, first as documented here is to add a this-> before any functions that are defined in the base class. The alternative is to explicitly scope the function with the child class. Both seem to work just fine, I thought that the first method, using this->, is a little bit cleaner.

Other errors exist but were not common, they will be covered here on a case by case basis.

### OSX GCC, 'dispatch_block_t' has not been declared, invalid typedef2014-11-23

In OSX 10.10 Yosemite the

/usr/include/dispatch/object.h

header file contains code that can be processed by clang but not GCC. The specific error that GCC 4.9 (via homebrew) produces is:

/usr/include/dispatch/object.h:143:15: error: expected unqualified-id before '^' token
typedef void (^dispatch_block_t)(void);
^
/usr/include/dispatch/object.h:143:15: error: expected ')' before '^' token
/usr/include/dispatch/object.h:362:3: error: 'dispatch_block_t' has not been declared
^

### Clang-format for eclipse and other programs in OSX2014-11-16

clang-format is a program similar to astyle that cleans up and formats C++ code. Currently there is support for integration with Vim, Emacs, BBEdit and Visual studio.

On OSX clang is one of the default compilers supported but the version of clang on OSX does not come with clang-format. There are two options for installing:

### Homebrew:

See related homebrew pull request here

brew tap tcr/tcr
brew install clang-format

### Manual Installation:

With this option you can copy clang-format to your /usr/local/bin directory (or a location located in your path)

Extract and copy clang-format

### Compression of Simulation Data using ZLib2014-11-06

This post will cover a simple way to compress simulation data in memory using ZLib. The goal is to write out compressed data directly without having to deal with binary data formats.

### Setup

I do a lot of rendering with PovRay which means that I need to store comma separated ascii files because that is the only data format supported. The problem is that when I’m saving data for millions of objects the files can become several hundred MB in size.

I propose one solution where all simulation data is stored compressed and a simple program can be used to decompress it and write it out as povray compatible files when needed.

My data is stored in a std::stringstream which I normally stream out to a file. I would like to directly compress this stream and when I need the data, decompress it back into a string.