wiki:kit_WP3

Version 4 (modified by Matthias Vogelgesang, 14 years ago) (diff)

--

[Proposal] Coding Style

In general, the coding standards used in the Linux kernel are versatile, comprehensive and quite good looking. They are boiling down to the following guide lines:

Indentation
Hardtabs
Spaces
Spaces around keywords but not in inner parenthesis.
Brace placement
'{' at end of line except for function definition and '}' on its own line except in do-while-loops.
Naming
Descriptive for global functions and usually lower case with underscores.
Macros
Upper case for constants, lower case with underscores for macros resembling functions.
Structures
No typedefs, although this is debatable. For shared data structures reference counting should be implemented.

I would add the following:

Position of C-pointer star
At variable name not type.
const
Wherever possible.
White space
Avoid at all costs.
C99
Enable it and declare variables only when needed.

There are still some open questions:

  • Number of white lines to separate functions?
  • Comments: C vs. C++ style, usage of '*'?
  • Alignment of multiple assignments?
  • Breaking of long lines, especially argument lists?
  • #define indentation? Commenting each #endif with the corresponding #define name makes the code hard to read in my opinion.
  • Documentation tools? (Doxygen, Sphinx
  • Name prefixes? (e.g. 'g_' for global)

In essence, a bit of code would look like that:

#define PI 3.14159265
#define min(a,b) ((a) < (b) ? (a) : (b))

struct string {
    char *content;
    size_t length;
    int refcount;
};

struct string* clone_string(const char *s)
{
    if (s == NULL)
        return NULL;

    struct string *clone = (struct string *) malloc(sizeof(struct string));
    const int len = strlen(s);
    clone->content = (char *) malloc(len);
    clone->length = len;
    clone->refcount = 1;
    strncpy(clone->content, s, len);

    return clone;
}

PyHST and OpenCL

To a certain degree, PyHST has been ported to OpenCL. Check-out the code via

  • git clone ssh://<user>@ipefser1.fzk.de/home/ipefser1/vogelgesang/repos/oclfft.git
  • git clone ssh://<user>@ipefser1.fzk.de/home/ipefser1/vogelgesang/repos/pyHST.git

Build and install the OpenCL FFT library

  • cd $OCLFFT_DIR && cmake . && make && sudo make install

as well as PyHST. Make sure to enable OpenCL support and copy the OpenCL kernel file wherever you intend to run PyHST. Please note: This has only been tested with a limited set of data and does not yet cover all features from the pure CPU version (such as FAI360 support).

Attachments (3)

Download all attachments as: .zip