00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include "converse.h"
00004 #include "../../../ck.h"
00005 #include "ampiProjections.h"
00006 #include "../../../traceCoreCommon.h"
00007 #include "ampiEvents.h"
00008 #include "cklists.h"
00009 #include "ampi.h"
00010 #include "ampiimpl.h"
00011 static int current_rank = -1;
00012 static int current_src = -1;
00013 static int current_count = -1;
00014 extern ampi *getAmpiInstance(MPI_Comm );
00015
00016
00017
00018
00019
00020 typedef struct {
00021 int funcNo;
00022 char *funcName;
00023 } funcData;
00024
00025
00026 typedef struct {
00027 int index;
00028 CkVec<int> funcList;
00029 } vprocData;
00030
00031 CkVec<funcData *> _funcTable;
00032 CkVec<vprocData *> vprocTable;
00033
00034 extern "C" void initAmpiProjections(){
00035
00036 }
00037
00038 extern "C" void closeAmpiProjections(){
00039 ampi_endProcessing(-1);
00040 }
00041
00042 extern "C" void ampi_beginProcessing(int rank,int src,int count){
00043 int iData[3];
00044 iData[0] = rank;
00045 iData[1] = src;
00046 if(vprocTable.size() <= rank || rank < 0){
00047 iData[2] = -1;
00048 }else{
00049 if(vprocTable[rank]->funcList.size() <= 0){
00050 iData[2] = -1;
00051 }else{
00052 iData[2] = vprocTable[rank]->funcList[vprocTable[rank]->funcList.size()-1];
00053 }
00054 }
00055 current_rank = rank;
00056 current_src = src;
00057 current_count = count;
00058 LogEvent1(_AMPI_LANG_ID,_E_BEGIN_AMPI_PROCESSING,3,iData);
00059 }
00060
00061 extern "C" void ampi_endProcessing(int rank){
00062 int iData[3];
00063 iData[0] = current_rank;
00064 iData[1] = current_src;
00065 if(vprocTable.size() <= rank || rank < 0){
00066 iData[2] = -1;
00067 }else{
00068 if(vprocTable[rank]->funcList.size() <= 0){
00069 iData[2] = -1;
00070 }else{
00071 iData[2] = vprocTable[rank]->funcList[vprocTable[rank]->funcList.size()-1];
00072 }
00073 }
00074
00075 LogEvent1(_AMPI_LANG_ID,_E_END_AMPI_PROCESSING,3,iData);
00076 }
00077
00078 extern "C" void ampi_msgSend(int tag,int dest,int count,int size){
00079 int iData[4];
00080 iData[0] = tag;
00081 iData[1] = dest;
00082 iData[2] = count;
00083 iData[3] = size;
00084
00085 LogEvent1(_AMPI_LANG_ID,_E_AMPI_MSG_SEND,4,iData);
00086 }
00087
00088
00089 extern "C" int ampi_registerFunc(char *funcName){
00090 for(int i=0;i<_funcTable.size();i++){
00091 if(strcmp(_funcTable[i]->funcName,funcName)==0){
00092 return _funcTable[i]->funcNo;
00093 }
00094 }
00095 funcData *funcElem = new funcData;
00096 funcElem->funcNo = _funcTable.size();
00097 funcElem->funcName = funcName;
00098 _funcTable.push_back(funcElem);
00099 return funcElem->funcNo;
00100 }
00101
00102 extern "C" void ampi_beginFunc(int funcNo,MPI_Comm comm){
00103 ampi *ptr = getAmpiInstance(comm);
00104 int myindex = ptr->thisIndex;
00105 int foundFlag=0;
00106 vprocData *procElem;
00107 if(vprocTable.size() <= myindex){
00108 procElem = new vprocData;
00109 procElem->index = myindex;
00110 procElem->funcList.push_back(funcNo);
00111 vprocTable.insert(myindex,procElem);
00112 }else{
00113 vprocTable[myindex]->funcList.push_back(funcNo);
00114 }
00115 int iData[2];
00116 iData[0] = myindex;
00117 iData[1] = funcNo;
00118 LogEvent3(_AMPI_LANG_ID,_E_AMPI_BEGIN_FUNC,2,iData,strlen(_funcTable[funcNo]->funcName)+1,_funcTable[funcNo]->funcName);
00119 }
00120
00121
00122 extern "C" void ampi_endFunc(int funcNo,MPI_Comm comm){
00123 ampi *ptr = getAmpiInstance(comm);
00124 int myindex = ptr->thisIndex;
00125 if(vprocTable.size() <= myindex){
00126 }else{
00127 int size = vprocTable[myindex]->funcList.size();
00128 if(size > 0){
00129 vprocTable[myindex]->funcList.remove(size-1);
00130 }
00131 int iData[2];
00132 iData[0] = myindex;
00133 iData[1] = funcNo;
00134 LogEvent1(_AMPI_LANG_ID,_E_AMPI_END_FUNC,2,iData);
00135 }
00136 }
00137
00138