using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using InterlMKLLib;
using mkl;
using System.Threading;

namespace TestIntelMKL64
{
    class Program
    {
        private const int SIZE = 16384;      
        private static int counter = 0;

        static void Main(string[] args)
        {           
            for (int i = 0; i < 10000; i++)
            {               
                Thread thd = new Thread(IntelCalculations, 1024 * 1024 * 4);
                thd.Start();               
            }

            while (true)
            {

            }
        }

        unsafe private static void IntelCalculations()
        {
            Console.WriteLine("MethodCalledCount: {0} ", counter++);

            float* time = stackalloc float[SIZE];
            float* harm = stackalloc float[SIZE];
            float* resultAbs = stackalloc float[SIZE];
            float* resultArg = stackalloc float[SIZE];
            float* resultArgMultTime = stackalloc float[SIZE];
            float* reals = stackalloc float[SIZE];
            float* images = stackalloc float[SIZE];

            for (int i = 0; i < SIZE; i++)
            {
                reals[i] = i;
                images[i] = i;
            }

            Thread.Sleep(1000);

            //IntelMathLib.Hypot(SIZE, reals, images, resultAbs);    //not releasing threads
            //IntelMathLib.Atan2(SIZE, reals, images, resultArg);    //not releasing threads

            //IntelMathLib.Add(SIZE, resultArg, time, resultArgMultTime);    //automatic release threads

            //IntelMathLib.Mult(SIZE, resultArgMultTime, harm, time);    //automatic release threads

            IntelMathLib.Cos(SIZE, time, resultArg); //not releasing threads              
        }
    }

}
