Monthly Archives: February 2012

Rodrick’s Rules

It’s about time, little bro, that you learn the secrets to an easy life.
Rule number one, don’t be good at something you don’t want to do.
Rule number two, always lower Mom and Dad’s expectations.
Rule number three, never do something when someone else can do it for you.


CFP: 2nd International Workshop on Computational Intelligence in Software Engineering (CISE 2012)

CFP: 2nd International Workshop on Computational Intelligence in Software Engineering (CISE 2012)

(Apologies if you have received multiple CFPs)
Call For Papers
CISE 2012: 2nd International Workshop on
Computational Intelligence in Software Engineering
September 27-30, 2012
Khalkidhiki (Halkidiki), Greece

The CISE workshop focuses on theoretical and applied research related to the utilization of Computational Intelligence techniques in Software Engineering, targeting the provision of alternative, interdisciplinary approaches for tackling problems found in Software Engineering.

The aim of the workshop is to host research papers that present practical solutions to emerging Software Engineering issues by applying Computational Intelligence methods. The workshop is associated with research and development advances in many fields of Software Engineering and particularly the study, analysis, design, modelling, implementation and application of Computational Intelligence techniques that tackle significant Software Engineering problems. The topics of interest call, especially, for papers with theoretical and practical importance, while research papers reporting emerging and innovative ideas are also highly desirable.

In particular the topics of the workshop include but are not limited to the following:

Clustering and Classification applied to Requirements Engineering
Decision Support Software Architectures
Machine Learning Software Methodologies
Data Mining Software Design
Text Mining & Retrieval Software Performance
Fuzzy Logic & Systems Software Quality Modelling & Assessment
Probabilistic Reasoning Software Reliability Modelling & Forecasting
Model Learning Software Maintenance
Recommender Systems Software Testing, Verification & Validation
Expert Systems Software Metrics
Artificial Neural Networks Software Reuse
Evolutionary Algorithms Software Project Management
Ranking Algorithms Object-Oriented Development
Cognitive Processes Open Source Software
Evolutionary Computing Agile Software Development
Swarm Intelligence Software Repository Management
Artificial Immune Systems Mobile Software Development
Dempster-Shafer Theory Software Risk Analysis & Modelling
Chaos Theory Configuration Management
Multi-valued Logic Component-Based Software Development
Ensemble Techniques Cloud Computing
Hybrid Approaches Web Engineering
Search-Based Software Engineering

Papers should not exceed 10 pages in length and must be formatted according to the LNCS Springer publication style found here ( In addition, papers should be submitted either in Microsoft Word or PDF format via email to one of the Workshop Chairs.
Each paper will reviewed by at least 2 academic referees. Papers reporting industrial applications will be reviewed by at least 1 industrial referee.

Important Dates:
Paper submission: April 27, 2012
Notification of acceptance/rejection: May 26, 2012
Camera-ready submission: June 4, 2012
Early registration: June 04, 2012
Workshop dates: September 27-30, 2012

Accepted papers will be presented at the workshop (approx. 20 minutes allocated time) and will be published in the Proceedings of the main event.
The papers of the workshop will be also considered for potential selection for publication in special issues of the journals “Artificial Intelligence Review”, “Engineering Intelligent Systems” and “Fuzzy Sets and Systems”.

Note that at least one author of each accepted paper is required to register and attend the workshop to present the paper.

Workshop Chairs:
Andreas S. Andreou
Department of Computer Engineering and Informatics,
Cyprus University of Technology, Cyprus
email: [email protected]


Efi Papatheocharous
Department of Computer Science
University of Cyprus, Cyprus
email: [email protected] 

C/C++: Set Affinity to threads Example Code 1

The following code sets the affinity of each pthread to a different and specific CPU core.

The selection is made with the variable speid (that is user defined) and contains a number from 0 to (CPU NUMBER – 1).

int s, j;
cpu_set_t cpuset;
pthread_t thread;

thread = pthread_self();

/* Set affinity mask to include CPUs 0 to 7 */

CPU_SET(speid, &cpuset);

s = pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
if (s != 0) {
    handle_error_en(s, "pthread_setaffinity_np");

/* Check the actual affinity mask assigned to the thread */
s = pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
if (s != 0) {
    handle_error_en(s, "pthread_getaffinity_np");

printf("Set returned by pthread_getaffinity_np() contained:\n");
for (j = 0; j < CPU_SETSIZE; j++) {
    if (CPU_ISSET(j, &cpuset)) {
        fprintf(stderr,"%d CPU %d\n",speid, j);

This code also verifies that the affinity set was successful.

Please note that you can use CPU_SET(core_id, &cpuset); multiple times, with different values for the variable core_id. This way you instruct the OS that it can move your thread to any of those available cores for execution and not limit it to just one.

Full example

Below you will find a full working example. This code will create 4 pthreads, assign each of them to a different CPU core, test that the affiliation was successful and then wait for all the threads to terminate and return their output in the form of a string.

Full source code available here affinity_pthread.c (compressed) (1006 downloads)

#include <stdio.h>
#include <stdlib.h>
#define __USE_GNU
#include <sched.h>
#include <errno.h>
#include <unistd.h>
#include <pthread.h>

// The <errno.h> header file defines the integer variable errno, which is set by system calls and some library functions in the event of an error to indicate what went wrong.
#define print_error_then_terminate(en, msg) \
  do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
#define print_perror_then_terminate(msg) \
  do { perror(msg); exit(EXIT_FAILURE); } while (0)

  struct thread_info {

    pthread_t thread_id; // ID returned by pthread_create()
    int core_id; // Core ID we want this pthread to set its affinity to

#define SUCCESS_MSG "Successfully set thread %lu to affinity to CPU %d\n"
#define FAILURE_MSG "Failed to set thread %lu to affinity to CPU %d\n"

void * thread_camper(void *arg) {

  struct thread_info *thread_info = arg;

  const pthread_t pid = pthread_self();
  const int core_id = thread_info->core_id;

  // cpu_set_t: This data set is a bitset where each bit represents a CPU.
  cpu_set_t cpuset;
  // CPU_ZERO: This macro initializes the CPU set set to be the empty set.
  // CPU_SET: This macro adds cpu to the CPU set set.
  CPU_SET(core_id, &cpuset);

  // pthread_setaffinity_np: The pthread_setaffinity_np() function sets the CPU affinity mask of the thread thread to the CPU set pointed to by cpuset. If the call is successful, and the thread is not currently running on one of the CPUs in cpuset, then it is migrated to one of those CPUs.
  const int set_result = pthread_setaffinity_np(pid, sizeof(cpu_set_t), &cpuset);
  if (set_result != 0) {

    print_error_then_terminate(set_result, "pthread_setaffinity_np");

  // Check what is the actual affinity mask that was assigned to the thread.
  // pthread_getaffinity_np: The pthread_getaffinity_np() function returns the CPU affinity mask of the thread thread in the buffer pointed to by cpuset.
  const int get_affinity = pthread_getaffinity_np(pid, sizeof(cpu_set_t), &cpuset);
  if (get_affinity != 0) {

    print_error_then_terminate(get_affinity, "pthread_getaffinity_np");

  char *buffer;
  // CPU_ISSET: This macro returns a nonzero value (true) if cpu is a member of the CPU set set, and zero (false) otherwise. 
  if (CPU_ISSET(core_id, &cpuset)) {

    const size_t needed = snprintf(NULL, 0, SUCCESS_MSG, pid, core_id);
    buffer = malloc(needed);
    snprintf(buffer, needed, SUCCESS_MSG, pid, core_id);
  } else {

    const size_t needed = snprintf(NULL, 0, FAILURE_MSG, pid, core_id);
    buffer = malloc(needed);
    snprintf(buffer, needed, FAILURE_MSG, pid, core_id);

  return buffer;

int main(int argc, char *argv[]) {

  // Initialize thread creation attributes
  pthread_attr_t attr;
  const int attr_init_result = pthread_attr_init(&attr);
  if (attr_init_result != 0) {
      print_error_then_terminate(attr_init_result, "pthread_attr_init");

  // We will set the stack size limit to is 1 MB (0x100000 bytes)
  const int stack_size = 0x100000;
  const int setstacksize_result = pthread_attr_setstacksize(&attr, stack_size);
  if (setstacksize_result != 0) {
    print_error_then_terminate(setstacksize_result, "pthread_attr_setstacksize");

  const int num_threads = 4;
  // Allocate memory for pthread_create() arguments
  struct thread_info *thread_info = calloc(num_threads, sizeof(struct thread_info));
  if (thread_info == NULL) {

  // Create the threads and initialize the core_id argument, which will be used to set the thread to the specific CPU core.
  // For example, we want the first pthread to camp on the first CPU core which has the ID 0. So we pass the value 0 to its core_id.
  int tnum;
  for (tnum = 0; tnum < num_threads; tnum++) {

    thread_info[tnum].core_id = tnum;
    // The pthread_create() call stores the thread ID into corresponding element of thread_info[]
    const int create_result = pthread_create(&thread_info[tnum].thread_id, &attr, &thread_camper, &thread_info[tnum]);
    if (create_result != 0) {
      print_error_then_terminate(create_result, "pthread_create");

  // Destroy the thread attributes object, since it is no longer needed
  const int destroy_result = pthread_attr_destroy(&attr);
  if (destroy_result != 0) {
   print_error_then_terminate(destroy_result, "pthread_attr_destroy");

  // Now join with each thread, and display its returned value
  for (tnum = 0; tnum < num_threads; tnum++) {
    void *res;
    const int join_result = pthread_join(thread_info[tnum].thread_id, &res);
    if (join_result != 0) {
      print_error_then_terminate(join_result, "pthread_join");

    printf("Joined with thread %d; returned value was %s\n", thread_info[tnum].core_id, (char *) res);
    free(res); // Free memory allocated by thread

  return 0;

To compile we used the following command

gcc -Wall -pthread  affinity_pthread.c -o  affinity_pthread;

Full source code available here affinity_pthread.c (compressed) (1006 downloads)

For a full example that sets affinity for single threaded applications please visit this link.

Linux Bash: How to print leading zeroes on a variable

In order to print the leading zeros to a variable you need to use the function printf as follows, where %03d states that the number should consist of minimum 3 digits and thus it will put the missing leading zeros:

 printf %03d $counter

The following example renames a file that it has the following format for a filename: number.anything and adds the leading zeros in order to make it easier while sorting multiple files.
The name is contained in the variable $a.
If for example we had the file 11.txt  it will become 0011.txt

mv $a `printf %04d.%s ${a%.*} ${a##*.}`