Samuel,
This is what I have so far. I'm not sure how to get the handle for an array and I'm also getting an
error from this line:
hwloc_bitmap_set_only(bitmap, t);
|50|undefined reference to `hwloc_bitmap_set_only'|
I'm also confused about these two lines and whether its necessary for the second one to exist?
HANDLE thread[num_threads];
HANDLE pthread_getw32threadhandle_np(thread);
Does the second api call fill the thread array or just the first element?
Also when do I use:
hwloc_bitmap_free(bitmap);
Is it correct in my program or do I need it inside the for loop?
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <hwloc.h>
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 =+ i;
}
printf("Task %d completed with result %e\n", id, result);
}
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);
}
void *parallel(int num_tasks)
{
int num_threads = num_tasks;
//pthread_t thread[num_threads];
HANDLE thread[num_threads];
HANDLE pthread_getw32threadhandle_np(thread);
int rc;
long t;
for (t = 0; t < num_threads; t++)
{
printf("Creating thread %ld\n", t);
rc = pthread_create(&thread[t], NULL, threaded_task, (void *)t);
hwloc_bitmap_t bitmap = hwloc_bitmap_alloc();
hwloc_bitmap_set_only(bitmap, t);
hwloc_set_thread_cpubind(topology, thread[t], bitmap, 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);
}
|