Go Back   AC3D Forums > General > AC3D Suggestions
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 17th December 2020, 12:43 AM   #1
modeler
Member
Advanced member
 
Join Date: Nov 2003
Posts: 35
Default Overall support for multicore cpu

It seems the function calls does not work with parallel processing using multicore cpu. I use Openmp in some of my plugins but calling ac3d functions does not work. I can only get Openmp to work with code that does not use ac3d functions.
Here is an example code to process a list of vertices. This example divides a list of vertices depending on the number of vertices and number of cpu cores. The code then process the divided list in parallel.

typedef struct pair2_t
{
List* start, * end;
} Pair2;

int numvert1 = list_count(selver);

int cores = numvert1 / 100;
if (cores == 0)
cores = 1;
if (cores > omp_get_num_procs())
cores = omp_get_num_procs();


if (cores > 1)
{

int vertpercore = numvert1 / cores;
Pair2* p;
p = (Pair2*)_aligned_malloc(sizeof(Pair2) * cores, 16);
List* tl = NULL;
int i = 1;
int corecount = 0;
p[0].start = selver;
for (tl = selver; tl != NULL; tl = tl->next)
{

if (i == vertpercore * (corecount + 1))
{
p[corecount].end = tl->next;
if ((corecount + 1) < cores)
{
corecount++;
p[corecount].start = tl->next;
}
}
i++;
}
p[corecount].end = tl;


#pragma omp parallel for num_threads (cores) private(i)
for (i = 0; i < cores; i++)
{

getplanes(p[i].start, distance, p[i].end);
}

fprintf(file, "vertex count %d\n", numvert1);
fprintf(file, "number of cores %d\n", cores);
fprintf(file, "vertex per core %d\n", vertpercore);
for (i = 0; i < cores; i++)
{
fprintf(file, "core %d start %p end %p\n", i, p[i].start, p[i].end);
}
_aligned_free(p);

}
else
{

getplanes(selver, distance, NULL);

}
modeler is offline   Reply With Quote
Old 22nd December 2020, 09:04 AM   #2
Andy
Administrator
Professional user
 
Andy's Avatar
 
Join Date: Jun 2003
Posts: 4,563
Default Re: Overall support for multicore cpu

That's interesting. Do you mean that it doesn't link or doesn't load or doesn't run?
Andy is offline   Reply With Quote
Old 22nd December 2020, 12:08 PM   #3
modeler
Member
Advanced member
 
Join Date: Nov 2003
Posts: 35
Default Re: Overall support for multicore cpu

The program crashes. This code is part of an importer. It works on the first import but crashes on the second import.
#pragma omp parallel
for (int n = 0; n < (int)num_vertices; n++)
{
Vertex *vtemp;
v.x = vert[n].v[0];
v.y = vert[n].v[1];
v.z = vert[n].v[2];
vtemp = object_find_vertex_point(ob, &v);
vindex[n] = ac_object_get_vertex_index(ob, vtemp);

}
modeler is offline   Reply With Quote
Old 26th December 2020, 11:48 AM   #4
modeler
Member
Advanced member
 
Join Date: Nov 2003
Posts: 35
Default Re: Overall support for multicore cpu

I got it to work. I missed one of the variables that has to be included inside the for loop.

int cores = (int)num_vertices / 100;
if (cores == 0)
cores = 1;
if (cores > omp_get_num_procs())
cores = omp_get_num_procs();
int m;

#pragma omp parallel for num_threads (cores) private(m)
for (m = 0; m < (int)num_vertices; m++)
{
Point3 v;
Vertex *vtemp;
v.x = vert[m].v[0];
v.y = vert[m].v[1];
v.z = vert[m].v[2];
vtemp = object_find_vertex_point(ob, &v);
vindex[m] = ac_object_get_vertex_index(ob, vtemp);
}

Last edited by modeler; 27th December 2020 at 11:29 AM.
modeler is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -4. The time now is 09:42 AM.


AC3D Forum
(C) Inivis Limited 2020