using System; using System.Runtime.InteropServices; using System.Security; using mkl; public class test_vsl { private test_vsl() { } public static void Main(string[] args) { /* Data initialization */ double[] A = { 10, 20, 30 }; int dim = 1; int n = 3; double[] min_est = { 1 }; double[] max_est = { 1 }; IntPtr task = new IntPtr(); /* setup task and compute */ VSL.vsldSSNewTask(ref task, ref dim, ref n, ref VSL.VSL_SS_MATRIX_STORAGE_ROWS, A, null, null); VSL.vsldSSEditTask(task, VSL.VSL_SS_ED_MIN, min_est); VSL.vsldSSEditTask(task, VSL.VSL_SS_ED_MAX, max_est); VSL.vslsSSCompute(task, VSL.VSL_SS_MIN | VSL.VSL_SS_MAX, VSL.VSL_SS_METHOD_FAST); /* Print the result */ printVector("MIN: ", min_est, 1); printVector("MAX: ", max_est, 1); VSL.vslSSDeleteTask(ref task); Console.WriteLine("TEST PASSED"); Console.WriteLine(); } /** Print vector X */ private static void printVector(string prompt, double[] X, int N) { Console.WriteLine(prompt); for (int n = 0; n < N; n++) Console.Write("\t" + X[n]); Console.WriteLine(); } } namespace mkl { /** VSL wrappers */ public sealed class VSL { public static int VSL_SS_MATRIX_STORAGE_ROWS = 0x00010000; public static int VSL_SS_MATRIX_STORAGE_COLS = 0x00020000; public const int VSL_SS_ED_2R_MOM = 8; public const int VSL_SS_ED_2C_MOM = 11; public const int VSL_SS_ED_MIN = 16; public const int VSL_SS_ED_MAX = 17; public const int VSL_SS_MIN = 0x0000000000000400; public const int VSL_SS_MAX = 0x0000000000000800; public const int VSL_SS_METHOD_FAST = 0x00000001; private VSL() { } /** VSL vsldSSNewTaskref wrapper */ public static void vsldSSNewTask(ref IntPtr taskPtr, ref int dim, ref int num, ref int xstorage, double[] x, double[] weights, int[] indices) { VSLNative.vsldSSNewTask(ref taskPtr, ref dim, ref num, ref xstorage, x, weights, indices); } /** VSL vslsSSEditTask wrapper */ public static void vsldSSEditTask(IntPtr taskPtr, int taskNum, double[] results) { VSLNative.vsldSSEditTask(taskPtr, taskNum, results); } public static void vslsSSCompute(IntPtr taskPtr, int taskNum, int method) { VSLNative.vslsSSCompute(taskPtr, taskNum, method); } public static void vslSSDeleteTask(ref IntPtr taskPtr) { VSLNative.vslSSDeleteTask(ref taskPtr); } } /** VSL native declarations */ [SuppressUnmanagedCodeSecurity] internal sealed class VSLNative { private VSLNative() { } /** VSL vsldSSNewTask native declaration */ [DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = false)] internal static extern int vsldSSNewTask([In, Out] ref IntPtr task, [In] ref int p, [In] ref int n, [In] ref int xstorage, [In] double[] x, [In] double[] w, [In] int[] indices); /** VSL vsldSSEditTask native declaration */ [DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = false)] internal static extern int vsldSSEditTask([In] IntPtr task, [In] int parameter, [Out] double[] par_addr); /** VSL vslsSSCompute native declaration */ [DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = false)] internal static extern int vslsSSCompute([In] IntPtr task, [In] int estimates, [In] int method); /** VSL vslSSDeleteTask native declaration */ [DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = false)] internal static extern int vslSSDeleteTask([In] ref IntPtr task); } }