![]() |
#1 |
Member
Advanced member
Join Date: Nov 2003
Posts: 34
|
![]()
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); } |
![]() |
![]() |
![]() |
#2 |
Administrator
Professional user
Join Date: Jun 2003
Posts: 4,523
|
![]()
That's interesting. Do you mean that it doesn't link or doesn't load or doesn't run?
|
![]() |
![]() |
![]() |
#3 |
Member
Advanced member
Join Date: Nov 2003
Posts: 34
|
![]()
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); } |
![]() |
![]() |
![]() |
#4 |
Member
Advanced member
Join Date: Nov 2003
Posts: 34
|
![]()
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. |
![]() |
![]() |
![]() |
Thread Tools | |
Display Modes | |
|
|