Ice Sheet System Model  4.18
Code documentation
Data Structures | Functions
PointCloudFindNeighborsx.h File Reference
#include "../../shared/shared.h"
#include "../../classes/classes.h"

Go to the source code of this file.

Data Structures

struct  PointCloudFindNeighborsThreadStruct
 

Functions

int PointCloudFindNeighborsx (IssmSeqVec< IssmPDouble > **pflags, double *x, double *y, int nods, double mindistance, double multithread)
 
void * PointCloudFindNeighborsxt (void *vPointCloudFindNeighborsThreadStruct)
 

Function Documentation

◆ PointCloudFindNeighborsx()

int PointCloudFindNeighborsx ( IssmSeqVec< IssmPDouble > **  pflags,
double *  x,
double *  y,
int  nods,
double  mindistance,
double  multithread 
)

Definition at line 6 of file PointCloudFindNeighborsx.cpp.

6  {
7 
8  /*output: */
9  IssmSeqVec<IssmPDouble>* flags=NULL;
10  flags=new IssmSeqVec<IssmPDouble>(nods);
11 
12  /*threading: */
13  int num=_NUMTHREADS_;
14  if(!multithread)num=1;
15 
16  /*initialize thread parameters: */
18  gate.x = x;
19  gate.y = y;
20  gate.nods = nods;
21  gate.mindistance = mindistance;
22  gate.flags = flags;
23 
24  /*launch the thread manager with InterpFromGridToMeshxt as a core: */
25  LaunchThread(PointCloudFindNeighborsxt,(void*)&gate,num);
26 
27  /*Assemble vector: */
28  flags->Assemble();
29 
30  /*Assign output pointers: */
31  *pflags=flags;
32 
33  return 1;
34 }

◆ PointCloudFindNeighborsxt()

void* PointCloudFindNeighborsxt ( void *  vPointCloudFindNeighborsThreadStruct)

Definition at line 8 of file PointCloudFindNeighborsxt.cpp.

8  {
9 
10  /*gate variables :*/
12  pthread_handle* handle=NULL;
13  int my_thread;
14  int num_threads;
15  double* x;
16  double* y;
17  int nods;
18  double mindistance;
20 
21  /*recover handle and gate: */
22  handle=(pthread_handle*)vpthread_handle;
24  my_thread=handle->id;
25  num_threads=handle->num;
26 
27  /*recover parameters :*/
28  x=gate->x;
29  y=gate->y;
30  nods=gate->nods;
31  mindistance=gate->mindistance;
32  flags=gate->flags;
33 
34  /*intermediary: */
35  int i,j;
36  int i0,i1;
37  double distance;
38  bool* already=NULL;
39 
40  /*allocate: */
41  already=xNewZeroInit<bool>(nods);
42 
43  /*partition loop across threads: */
44  PartitionRange(&i0,&i1,nods,num_threads,my_thread);
45 
46  /*Loop over the nodes*/
47  for (i=i0;i<i1;i++){
48 
49  /*display current iteration*/
50  if (my_thread==0 && fmod((double)i,(double)100)==0)
51  _printf_("\r loop progress: "<<setw(6)<<setprecision(2)<<double(i-i0)/double(i1-i0)*100<<"% ");
52 
53  distance=mindistance+100; //make sure initialization respects min distance criterion.
54  for (j=0;j<nods;j++){
55 
56  /*skip himself: */
57  if (j==i)continue;
58  distance=sqrt(pow(x[i]-x[j],2)+ pow(y[i]-y[j],2));
59 
60  if(distance<=mindistance){
61 
62  /*insert value and go to the next point*/
63  if(!already[i]) flags->SetValue(i,1,INS_VAL);
64  if(!already[j]) flags->SetValue(j,2,INS_VAL);
65  already[i]=true;
66  already[j]=true;
67  break;
68  }
69  }
70  }
71  if (my_thread==0)
72  _printf_("\r loop progress: "<<fixed<<setw(6)<<setprecision(2)<<100.<<"% \n");
73 
74  /*Free ressources:*/
75  xDelete<bool>(already);
76 
77  return NULL;
78 }
pthread_handle::id
int id
Definition: issm_threads.h:12
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
LaunchThread
void LaunchThread(void *function(void *), void *gate, int num_threads)
Definition: LaunchThread.cpp:25
PointCloudFindNeighborsThreadStruct::mindistance
double mindistance
Definition: PointCloudFindNeighborsx.h:20
pthread_handle::num
int num
Definition: issm_threads.h:13
IssmSeqVec< IssmPDouble >
IssmSeqVec::SetValue
void SetValue(int dof, doubletype value, InsMode mode)
Definition: IssmSeqVec.h:115
PointCloudFindNeighborsThreadStruct::x
double * x
Definition: PointCloudFindNeighborsx.h:17
PointCloudFindNeighborsThreadStruct::nods
int nods
Definition: PointCloudFindNeighborsx.h:19
pthread_handle
Definition: issm_threads.h:10
PointCloudFindNeighborsThreadStruct::y
double * y
Definition: PointCloudFindNeighborsx.h:18
PartitionRange
void PartitionRange(int *pi0, int *pi1, int num_el, int num_threads, int my_thread)
Definition: PartitionRange.cpp:13
INS_VAL
@ INS_VAL
Definition: toolkitsenums.h:14
PointCloudFindNeighborsxt
void * PointCloudFindNeighborsxt(void *vPointCloudFindNeighborsThreadStruct)
Definition: PointCloudFindNeighborsxt.cpp:8
PointCloudFindNeighborsThreadStruct
Definition: PointCloudFindNeighborsx.h:15
pthread_handle::gate
void * gate
Definition: issm_threads.h:11
IssmSeqVec::Assemble
void Assemble(void)
Definition: IssmSeqVec.h:92
PointCloudFindNeighborsThreadStruct::flags
IssmSeqVec< IssmPDouble > * flags
Definition: PointCloudFindNeighborsx.h:21