Open MPI logo

Hardware Locality Users' Mailing List Archives

  |   Home   |   Support   |   FAQ   |  

This web mail archive is frozen.

This page is part of a frozen web archive of this mailing list.

You can still navigate around this archive, but know that no new mails have been added to it since July of 2016.

Click here to be taken to the new web archives of this list; it includes all the mails that are in this frozen archive plus all new mails that have been sent to the list since it was migrated to the new archives.

Subject: Re: [hwloc-users] Windows api threading functions equivalent to hwloc?
From: Andrew Somorjai (verthex2099_at_[hidden])
Date: 2012-11-20 20:22:20


Hi Samuel and Brice,

I made the changes to the code. I tried running it and it crashed around line 53 with this statement
(I debugged it by stepping through the program).

hwloc_set_thread_cpubind(topology, handle,
hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, t)->cpuset,
0); 

I also wanted to know what these two lines mean:

bitmap = hwloc_bitmap_alloc();
hwloc_bitmap_only(bitmap, t);

and do I need those?

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <hwloc.h>
/* A task that takes some time to complete. The id identifies distinct
tasks for printed messages. */

hwloc_topology_t topology;

void *task(int id)
{
printf("Task %d started\n", id);
int i;
double result = 0.0;
for (i = 0; i < 1000000000; i++)
{
result = result + sin(i) * tan(i);
}
printf("Task %d completed with result %e\n", id, result);
}
/* Same as 'task', but meant to be called from different threads. */
void *threaded_task(void *t)
{
long id = (long) t;
printf("Thread %ld started\n", id);
task(id);
printf("Thread %ld done\n", id);
pthread_exit(0);
}
/* Run 'task' num_tasks times serially. */
void *parallel(int num_tasks)
{
int num_threads = num_tasks;

  

pthread_t thread[num_threads];
  

int rc;
long t;
hwloc_bitmap_t bitmap;

for (t = 0; t < num_threads; t++)
{
printf("Creating thread %ld\n", t);
rc = pthread_create(&thread[t], NULL, threaded_task, (void *)t);
HANDLE handle = pthread_getw32threadhandle_np(thread[t]);
bitmap = hwloc_bitmap_alloc();
hwloc_bitmap_only(bitmap, t);
hwloc_set_thread_cpubind(topology, handle,
hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, t)->cpuset,
0);

if (rc)
{
printf("ERROR: return code from pthread_create() is %d\n", rc);
exit(-1);
}
}

hwloc_bitmap_free(bitmap);
}

int main()
{
hwloc_topology_init(&topology);
parallel(2);

pthread_exit(NULL);
}

Andrew