{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "da7c16b4",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "original_df= pd.read_csv(\"data/data-single-multi-original.csv\",delimiter=\",\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "9ba9bfd9",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "df = original_df.copy()\n",
    "df = df.fillna(\"None\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "85c7c7d3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['Allreduce', 'Scatterv', 'Gather', 'Alltoall', 'Allgatherv',\n",
       "       'Gatherv', 'Bcast', 'Reduce', 'Reduce_scatter', 'Scatter',\n",
       "       'Allgather'], dtype=object)"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "msg_sizes = df['msg_size_bytes'].unique().copy()\n",
    "msg_sizes.sort()\n",
    "msg_sizes.tolist()\n",
    "small_msg = msg_sizes[msg_sizes<4097]\n",
    "big_msg = msg_sizes[msg_sizes>=4097]\n",
    "small_msg,big_msg\n",
    "sub_benchmarks = ['Allreduce','Gather','Scatter','Alltoall','Allgather']\n",
    "df['benchmark_type'].unique()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f2ebfba",
   "metadata": {},
   "source": [
    "### Effect of OFF-CHACHE-FLAG"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "6bca1dad",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "df_subb = df[df['benchmark_type'].isin(sub_benchmarks)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "37d6731a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 529844 characters]",
      "text/plain": [
       "<Figure size 2811.11x1500 with 45 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "g_small = sns.FacetGrid(df_subb[df_subb['msg_size_bytes'].isin(small_msg)], row='benchmark_type', col='proc_num', hue='off_cache_flag', margin_titles=True, sharey=False,sharex=True,despine=False)\n",
    "g_small.map_dataframe(sns.lineplot, x='msg_size_bytes', y='t_avg_usec')\n",
    "# g_small.set(xscale=\"log2\", yscale=\"linear\")\n",
    "for ax in g_small.axes.flat:\n",
    "    ax.set_xscale(\"log\",base=2)\n",
    "g_small.add_legend()\n",
    "g_small.set_axis_labels(\"Message Size (bytes)\", r\"Avg Time ($\\mu$s)\")\n",
    "plt.subplots_adjust(top=0.9)\n",
    "g_small.figure.suptitle(\"MPI Benchmark: Offmem Impact on Avg Time (Message Size < 4kb)\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "ab5719ea",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 513588 characters]",
      "text/plain": [
       "<Figure size 2811.11x1500 with 45 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "g_big = sns.FacetGrid(df_subb[df_subb['msg_size_bytes'].isin(big_msg)], row='benchmark_type', col='proc_num', hue='off_cache_flag', margin_titles=True, sharey=False,sharex=True,despine=False)\n",
    "g_big.map_dataframe(sns.lineplot, x='msg_size_bytes', y='t_avg_usec')\n",
    "# g_big.set(xscale=\"linear\", yscale=\"linear\")\n",
    "for ax in g_big.axes.flat:\n",
    "    ax.set_xscale(\"log\",base=2)\n",
    "g_big.add_legend()\n",
    "g_big.set_axis_labels(\"Message Size (bytes)\", r\"Avg Time ($\\mu$s)\")\n",
    "plt.subplots_adjust(top=0.9)\n",
    "g_big.figure.suptitle(\"MPI Benchmark: Offmem Impact on Avg Time (Message Size > 4kb)\")\n",
    "plt.savefig(\"plots/off_cache_flag_effect1.png\")\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "data",
   "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.13.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
