找回密码
 注册
查看: 2852|回复: 0

UDF并行问题

[复制链接]
发表于 2013-6-13 22:05:23 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
下面是我按照help manual修改的代码的一部分,可以串行,并行也可以运行,只是传值有问题,不知道应该怎么修改,求助哇!!!

1、这是help manual的例子
Example: Writing Data to a Common File on the Host Process’s File System
/*******************************************************************
   This function will write pressures and positions
    for a fluid zone to a file on the host machine
 ********************************************************************/
 #include "udf.h"
 
 # define FLUID_ID 2
 
 DEFINE_ON_DEMAND(pressures_to_file)
 {
    /* Different variables are needed on different nodes */
 #if !RP_HOST
   Domain *domain=Get_Domain(1);
   Thread *thread;
   cell_t c;
 #else
   int i;
 #endif
 
 #if !RP_NODE
   FILE *fp = NULL;
   char filename[]="press_out.txt";
 #endif
 
 #if&#160ARALLEL
   int size; /* data passing variables */
   real *array;
   int pe;
 #endif
/* Only Serial and Compute Nodes have data on threads */
 #if !RP_HOST
   thread=Lookup_Thread(domain,FLUID_ID);
 #endif 
 #if !RP_NODE /* SERIAL or HOST */
   if ((fp = fopen(filename, "w"))==NULL)
      Message("\n Warning: Unable to open %s for writing\n",filename);
   else
      Message("\nWriting&#160ressure to %s...",filename);
 #endif
/* UDF Now does 3 different things depending on SERIAL, NODE or HOST */
 
 #if !PARALLEL /* SERIAL */
   begin_c_loop(c,thread)
       fprintf(fp, "%g\n", C_P(c,thread));/* Simply write out pressure data */
   end_c_loop(c,thread)
 #endif /* !PARALLEL */
 
 #if RP_NODE
   /* Each Node loads up its data passing array */
   size=THREAD_N_ELEMENTS_INT(thread);
   array = (real *)malloc(size * sizeof(real));
   begin_c_loop_int(c,thread)
     array[c]= C_P(c,thread);
   end_c_loop_int(c,thread)

   /* Set pe to destination node */
   /* If on node_0 send data to host */
   /* Else send to node_0 because */
   /*  compute nodes connect to node_0 & node_0 to host */
   pe = (I_AM_NODE_ZERO_P) ? node_host : node_zero;
   PRF_CSEND_INT(pe, &size, 1, myid);
   PRF_CSEND_REAL(pe, array, size, myid);
   free(array);/* free array on nodes after data sent */

   /* node_0 now collect data sent by other compute nodes */
   /*  and sends it straight on to the host */

if (I_AM_NODE_ZERO_P)
   compute_node_loop_not_zero (pe)
   {
      PRF_CRECV_INT(pe, &size, 1, pe);
      array = (real *)malloc(size * sizeof(real));
      PRF_CRECV_REAL(pe, array, size, pe);
      PRF_CSEND_INT(node_host, &size, 1, myid);
      PRF_CSEND_REAL(node_host, array, size, myid);
      free((char *)array);
   }
 #endif /* RP_NODE */
 
 #if RP_HOST
   compute_node_loop (pe) /* only acts as a counter in this loop */
     {
        /* Receive data sent by each node and write it out to the file */
        PRF_CRECV_INT(node_zero, &size, 1, node_zero);
        array = (real *)malloc(size * sizeof(real));
        PRF_CRECV_REAL(node_zero, array, size, node_zero); 

  &#160;for&#160;(i=0;&#160;i<size;&#160;i++)
      fprintf(fp,&#160;"%g\n",&#160;array);

   free(array);
}
&#160;#endif&#160;/*&#160;RP_HOST&#160;*/
&#160;
&#160;
&#160;#if&#160;!RP_NODE&#160;/*&#160;SERIAL&#160;or&#160;HOST&#160;*/
   fclose(fp);&#160;/*&#160;Close&#160;the&#160;file&#160;that&#160;was&#160;only&#160;opened&#160;if&#160;on&#160;SERIAL&#160;or&#160;HOST&#160;*/
   Message("Done\n");
&#160;#endif
&#160;
&#160;}&#160;

2、这是我编写的UDF的一部分
#if !RP_HOST
float f[16];
#endif/*!RP_HOST*/

#if PARALLEL
   float *array;
   int pe;
   int size;
#endif/*PARALLEL*/

#if RP_NODE
       size=16;
       array=(float*)malloc(size*sizeof(float));
           for(i=0;i<size;i++)
           {array=f;}
          
           pe=(I_AM_NODE_ZERO_P)?node_host:node_zero;
           PRF_CSEND_INT(pe,&size,1,myid);
           PRF_CSEND_FLOAT(pe,array,size,myid);
           free(array);
           if(I_AM_NODE_ZERO_P)
                   compute_node_loop_not_zero(pe)
               {
                 PRF_CRECV_INT(pe,&size,1,pe);
                         array=(float*)malloc(size*sizeof(float));
                         PRF_CRECV_FLOAT(pe,array,size,pe);
                         PRF_CSEND_INT(node_host,&size,1,myid);
                 PRF_CSEND_FLOAT(node_host,array,size,myid);
                         free((char*)array);
                        }
#endif/*RP_NODE*/

#if RP_HOST
           compute_node_loop(pe)
             {
                         PRF_CRECV_INT(node_zero,&size,1,node_zero);
                         array=(float*)malloc(size*sizeof(float));
                         PRF_CRECV_FLOAT(node_zero,array,size,node_zero);
                         F[0][0]=array[0];F[0][1]=array[1];F[1][0]=array[2];F[1][1]=array[3];F[2][0]=array[4];F[2][1]=array[5];F[3][0]=array[6];F[3][1]=array[7];
                         F[4][0]=array[8];F[4][1]=array[9];F[5][0]=array[10];F[5][1]=array[11];F[6][0]=array[12];F[6][1]=array[13];F[7][0]=array[14];F[7][1]=array[15];
                         free(array);
             }
#endif
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表