I have a cube of 1 million points followed by an attribute wrangle with a flow field algorithm, using run over numbers so I can multi-thread it.
Single threaded the memory slowly climbs to 18 GB, which is a lot more than the points and arrays use.
When I multi-thread it the ram increases to my limit(64 GB) then crashes.
Can anyone tell me why this wrangle uses so much ram?
int resourcesArray[]; resourcesArray = detail(0,"resourcesArray",0); int resourcePt = resourcesArray[@elemnum]; int current = resourcePt; float gCostArray[]; float gCost[]; int ptArray[]; int inOpen[]; int inClosed[]; float cost[] = detail(0,"costArray",0); int obst[] = detail(0,"obstArray",0); int border[]; int iter = 0; gCostArray[0] = 0; ptArray[0] = current; int ptCount = chi("/obj/grid1/populate_points1/x") * chi("/obj/grid1/populate_points1/y") * chi("/obj/grid1/populate_points1/z"); int yUD = chi("/obj/grid1/populate_points1/x") * chi("/obj/grid1/populate_points1/z"); int zUD = chi("/obj/grid1/populate_points1/z"); function int[]getNeigh(int pointNum; int yUpDown; int zUpDown; int ptCount; int obst[]) { int neigh[]; for(int x = -1; x < 2; x ++){ for(int y = -1; y < 2; y ++){ for(int z = -1; z < 2; z ++){ int ptn = pointNum + (1 * x) + (yUpDown * y) + (zUpDown * z); if(ptn != pointNum && obst[ptn] == 0 && ptn >=0 && ptn < ptCount) { push(neigh,ptn); } } } } return neigh; } for(int i = 0; i < @numpt; i++) { push(inOpen,0); push(inClosed,0); push(gCost,10000000.0); } gCost[current] = 0; while(len(ptArray) > 0) { iter ++; if(iter % 1000 == 0) { printf("%g\n",iter); } float minG = min(gCostArray); int indexMinG = find(gCostArray,minG); current = ptArray[indexMinG]; inOpen[current] = 0; inClosed[current] = 1; removeindex(gCostArray,indexMinG); removeindex(ptArray,indexMinG); int neighs[] = getNeigh(current,yUD,zUD,ptCount,obst); foreach(int neigh; neighs) { if(obst[neigh] == 0 && inClosed[neigh] == 0) { vector pos1 = point(0,"P",neigh); vector pos2 = point(0,"P",current); float dist = distance(pos1,pos2); float newgCost = dist + cost[neigh]+ gCost[current]; if(newgCost < gCost[neigh] || inOpen[neigh] == 0) { gCost[neigh] = newgCost; if(inOpen[neigh] == 0) { inOpen[neigh] = 1; push(gCostArray,newgCost); push(ptArray,neigh); } } } } } string dAt = "channel" + itoa(@elemnum); setdetailattrib(0,dAt,gCost,"set");