PFUNC 1.0
|
Implements pfunc_pack and pfunc_unpack functions. More...
#include <pfunc/pfunc.h>
#include <cstdarg>
#include <cstring>
#include <iostream>
#include <vector>
Defines | |
#define | PFUNC_PACK_CODE |
Enumerations | |
enum | { INVALID_TOKEN = -1, INT, UINT, LINT, INTP, UINTP, LINTP, INTPP, UINTPP, LINTPP, CHRP, UCHRP, CHRPP, UCHRPP, FLTP, FLTPP, DBL, DBLP, DBLPP, VOIDP } |
Functions | |
static int | get_star_count (const char *&format) |
static int | extract_tokens (const char *format, std::vector< int > &token_array) |
Extracts tokens from the format string and populates the given vector. | |
int | pfunc_pack (char **buffer_ptr, const char *format,...) |
int | pfunc_unpack (char *buffer, const char *format,...) |
Implements pfunc_pack and pfunc_unpack functions.
While parallelizing a program, it is desirable to keep the original function as it is and write a wrapper around it that is the parallel call. As an example, consider this:
void serial_foo (int a, int b, int c) { ... } void parallel_foo (void* buffer) { int a, int b, int c; pfunc_unpack (buffer, "int, int, int", &a, &b, &c); serial_foo (a, b, c); } int main () { int a, b, c; void* buffer; .... pfunc_pack (&buffer, "int, int, int", a, b, c); pfunc_run (..,.., parallel_foo, buffer); .... }
Notice that the big improvement here is that we have been able to keep serial_foo as is. This is important since serial_foo might be part of a code that we cannot touch -- from another library. This is quintessential for non-intrusiveness.
#define PFUNC_PACK_CODE |
anonymous enum |
static inline int extract_tokens | ( | const char * | format, |
std::vector< int > & | token_array | ||
) | [inline, static] |
Extracts tokens from the format string and populates the given vector.
format | A string that containts the desired format |
token_array | A std::vector of int's that is populated. |
static int get_star_count | ( | const char *& | format | ) | [inline, static] |
static inline int get_star_count (const char*& format);
[out] | format | The format string from which to extract the star count |
int pfunc_pack | ( | char ** | , |
const char * | format, | ||
... | |||
) |
PFUNC_PACK_CODE Utility functions to pack and unpack the arguements into a single buffer.
int pfunc_unpack | ( | char * | buffer, |
const char * | format, | ||
... | |||
) |