Simple task from example failing to execute

Simple task from example failing to execute

Hi all,

I' ve got a simple example from http://software.intel.com/sites/products/documentation/doclib/mkl_sa/11/mklman/index.htm

which works fine.

I wrote the pretty similar code

#include <stdio.h>
#include "mkl.h"
#include "errcheck.inc"

#define NPART 10
#define NDIM 2
#define STREAMFILENAME "task.stream"

int main(){

  VSLStreamStatePtr stream;
  FILE* streamfile;
  int errcode=0;
  double *r=malloc(NPART*NDIM*sizeof(double));
  double M[]={1e0,0e0},S[]={1e0,1e0};

  VSLSSTaskPtr task;
  double *m=malloc(NDIM*sizeof(double));
  MKL_INT rstorage=VSL_SS_MATRIX_STORAGE_ROWS;
  int ipart=0,idata=0,idim=0;
  MKL_INT npart=NPART,ndim=NDIM,xstorage=VSL_SS_MATRIX_STORAGE_COLS;

  streamfile=fopen(STREAMFILENAME,"r");
  if(streamfile){
    fclose(streamfile);
    errcode=vslLoadStreamF(&stream,STREAMFILENAME);
  }else{
    errcode=vslNewStream(&stream,VSL_BRNG_MCG31,7777777);
  }

  errcode=vdRngGaussianMV(VSL_RNG_METHOD_GAUSSIANMV_BOXMULLER2,stream,
    NPART,(double*)r,NDIM,VSL_MATRIX_STORAGE_DIAGONAL,M,(double*)S);

  errcode=vsldSSNewTask(&task,&npart,&ndim,&xstorage,r,0,0);

  errcode=vsldSSEditTask(task,VSL_SS_ED_MEAN,m);

  errcode=vsldSSCompute(task,VSL_SS_MEAN,VSL_SS_METHOD_FAST);
  errcode=vslSSDeleteTask(&task);
  CheckVslError(errcode);

  for(idim=0;idim<NDIM;idim++)printf("%20.16e ",m[idim]);
  printf("\n");  free(r);
  free(m);
  errcode=vslSaveStreamF(stream,STREAMFILENAME);

  return 0;
}

this wont work at all. I can compile and run, but a fatal error occurs

in between vsldSSCompute and result printing.

Where am I doing the error? Can someone help me?

Thanks!

 

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Best Reply

Hi Fabio,

You generate 10 vectors of size 2 with MKL multi-variate version of Gaussian RNG, thus, the dimension of Summary Stats task p should be set to 2, and number of observations n - to 10. Please, replace the line errcode=vsldSSNewTask(&task,&npart,&ndim,&xstorage,r,0,0); with errcode=vsldSSNewTask(&task,&ndim, &npart,&xstorage,r,0,0);

Also, do not forget to delete the memory allocated for need of random number generation via call to the function vslDeleteStream();

Please, let me know if it answers your question.

Andrey

 

Andrey,

thanks, that was the fault! I am guessing if the array-linear representation

I am using and called in the routine vsldSSNewTask is either the

{x_0,y_0,...,x_npart,y_npart}

or

{x_0,...,x_npart,y_0,...,y_npart}

?

Hi Fabio,

MKL Multi-variate Gaussian RNG packs the numbers in column-major format, that is

{ (x(0),y(0)),
  (x(1),y(1)),
  (x(2),y(2)),
   ...
};

So, in your example you correctly specified the storage format for the dataset xstorage=VSL_SS_MATRIX_STORAGE_COLS;

Andrey

OK! Thank you very much for everything!

Login to leave a comment.