cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

mordakhay
Journeyman III

Check Brook progarm

Dear all,
Kindly I want to know why this program do well when the parameter nstep is less than 150 . I want any one to compile it and check if the result is big numbers when nstep more than 150.
I use brook 0.5 & MSVS 2005 & vista home edition & nvidia geforce 8400M GS.
- do you think this problem related to display card (Nvidia 8400)?
- why defination of "iter float its<499> = iter(1.0f, 500.0f); " must be before any defination . i.e. if you move it down in the program the token error appears

Thanks alot for your time

 

 

// This program named sum.br used to calculate parameter "ex"
//.......................
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

kernel void electric_field(float exs[],float cees[],float cehs[],float hys[],iter float its<>,float cs[],float pulse,out float o_exs<>{
float to = 1.0f;
o_exs = (cees[its]*exs[its])+(cehs[its]*(hys[its-to]-hys[its]))+(cs[its]*pulse);
}

kernel void magnetic_field(float hys[],float chhs[],float ches[],float o_exs[], iter float its<>,out float o_hys<>
{
    float to = 1.0f;
    o_hys = (chhs[its]*hys[its])+(ches[its]*(o_exs[its]-o_exs[its+to]));

}

int main()
{
    const int kz = 501;
    const int nstep =300;
    const int M = 4;
    const int delta = 10;
    int sp,kc;
    float sigmamax,sigmaze[kz],sigmazh[kz];
    float ex[kz],hy[kz],cee[kz],ceh[kz],chh[kz],che[kz],acs[kz];
    float exs<kz>,hys<kz>,cees<kz>,cehs<kz>,chhs<kz>,ches<kz>;
    float o_exs<kz>,o_hys<kz>,cs<kz>;
    float pi,co,dt,dz,epso,muo,freq,lumbda,tto,spread,fmax;
    float* pulse=NULL;
    int i,k;
    iter float its<499> = iter(1.0f, 500.0f);       
    kc = kz/2;
    sp = (int)kc;
    pi=4*atan(1.);
    co=3e+08;
    epso=8.854;
    epso=epso*1e-6;
    epso=epso*1e-6;
    muo=4*pi;
    muo=muo*1e-4;
    muo=muo*1e-3;
    freq = 600e6;
    lumbda = co/freq;
    dz =lumbda/20;
    dt = dz/co;
    dt = 0.5*dt;
    spread = 10.0;
    tto = 3*spread;
    fmax = 1/(2*dt*spread);
    sigmamax = 0.8*(float)(M+1)/(120*pi*dz);

   for(k=0;k<kz;k++){
        if (k<(kz/2))
       sigmaze=(pow(((float)(delta-k+1)/(float)(delta)),M))*sigmamax;
        else
       sigmaze=(pow(((float)(k-(kz-delta))/(float)(delta)),M))*sigmamax;
    }
    for(k=0;k<kz;k++){
        if (k<kz/2)
    sigmazh=(pow((((float)(delta-k)+0.5)/(float)(delta)),M))*sigmamax;
        else
  sigmazh=(pow((((float)(k-(kz-delta))+0.5)/(float)(delta)),M))*sigmamax;
    }
    for(k=delta+1;k<kz-delta-1;k++){
        sigmaze=0.;
        sigmazh=0.;
    }
 
   for(k=0;k<kz;k++){
   acs=0;
        ex=0;
        hy=0;
        cee=(2*epso-sigmaze*dt)/(2*epso+sigmaze*dt);
        ceh=(2*dt/dz)/(2*epso+sigmaze*dt);
        chh=(2*epso-sigmazh*dt)/(2*epso+sigmazh*dt);
        che=(2*epso*dt/(dz*muo))/(2*epso+sigmazh*dt);
    }

   
    acs[sp]=1;
    streamRead(cees,cee);
    streamRead(cehs,ceh);
    streamRead(chhs,chh);
    streamRead(ches,che);
    streamRead(exs,ex);
    streamRead(hys,hy);
    streamRead(cs,acs);

pulse = (float*)malloc(nstep*sizeof(float));

   pulse[0]=0;
                       

    for(i=1;i<nstep;i++){
      pulse=exp(-0.5*pow(((i-tto)/spread),2));
        if(i%2==0){
            electric_field(exs,cees,cehs,hys,its,cs,pulse
,o_exs);
            magnetic_field(hys,chhs,ches,o_exs,its,o_hys);
        }
        else
        {
            electric_field(o_exs,cees,cehs,o_hys,its,cs,pulse,exs);
            magnetic_field(o_hys,chhs,ches,exs,its,hys);
        }
    }         
   if(i%2==0){
      streamWrite(o_exs,ex);
      streamWrite(o_hys,hy);
      streamWrite(cs,acs);
         }
   else
      {
      streamWrite(cs,acs);
      streamWrite(exs,ex);
      streamWrite(hys,hy);
      }
    for (i=1; i<kz; i++) {
   printf("%e \n",ex
);
    }
printf("program complete\n");
return 0;
}

0 Likes
2 Replies
mordakhay
Journeyman III

The above code is just a *.br

Kindly, try to compile it to know if the problem in my display drive since as I increase "nstep" parameter the resulted answer away from the correct one as I expected the result between 0 and 1.

Thanks much for your time 

0 Likes
Ceq
Journeyman III

Well, this forum is for Brook+ only, not BrookGPU, but I'll try to help anyway.

1. If you try to run this in Brook+ it would complain about the iterator, because it isn't supported
Looking at the code I found out something that I think is wrong, you're using the iterator value
as an array index, however the iterator doesn't match the size of the output string, so it would be reshaped.
Try using within the kernel: "float its = indexof(o_exs);"

2. You're using "pulse" as a parameter for "electric_field", but you're passing the pointer, not the element.
I'm not sure, but probably you want to use "pulse[ i ]", and the same in the last printf "ex[ i ]"

3. After changing those things, no matter what the value of "nstep" is, I get "-1.#IND00e+000"

4. If you only have an nVidia card, you can try running it on Brook+ software backend, just install the SDK
and set environment variable BRT_RUNTIME = CPU
0 Likes