4 Replies Latest reply on Jul 20, 2010 10:04 PM by tannergooding

    Using zfft1d in c#

    fluktuation

      Hi,

      I am trying to use the acml (Intel fortran) Library with c# on a windows xp 32 bit.

      I added the functions and the struct as follows:

          public struct doublecomplex
              {
                  public double real, imag;
              };

          public class ACMLFunctions
          {

              [DllImport("libacml_dll")]

              public static extern void zfft1d(int mode, int length, doublecomplex[] input,doublecomplex[] help, ref int info);
          }

      calling the method like this:
      zfft1d(0, com.Length, com, ret, ref test);
      zfft1d(-1, com.Length, com, ret, ref test);

      i'll get back an unchanged array.

      using a ref for com and ret (in declaration and in the call)

      zfft1d(0, com.Length,ref com,ref ret, ref test);

      will crash

      If I dont use the 0 Mode(initialisation):

      zfft1d(-1, com.Length,ref com,ref ret, ref test);

      in the output array remains just the first unchanged element(the array is resized).

      I don't get the point, why the ref not work neither why the array is resized. The example csharp project for(dgesdd) works, and there is no reference used.

      Thanks

       

       

        • Using zfft1d in c#
          fluktuation

          Anyone got an idea? I can not be the first one with this problem

          • Using zfft1d in c#
            chipf

            Here is an example of using zgemm that we built.  We'll try to build a similar zfft1d example, but maybe this helps in the meantime:

             

             

            using System; using System.Runtime.InteropServices; using System.Text; [StructLayout (LayoutKind.Sequential)] public struct DoubleComplex { public double real; public double imag; public DoubleComplex (double r,double i) { this.real = r; this.imag = i; } public override string ToString() { return "(" + this.real + "," + this.imag+ ")"; } } namespace ACMLsignatures { public class ACMLFunctions { [DllImport("libacml_dll", CharSet=CharSet.Ansi)] public static extern void zgemm(char transa, char transb, int m, int n, int k, ref DoubleComplex alpha, [In] DoubleComplex[,] a, int lda, [In] DoubleComplex[,] b, int ldb, ref DoubleComplex beta, [In, Out] DoubleComplex[,] c, int ldc); } public class example { public static void Main() { int lda=5; int i, j; int m, n, k; DoubleComplex alpha, beta; DoubleComplex[,] a, b, c; Console.WriteLine("ACML example: Multiply of a matrix A and B using zgemm"); Console.WriteLine("--------------------------------------------"); Console.WriteLine(""); m = lda; n = lda; k = lda; alpha = new DoubleComplex(1.0, 0.5); beta = new DoubleComplex(0.5, 0.5); a = new DoubleComplex[m, k]; b = new DoubleComplex[k, n]; c = new DoubleComplex[m, n]; // build the a and b matrices for (i = 0; i < m; i++) { for (j = 0; j <n; j++) { a[i, j] = new DoubleComplex(i+1, j+3); b[i, j] = new DoubleComplex(i+2, j+4); c[i, j] = new DoubleComplex(1,0); } } Console.WriteLine("Matrix A:"); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { Console.Write(" "); Console.Write(a[i,j]); } Console.WriteLine(""); } Console.WriteLine("Matrix B:"); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { Console.Write(" "); Console.Write(b[i,j]); } Console.WriteLine(""); } /* Multiply A and B */ ACMLFunctions.zgemm('N', 'N', n, m, k, ref alpha, b, n, a, k, ref beta, c, n); /* Print solution */ Console.WriteLine("Matrix C:"); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { Console.Write(" "); Console.Write(c[i,j]); } Console.WriteLine(""); } } } }