Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F78466289
utility.h
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Aug 21, 01:43
Size
1 KB
Mime Type
text/x-c
Expires
Fri, Aug 23, 01:43 (2 d)
Engine
blob
Format
Raw Data
Handle
20050466
Attached To
R10834 Project_multiproc
utility.h
View Options
/*
============================================================================
Filename : utility.h
Author : Arash Pourhabibi, Hussein Kassir
============================================================================
*/
#ifndef UTILITYH
#define UTILITYH
#include <time.h>
#include <sys/time.h>
#include <string.h>
#define INIT_VALUE 1000
#define x(i,j) x[(i)*length+(j)]
struct timeval start, end;
void set_clock()
{
gettimeofday(&start, NULL);
}
double elapsed_time()
{
gettimeofday(&end, NULL);
double elapsed = (end.tv_sec - start.tv_sec);
elapsed += (double)(end.tv_usec - start.tv_usec) / 1000000.0;
return elapsed;
}
//Initialize the two-dimensional array
void init(double *x, int length)
{
memset(x, 0, sizeof(double)*length*length);
x(length/2-1,length/2-1) = INIT_VALUE;
x(length/2-1,length/2) = INIT_VALUE;
x(length/2,length/2-1) = INIT_VALUE;
x(length/2,length/2) = INIT_VALUE;
}
//Save the two-dimensional array in a csv file
void save(double *x, int length, const char *outputfilename)
{
FILE *output_file;
output_file = fopen(outputfilename,"w");
for(int i=0; i<length; i++)
{
for(int j=0; j<length-1; j++)
fprintf(output_file, "%.4g;", x(i,j));
fprintf(output_file, "%.4g", x(i,length-1));
fprintf(output_file, "\n");
}
fclose(output_file);
}
#endif
Event Timeline
Log In to Comment