Fluids

Fluids

Message statment from UDF with parallel run prints nan(ind) but not in serial.

    • atulsingh92
      Subscriber
      Hello, nI have a UDF printing out results of few function calls.nThis when run with the serial configuration, still prints twice than what is requested in the funciton, with once in nan, while with the answer the second time.nAnd when is run with parallel configuration, there are number of cores+1 times the printing of Message command's output.nFor instance the function would look something like thisndouble calulateReynolds(Domain *domain , int id)n{n cell_t c;n Thread *t;n int cells = 0;n face_t f;n t = Lookup_Thread(domain, id);n n double vmag=0.0, vmag_total , rho, mu, reynolds;n begin_c_loop(c,t)n {n uc = C_U(c,t);n vc = C_V(c,t);n wc = C_W(c,t); n rho = C_R(c,t);n mu = C_MU_T(c,t);n vmag += sqrt(pow(uc,2) + pow(vc,2) + pow(wc,2));n cells += 1;n /Message(Velocity is %g, vmag);n }n end_c_loop(c,t)n n # if RP_NODEn vmag = PRF_GRSUM1(vmag);n # endifn n node_to_host_real_1(vmag);n n double avgv = vmag/cells;nn reynolds = rho * avgv * Dia / mu ;nn return reynolds;ncalled as and printed as followsnreynolds_obtained2 = calulateReynolds(domain, 7);nnMessage(reynolds obtained is: %g, reynolds_obtained2);nnSerial result will be asnreynolds obtained is: -nan(ind)nnreynolds obtained is: 29934.524nwhile parallel result would be the above and rest of print (Message) statements with -nan(ind) values, 7 times while sometimes with the actual required values.nIs there a way I could correct this?nMy guess was to use the node_to_host_real_1(variable) inorder to send only one required answer to the host, but apparently that is mixing up the resultn
    • YasserSelima
      Subscriber
      add this after the end_c_loopnvmag = vPRF_GRSUM1(vmag);ncells = PRF_GISUM1(cells);nnAlso remove node_to_host .. you don't need itn
    • atulsingh92
      Subscriber
      Doesn't seem to work, nstill prints 5 times (see ***********) , when used with 4 cores, and have multiple -nan(Ind)n ******************************nPressure drop pipe 1(Pa) -nan(ind) = p_inlet -nan(ind) - p_outlet -nan(ind)nVelocity average is at pipe 1: -nan(ind)nfrictionfactor is: -nan(ind)nPressure drop pipe 2(Pa) -nan(ind) = p_inlet -nan(ind) - p_outlet -nan(ind)nVelocity average is at pipe 2: -nan(ind)nfrictionfactor is: -nan(ind)n******************************nPressure drop pipe 1(Pa) 0 = p_inlet 975.903 - p_outlet 975.903nVelocity average is at pipe 1: 9.52898nfrictionfactor is: 0nPressure drop pipe 2(Pa) 0 = p_inlet 975.903 - p_outlet 975.903nVelocity average is at pipe 2: 10.8784nfrictionfactor is: 0n******************************nPressure drop pipe 1(Pa) -nan(ind) = p_inlet -nan(ind) - p_outlet 113.768nVelocity average is at pipe 1: 9.52898nfrictionfactor is: -nan(ind)nPressure drop pipe 2(Pa) 0 = p_inlet 113.768 - p_outlet 113.768nVelocity average is at pipe 2: 10.8784nfrictionfactor is: 0n******************************nPressure drop pipe 1(Pa) -nan(ind) = p_inlet -nan(ind) - p_outlet -nan(ind)nVelocity average is at pipe 1: 9.52898nfrictionfactor is: -nan(ind)nPressure drop pipe 2(Pa) 0 = p_inlet 1240.94 - p_outlet 1240.94nVelocity average is at pipe 2: 10.8784nfrictionfactor is: 0n******************************nPressure drop pipe 1(Pa) -nan(ind) = p_inlet -nan(ind) - p_outlet -nan(ind)nVelocity average is at pipe 1: 9.52898nfrictionfactor is: -nan(ind)nPressure drop pipe 2(Pa) -nan(ind) = p_inlet -nan(ind) - p_outlet 182.743nVelocity average is at pipe 2: 10.8784nfrictionfactor is: -nan(ind)nnn
    • YasserSelima
      Subscriber
      This is because every node is printing a message. The above lines help you to get the same Re ... where are you printing the message?n
    • atulsingh92
      Subscriber
      So, the above result is based on a DEFINE_ON_DEMAND(get_results) method, after achieveing convergence. (Note RE was just an example, to show the problem, other methods printed above are called as similar to the Reynolds discussed above.)nIn this DEFINE_ON_DEMAND, I call all the methods to calculate the required values, and at the end, the results are to be printed in Message() commands.nAlso, based on your answer, does that mean, I cannot have only one node printing the answer? And most importantly correctly?n
    • YasserSelima
      Subscriber
      If you want one node printing the message , make it Message0 ... this makes node 0 only print the message. Or ... n#if RP_HOSTnMessage(Whatever);n#endifnThe latter makes the host only to print the message. nIn all cases, if you loop through cell thread, every node will have a value from the threads assigned to it. That's why you need to use parallelisation macros ... these two macros should be used after SUM ... one for real and one for integersnvmag = PRF_GRSUM1(vmag);ncells = PRF_GISUM1(cells);nnThere are other macros should be used after MIN , MAX ... etc. check the UDF manual for detailsnn
    • DrAmine
      Ansys Employee
      Or calculate it on each node and then get the max or mix or whatever for all nodes together via a reduction. n
Viewing 6 reply threads
  • You must be logged in to reply to this topic.