If statement inside loop

18 views
Skip to first unread message

Shivam Malhotra

unread,
Nov 4, 2015, 6:24:07 AM11/4/15
to Clan Users
Is it possible to put an if condition inside a loop to be parallelized.
My code looks like:

#define get_xp(a1,a2) xp[a1][a2]
#define get_R(a1) R[a1]   

   for(i=Nboun+1;i<=Npartstot;i++)
       {
           for (n=1;n<=3;++n)
           {
            j=neb[i][n];
            dxij[1]=xp[i][1]-get_xp(j,1);
            Rj =  get_R(j);
            temp1 = dxij[1];
            temp2 = L-rng*(R[i]+ Rj);
           
            if( temp1 > temp2){
                dxij[1]=dxij[1]-L;
              }
      
          }
      }


If need to read from nth neighbor of ith particle, so I use the #define trick suggested in earlier post.
Basically doing this is giving me the following error at the if condition : "variable or array reference in an affine expression".

The same if condition if I code as a ternary operator, it works fine with clan

dxij[1] = (temp1>temp2)? dxij[1] : dxij[1] - L


But my actual code should contain a number of instructions inside the if statement, thus I cannot make it all as ternary operator. Is there any workaround for this so that I can get through clan to feed it into pluto for parallelization?
I think I am not able to understand what is allowed in condition of if statement.

Sincerely,
Shivam Malhotra




Cédric Bastoul

unread,
Nov 6, 2015, 5:38:09 AM11/6/15
to clan-...@googlegroups.com
Hi Shivam Malhotra,
I must admit Clan does not support this directly yet, except by using workarouds such as #define pragmas or ternary operators. The problem is, Clan only accepts at the moment non-data-dependent affine constraints in either conditions or loop bounds. The constraints are summarized there :

Note that this is "just" a technical limitation : it is easy to extend this but we need some engineering time. It will be suported at some point, but it depends on the contributor time so I have no clear date when it will be available (if you want to contribute, I can explain your how ;-) !).
Best,

Cedric


--
You received this message because you are subscribed to the Google Groups "Clan Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clan-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages