{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import matplotlib as mpl\n",
    "%matplotlib tk\n",
    "import numpy as np\n",
    "from scipy import optimize"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def speedup(P, alpha_over_beta) :\n",
    "    N = 1e7\n",
    "    return P/(1+alpha_over_beta*P/N)\n",
    "\n",
    "thread = np.array([1, 2, 4, 8, 16])\n",
    "\n",
    "times = []\n",
    "# times.append(np.array([43.8, 27.7, 18.4, 11.4, 9.5]))  # 100'000 * 100\n",
    "\n",
    "# times.append(np.array([44.0, 29.0, 18.5, 11.7, 9.8]))  # 100'000 * 100\n",
    "times.append(np.array([51.4, 33.3, 18.5, 11.0, 9.3]))  # 100'000 * 100\n",
    "# times.append(np.array([42.5, 30.9, 22.5, 19.1, 18.1])) # 1'000 * 10'000\n",
    "# times.append(np.array([52.5, 32.6, 18.4, 12.0, 9.8]))  # 10'000'000 * 1\n",
    "\n",
    "# labels = ['npatch = 100k', 'npatch = 100k-v2', 'npatch = 1k', 'npatch = 10M']\n",
    "labels = ['Kokkos-OMP, npatch = 100k']\n",
    "\n",
    "fontsize = 24\n",
    "for time, label in zip(times, labels):\n",
    "    plt.plot(thread, time[0]/time, '-o', label=label)\n",
    "\n",
    "\n",
    "plt.plot(thread, thread/thread[0], '--', label='linear')\n",
    "\n",
    "# params, _ = optimize.curve_fit(speedup, thread, times[1][0]/times[-1])\n",
    "# print(params)\n",
    "# print(speedup(thread, params))\n",
    "# plt.plot(thread, speedup(thread, params[0]), '--', label='fit: 100k-v2')\n",
    "\n",
    "plt.grid()\n",
    "plt.legend(loc='best',fontsize=fontsize)\n",
    "plt.xlabel(\"# threads\", fontsize=fontsize)\n",
    "plt.ylabel(\"Speedup\", fontsize=fontsize)\n",
    "plt.yticks(fontsize=fontsize)\n",
    "plt.xticks(fontsize=fontsize)\n",
    "plt.show()\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(400, 224)\n",
      "(224, 400)\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "grid = pd.read_csv('example/resp', sep=' ', header=None)\n",
    "grid = grid.to_numpy()[:,:-1]\n",
    "print(grid.shape)\n",
    "grid = np.transpose(grid, (1,0))\n",
    "print(grid.shape)\n",
    "\n",
    "\n",
    "clim = [-1000,1000]\n",
    "clim = [-1e-14,1e-14]\n",
    "\n",
    "cmap = \"bwr\"\n",
    "plt.figure()\n",
    "img = plt.imshow(grid, cmap=cmap, interpolation=\"none\"\n",
    ", norm=mpl.colors.SymLogNorm(linthresh = 1.0, vmin = clim[0], vmax = clim[1], base=10)\n",
    ", origin='lower'\n",
    ", aspect='auto'\n",
    ")\n",
    "plt.clim(clim)\n",
    "plt.colorbar(img)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([['0', '0', '0', ..., '0', '0', '0'],\n",
       "       ['0', '0', '0', ..., '0', '0', '0'],\n",
       "       ['0', '0', '0', ..., '0', '0', '0'],\n",
       "       ...,\n",
       "       [0.0, 0.0, 0.0, ..., 0.0, 0.0, 0.0],\n",
       "       [0.0, 0.0, 0.0, ..., 0.0, 0.0, 0.0],\n",
       "       [0.0, 0.0, 0.0, ..., 0.0, 0.0, 0.0]], dtype=object)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "grid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
