Commit ab48487c authored by Yliès's avatar Yliès
Browse files

added C/team 2's files

parent 78d5b5ed
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
-include ../makefile.init
RM := rm -rf
# All of the sources participating in the build are defined here
-include sources.mk
-include src/subdir.mk
-include subdir.mk
-include objects.mk
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C++_DEPS)),)
-include $(C++_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
ifneq ($(strip $(CC_DEPS)),)
-include $(CC_DEPS)
endif
ifneq ($(strip $(CPP_DEPS)),)
-include $(CPP_DEPS)
endif
ifneq ($(strip $(CXX_DEPS)),)
-include $(CXX_DEPS)
endif
ifneq ($(strip $(C_UPPER_DEPS)),)
-include $(C_UPPER_DEPS)
endif
endif
-include ../makefile.defs
# Add inputs and outputs from these tool invocations to the build variables
# All Target
all: CaseStudy2
# Tool invocations
CaseStudy2: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C++ Linker'
g++ -o "CaseStudy2" $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
# Other Targets
clean:
-$(RM) $(OBJS)$(C++_DEPS)$(C_DEPS)$(CC_DEPS)$(CPP_DEPS)$(EXECUTABLES)$(CXX_DEPS)$(C_UPPER_DEPS) CaseStudy2
-@echo ' '
.PHONY: all clean dependents
.SECONDARY:
-include ../makefile.targets
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
USER_OBJS :=
LIBS := -lrt -lpthread -lgomp
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
O_SRCS :=
CPP_SRCS :=
C_UPPER_SRCS :=
C_SRCS :=
S_UPPER_SRCS :=
OBJ_SRCS :=
ASM_SRCS :=
CXX_SRCS :=
C++_SRCS :=
CC_SRCS :=
OBJS :=
C++_DEPS :=
C_DEPS :=
CC_DEPS :=
CPP_DEPS :=
EXECUTABLES :=
CXX_DEPS :=
C_UPPER_DEPS :=
# Every subdirectory with source files must be described here
SUBDIRS := \
src \
src/CaseStudy2.d: ../src/CaseStudy2.cpp ../src/MonLib.h
../src/MonLib.h:
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
../src/CaseStudy2.cpp
OBJS += \
./src/CaseStudy2.o
CPP_DEPS += \
./src/CaseStudy2.d
# Each subdirectory must supply rules for building sources it contributes
src/%.o: ../src/%.cpp
@echo 'Building file: $<'
@echo 'Invoking: GCC C++ Compiler'
g++ -O0 -g3 -Wall -c -fmessage-length=0 -fopenmp -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
/**
* Copyright 1993-2012 NVIDIA Corporation. All rights reserved.
*
* Please refer to the NVIDIA end user license agreement (EULA) associated
* with this source code for terms and conditions that govern your use of
* this software. Any use, reproduction, disclosure, or distribution of
* this software and related documentation outside the terms of the EULA
* is strictly prohibited.
*/
#include <stdio.h>
#include <stdlib.h>
#include "MonLib.h"
#include <fstream>
#include <sstream>
#include <cstring>
#include <sstream>
#include <functional>
#include <mcstl.h>
#include <pthread.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <string.h>
//static const int WORK_SIZE = 256;
using namespace std;
/**
* This macro checks return value of the CUDA runtime call and exits
* the application if the call failed.
*/
/**
* Host function that prepares data array and passes it to the CUDA kernel.
*/
struct program_trace
{
long objectid;
int sequence;
long transfer_size;
};
int get_next_state1(const program_trace& trace_event, int curr_state = 0)
{
switch(curr_state)
{
case 0: if(trace_event.transfer_size > 999999)
return 1;
else
return 0;
case 1:
return 1;
}
return 1;
}
int get_next_state2(const program_trace& trace_event, int curr_state = 0)
{
switch(curr_state)
{
case 0: if(trace_event.transfer_size > 10000)
return 1;
else
return 0;
case 1: if(trace_event.transfer_size <= 10000)
return 0;
else
return 1;
}
return 1;
}
bool is_equal (const program_trace& T1, const program_trace&T2 )
{
if(T1.objectid != T2.objectid)
return false;
return true;
}
bool operator < (const program_trace &T1, const program_trace &T2 )
{
if(T1.objectid < T2.objectid)
return true;
else
if(T1.sequence < T2.sequence && T1.objectid == T2.objectid)
return true;
return false;
}
ostream& operator << (ostream &os, const program_trace &T1 )
{
os<<T1.objectid<<":"<<T1.transfer_size<<endl;
return os;
}
class CommandLineParse
{
int argc;
char **argv;
public:
CommandLineParse(int argc, char *argv[]):argc(argc),argv(argv)
{
}
char* parse_comamand_line(char *option, int exist = 1)
{
long i = 0;
for(i = 1; i <argc; i++)
if(strcmp(argv[i],option) == 0)
if(!exist)
return argv[i+1];
else
return argv[i];
return 0;
}
};
class LineParser
{
char *line;
public:
LineParser(){
line = 0;
}
void setline(char *line)
{
this->line = line;
}
string get_field(int count)
{
string line_str(line), word;
stringstream ss;
ss<<line;
for(int i = 0; i < count; i++)
{
ss>>word;
}
ss>>word;
return word;
}
};
long MAX = 32768;
int TRACE_SIZE = 2, THRESHHOLD;
long event_count = 0;
long *trace_count;
int replicates;
MonlibOpenMP<program_trace> *mon;
int ON_CPU;
struct rusage selfstats;
struct rusage selfstats1, selfstats2;
void* run_mon(void *n)
{
double cputime2;
int replica = *((uint32_t *)n);
getrusage(RUSAGE_SELF,&selfstats1);
long long total_time = mon-> invoke_monitor(ON_CPU);
getrusage(RUSAGE_SELF,&selfstats2);
cputime2 = selfstats2.ru_utime.tv_sec - selfstats1.ru_utime.tv_sec;
cputime2 += selfstats2.ru_stime.tv_sec - selfstats1.ru_stime.tv_sec;
cputime2 += (selfstats2.ru_utime.tv_usec - selfstats1.ru_utime.tv_usec)* 0.000001;
cputime2 += (selfstats2.ru_stime.tv_usec - selfstats1.ru_stime.tv_usec)* 0.000001;
cout<<replica<<",\t"<<total_time<<",\t"<<(float)cputime2<<",\t"<<(ON_CPU == 1? "CPU":"OPENMP")<<",\t"<<MAX*TRACE_SIZE<<"\n";
return NULL;
}
int main(int argc, char *argv[])
{
char *filename;
char line[1024];
pthread_t other;
CommandLineParse P(argc, argv);
LineParser L;
if(P.parse_comamand_line("-c"))
ON_CPU = CPU;
if(P.parse_comamand_line("-o"))
ON_CPU = OPENMP;
if(P.parse_comamand_line("-f",0))
{
filename = P.parse_comamand_line("-f",0);
}
else
{
cout<<"No trace file Option -f Provided\n";
exit(-1);
}
if(P.parse_comamand_line("-l",0))
{
MAX = atol(P.parse_comamand_line("-l",0));
THRESHHOLD = MAX*TRACE_SIZE*9/10;
}
else
{
cout<<"No trace length Option -l Provided\n";
exit(-1);
}
replicates = 1;
if(P.parse_comamand_line("-r",0))
{
replicates= atoi(P.parse_comamand_line("-r",0));
}
trace_count = (long*)malloc(sizeof(long)*MAX);
memset(trace_count,0,sizeof(long)*MAX);
program_trace *trace;
ifstream trace_reader;
long event_count = 0;
int state_count[NO_OF_PROPS] = {1,1};
int (*mons[NO_OF_PROPS])(const program_trace&,int);
mons[0]=&get_next_state1;
mons[1]=&get_next_state2;
for(int i = 0 ; i < replicates; i++)
{
trace = (program_trace*)malloc(sizeof(program_trace)*MAX*TRACE_SIZE);
mon = new MonlibOpenMP<program_trace>(trace,TRACE_SIZE*MAX, MAX,state_count,mons);
trace_reader.open(filename,fstream::in);
while(trace_reader.getline(line,sizeof(line)))
{
L.setline(line);
string ip = L.get_field(0);
string chunk_size = L.get_field(6);
short ip_part_4 = (short)atoi(ip.substr(ip.find_last_of(".")+1).c_str());
unsigned third_dot = ip.substr(0,ip.find_last_of(".")-1).find_last_of(".");
short ip_part_3 = (short)atoi(ip.substr(third_dot+1,ip.find_last_of(".")-1).c_str());
long index = ip_part_3 + ((ip_part_4 + ip_part_3)*(ip_part_4 + ip_part_3+1))/2;
long trace_count_index = index % (MAX);
trace[event_count].objectid = index;
trace[event_count].sequence = trace_count[trace_count_index]++;
trace[event_count++].transfer_size = atof(chunk_size.c_str());
if(event_count >= THRESHHOLD )
{
pthread_create(&other, NULL, &run_mon,(void*) &i);
pthread_join(other, NULL);
event_count= 0;
break;
}
}
if(event_count != 0 )
{
pthread_create(&other, NULL, &run_mon,(void*) &i);
pthread_join(other, NULL);
event_count= 0;
}
trace_reader.close();
free(trace);
free(trace_count);
delete mon;
sleep(1);
}
return 0;
}
/*
* MonLib.h
*
* Created on: 2014-04-19
* Author: y2joshi
*/
#ifndef MONLIB_H_
#define MONLIB_H_
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <parallel/algorithm>
#include <vector>
#include <time.h>
#define NO_OF_PROPS 2
struct timespec diff_timespec(struct timespec start, struct timespec end)
{
struct timespec result;
if (end.tv_nsec < start.tv_nsec){
result.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec;
result.tv_sec = end.tv_sec - 1 - start.tv_sec;
}
else{
result.tv_nsec = end.tv_nsec - start.tv_nsec;
result.tv_sec = end.tv_sec - start.tv_sec;
}
return result;
}
long long millisec_elapsed(struct timespec diff){
return ((long long)diff.tv_sec * 1000) + (diff.tv_nsec / 1000000);
}
long long microsec_elapsed(struct timespec diff){
return ((long long)diff.tv_sec * 1000000) + (diff.tv_nsec / 1000);
}
long long nanosec_elapsed(struct timespec diff){
return ((long long)diff.tv_sec * 1000000000) + diff.tv_nsec;
}
enum platform
{
CPU=1,
GPU,
OPENMP
};
template<typename T1>
class MonlibOpenMP
{
T1 *trace_h;
int (*mons[NO_OF_PROPS])(const T1&,int);
long event_count;
long mon_count;
int *Result_States;
int state_count[NO_OF_PROPS];
public:
MonlibOpenMP(T1* trace_h,
long event_count,
long mon_count,
int *state_count,
int (*mons[])(const T1&,int)):
trace_h(trace_h), event_count(event_count),
mon_count(mon_count)
{
Result_States =(int*)malloc(sizeof(int)*event_count*NO_OF_PROPS);
for(int i =0 ; i < NO_OF_PROPS;i++)
{
this->state_count[i] = state_count[i];
this->mons[i] = mons[i];
}
}
long long invoke_monitor(int platform)
{
struct timespec start, end, diff;
clock_gettime(CLOCK_REALTIME,&start);
long start_index = 0;
int next_state1;
int next_state2;
long sum1 = 0;
long sum2 = 0;
long total_mons = 0;
if(platform == CPU)
std::sort(trace_h, trace_h + event_count);
if(platform == OPENMP)
__gnu_parallel::sort(trace_h, trace_h + event_count);
for(long i =0 ; i < event_count; i++)
{
if(i != 0)
{
if(!is_equal(trace_h[i],trace_h[i-1]))
{
Result_States[start_index] = next_state1;
Result_States[start_index + event_count] = next_state2;
if(next_state1 == state_count[0])
sum1++;
if(next_state2 == state_count[1])
sum2++;
next_state1 = (*mons[0])(trace_h[i],0);
next_state2 = (*mons[1])(trace_h[i],0);
start_index++;
total_mons++;
}
next_state1 = (*mons[0])(trace_h[i], next_state1);
next_state2 = (*mons[1])(trace_h[i], next_state2);
}
else
{
next_state1 = (*mons[0])(trace_h[i],0);
next_state2 = (*mons[1])(trace_h[i],0);
}
}
clock_gettime(CLOCK_REALTIME,&end);
diff = diff_timespec(start,end);
return millisec_elapsed(diff);
}
~MonlibOpenMP()
{
free(Result_States);
}
};
#endif /* MONLIB_H_ */
The program simulates a trace of summary report of connections of Dropbox using real dataset - http://www.simpleweb.org/wiki/Dropbox_Traces
Property 1 - For all Connections, [] (Connection.Chunksize <= 999999)
./CaseStudy2 -f home1_dropbox.log -o -l 131072 -r 1 //OPENMP
./CaseStudy2 -f home1_dropbox.log -c -l 131072 -r 1 //CPU
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
-include ../makefile.init
RM := rm -rf
# All of the sources participating in the build are defined here
-include sources.mk
-include src/subdir.mk
-include subdir.mk
-include objects.mk
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C++_DEPS)),)
-include $(C++_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
ifneq ($(strip $(CC_DEPS)),)
-include $(CC_DEPS)
endif
ifneq ($(strip $(CPP_DEPS)),)
-include $(CPP_DEPS)
endif
ifneq ($(strip $(CXX_DEPS)),)
-include $(CXX_DEPS)
endif
ifneq ($(strip $(C_UPPER_DEPS)),)
-include $(C_UPPER_DEPS)
endif
endif
-include ../makefile.defs
# Add inputs and outputs from these tool invocations to the build variables
# All Target
all: CaseStudy2
# Tool invocations
CaseStudy2: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C++ Linker'
g++ -o "CaseStudy2" $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
# Other Targets
clean:
-$(RM)