Skip to content

Instantly share code, notes, and snippets.

@legokichi
Last active August 29, 2015 14:03
Show Gist options
  • Save legokichi/b6996cb9fde6181b1d0e to your computer and use it in GitHub Desktop.
Save legokichi/b6996cb9fde6181b1d0e to your computer and use it in GitHub Desktop.
台形積分
$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 44
model name : Intel(R) Xeon(R) CPU L5630 @ 2.13GHz
stepping : 2
cpu MHz : 426.069
cache size : 12288 KB
fpu : yes
fpu_exception : yes
cpuid level : 11
wp : yes
flags : fpu de tsc msr pae cx8 sep cmov pat clflush mmx fxsr sse sse2 ss ht syscall nx lm rep_good aperfmperf unfair_spinlock pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 popcnt aes hypervisor lahf_lm ida arat dts
bogomips : 4266.94
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 44
model name : Intel(R) Xeon(R) CPU L5630 @ 2.13GHz
stepping : 2
cpu MHz : 426.069
cache size : 12288 KB
fpu : yes
fpu_exception : yes
cpuid level : 11
wp : yes
flags : fpu de tsc msr pae cx8 sep cmov pat clflush mmx fxsr sse sse2 ss ht syscall nx lm rep_good aperfmperf unfair_spinlock pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 popcnt aes hypervisor lahf_lm ida arat dts
bogomips : 4266.94
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management:
$ cat /proc/meminfo
MemTotal: 1048576 kB
MemFree: 100672 kB
Cached: 843496 kB
Active: 184796 kB
Inactive: 722624 kB
Active(anon): 11688 kB
Inactive(anon): 52236 kB
Active(file): 173108 kB
Inactive(file): 670388 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 1048576 kB
SwapFree: 456844 kB
Dirty: 0 kB
Writeback: 0 kB
AnonPages: 63924 kB
Shmem: 2568 kB
Slab: 40468 kB
SReclaimable: 29108 kB
SUnreclaim: 11360 kB
$ gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ cat log.log
/usr/gridware/sge/default/spool/app01/active_jobs/3119.1/pe_hostfile app01
/usr/gridware/sge/default/spool/app01/active_jobs/3120.1/pe_hostfile app01 /usr/local/pvm3
/var/tmp/aaaNma4HJ
start_pvm: enrolled to local pvmd
start_pvm: got 5 hosts
Warning: no access to tty; thus no job control in this shell...
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
=================================================
Please Select Kanji Code
=================================================
1. Shift-JIS
2. EUC
3. UTF-8(default)
4. None
Please enter No. =>
a: 0.000000
b: 3.141593
result: 2.000000
result: 0.076120
0.470000[sec]
ログアウト
/usr/gridware/sge/default/spool/app01/active_jobs/3120.1/pe_hostfile app01
$ cat job.sh
#!/bin/sh
#$ -M [email protected]
#$ -m be
#$ -o log.log
#$ -cwd
/usr/local/mpi/bin/mpirun -np $NSLOTS mpi
# 1.1 OpenMP
change parallel
# 1.2 MPI
change parallel
# 2 GridEngine
table n-time-result
program list
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "mpi.h"
#define DIVIDE 10000000
int main(int argc, char **argv){
clock_t start, stop;
double a, b;
double allsum = 0;
int size, rank;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if(rank == 0){
printf("a: ");printf("%f\n", a=0);
printf("b: ");printf("%f\n", b=M_PI);
}
start = clock();
double begin = (b-a)/size*rank+a;
double end = (b-a)/size*(rank+1)+a;
double step = (b-a)/DIVIDE;
double sum = 0;
for(double i=begin; i<=end; i+=step){
double a = sin(i);
double b = sin(i+step);
double h = step;
double S = (a+b)*h/2;
sum += S;
}
MPI_Reduce(&sum, &allsum, 1, MPI_DOUBLE_PRECISION, MPI_SUM, 0, MPI_COMM_WORLD);
MPI_Finalize();
if(rank == 0){
stop = clock();
printf("result: %f\n", allsum);
printf("%f[sec]\n", (double)(stop - start)/CLOCKS_PER_SEC);
}
return 0;
/*
$ mpicc -lm -o mpi mpi.c
$ mpirun -np 4 mpi
a: 0.000000
b: 3.141593
result: 2.000000
0.340000[sec]
*/
#include <stdio.h>
#include <stdlib.h>
#define M_PI 3.14159265358979323846264338327
#define _USE_MATH_DEFINES
#include <math.h>
#include <time.h>
#define DIVIDE 10000000
int main(int argc, char **argv){
clock_t start, end;
double a, b;
printf("a: ");printf("%f\n", a=0);
//scanf("%lf", &a);
printf("b: ");printf("%f\n", b=M_PI);
//scanf("%lf", &b);
start = clock();
double step = (b-a)/DIVIDE;
double sum = 0;
for(long i=0; i<=DIVIDE-1; i++){
double a = sin(step*i);
double b = sin(step*(i+1));
double h = step;
double S = (a+b)*h/2;
sum += S;
}
end = clock();
printf("result: %f\n", sum);
printf("%f[sec]\n", (double)(end - start)/CLOCKS_PER_SEC);
return 0;
}
/*
./native [/home/legokichi]
a: 0.000000
b: 3.141593
result: 2.000000
0.480000[sec]
*/
#include <stdio.h>
#include <stdlib.h>
#define M_PI 3.14159265358979323846264338327
#define _USE_MATH_DEFINES
#include <math.h>
#include <time.h>
#define DIVIDE 10000000
int main(int argc, char **argv){
clock_t start, end;
double a, b;
printf("a: ");printf("%f\n", a=0);
//scanf("%lf", &a);
printf("b: ");printf("%f\n", b=M_PI);
//scanf("%lf", &b);
start = clock();
double step = (b-a)/DIVIDE;
double sum = 0;
#pragma omp parallel for reduction(+:sum)
for(long i=0; i<=DIVIDE-1; i++){
double a = sin(step*i);
double b = sin(step*(i+1));
double h = step;
double S = (a+b)*h/2;
sum += S;
}
end = clock();
#ifdef _OPENMP
printf("use oepnmp\n");
#endif
printf("result: %f\n", sum);
printf("%f[sec]\n", (double)(end - start)/CLOCKS_PER_SEC);
return 0;
}
/*
$ export OMP_NUM_THREADS=16
$ gcc -std=c99 -lm -fopenmp -O3 openmp.c -o openmp
$ ./openmp
a: 0.000000
b: 3.141593
use oepnmp
result: 2.000000
0.420000[sec]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment