Here is the code:

#include <stdio.h>
#include <xmmintrin.h>
#include <windows.h> typedef __m128 Vec; typedef unsigned long long value_t; __forceinline value_t now()
{
LARGE_INTEGER n;
QueryPerformanceCounter(&n);
return n.QuadPart;
} inline void img_transpose(
Vec *dst_img,
Vec *src_img,
const int src_w,
const int src_h)
{
#pragma omp parallel for
for (int j = ; j < src_w; ++j)
{
for (int i = ; i < src_h; ++i)
{
dst_img[j * src_h + i] = src_img[i * src_w + j];
}
}
} inline void img_transpose_block(
Vec *dst_img,
Vec *src_img,
const int src_w,
const int src_h)
{
#pragma omp parallel for
for (int j = ; j < src_w; j += )
{
for (int i = ; i < src_h; i += )
{
const int nsize = min(j + , src_w);
const int msize = min(i + , src_h); for (int n = j; n < nsize; ++n)
{
for (int m = i; m < msize; ++m)
{
dst_img[n * src_h + m] = src_img[m * src_w + n];
}
}
}
}
} int main(int argc, char *argv[])
{
//// performance benchmark //// const int w = ;
const int h = ;
Vec *a = new Vec [w * h];
Vec *b = new Vec [w * h];
value_t start_time, end_time; LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
double ms_per_tick = 1000.0 / (double)freq.QuadPart; start_time = now(); for (int t = ; t < ; ++t)
{
img_transpose(b, a, w, h);
img_transpose(a, b, h, w);
} end_time = now();
printf("img_transpose: %f ms\n", (double)(end_time - start_time) * ms_per_tick); start_time = now(); for (int t = ; t < ; ++t)
{
img_transpose_block(b, a, w, h);
img_transpose_block(a, b, h, w);
} end_time = now();
printf("img_transpose_block: %f ms\n", (double)(end_time - start_time) * ms_per_tick); delete [] a;
delete [] b; //// algorithm validation ////
const int width = ;
const int height = ;
Vec *src_img = new Vec [width * height];
Vec *dst_img = new Vec [height * width]; for (int j = ; j < height; ++j)
{
for (int i = ; i < width; ++i)
{
src_img[j * width + i].m128_i32[] = i;
src_img[j * width + i].m128_i32[] = j;
}
} img_transpose_block(dst_img, src_img, width, height); for (int j = ; j < width; ++j)
{
for (int i = ; i < height; ++i)
{
int pi = dst_img[j * height + i].m128_i32[];
int pj = dst_img[j * height + i].m128_i32[]; if (pi != j || pj != i)
{
printf("Algorithm is wrong!!!\n");
goto END_OF_PROGRAM;
}
}
} END_OF_PROGRAM:
printf("All done\n"); return ;
}

A tiny program to benchmark image transpose algorithms的更多相关文章

  1. hey is a tiny program that sends some load to a web application.

    hey is a tiny program that sends some load to a web application. DOS attack DOS攻击生成 https://github.c ...

  2. 自己动手写一个编译器Tiny语言解析器实现

    然后,上一篇文章简介Tiny词法分析,实现语言.本文将介绍Tiny的语法分析器的实现. 1 Tiny语言的语法 下图是Tiny在BNF中的文法. 文法的定义能够看出.INNY语言有以下特点: 1 程序 ...

  3. Reading List on Automated Program Repair

    Some resources: https://www.monperrus.net/martin/automatic-software-repair 2017 [ ] DeepFix: Fixing ...

  4. [io benchmark]常用磁盘基准/压力测试工具

    Unix Disk I/O Benchmarks fio - NEW! fio is an I/O tool meant to be used both for benchmark and stres ...

  5. UVA - 10895 Matrix Transpose

    UVA - 10895 Matrix Transpose Time Limit:3000MS   Memory Limit:Unknown   64bit IO Format:%lld & % ...

  6. Awesome Go

    A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...

  7. Go 语言相关的优秀框架,库及软件列表

    If you see a package or project here that is no longer maintained or is not a good fit, please submi ...

  8. Awesome Go (http://awesome-go.com/)

    A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...

  9. Awesome Go精选的Go框架,库和软件的精选清单.A curated list of awesome Go frameworks, libraries and software

    Awesome Go      financial support to Awesome Go A curated list of awesome Go frameworks, libraries a ...

随机推荐

  1. Linux 下 FastDFS v5.08 分布式文件系统的安装

    一.系统安装目录 源代码包目录 /data/wwwroot libevent安装目录 /usr/local/libevent FastDFS安装目录 /data/fastdfs nginx安装目录 / ...

  2. jquery 处理重新绑定插件的方法

    比如有一个slide的jquery插件,页面打开就对dom进行了绑定. <div class="expert"> <div class="expert- ...

  3. golang协程进行同步方法

    1.使用chanel func main() { done := make(chan bool) ticker := time.NewTicker(time.Millisecond * 1000) g ...

  4. Linux升级Ruby

    一.简介 Ruby 是一种开源的面向对象程序设计的服务器端脚本语言,在 20 世纪 90 年代中期由日本的松本行弘(まつもとゆきひろ/Yukihiro Matsumoto)设计并开发.在 Ruby 社 ...

  5. [SoapUI] Tips and Tricks(提示和技巧)

    https://www.soapui.org/scripting-properties/tips-tricks.html

  6. 多线程的使用:只能用cmd来玩不能用idle

    from multiprocessing import Process import os def pro_do(name, func): print () if __name__ == " ...

  7. dbutils封装对象,单列,一行一列(用)

    基本用法:查找并封装对象与对象集合 public User findUserByNamePassword(String name,String password){ QueryRunner runne ...

  8. 2018.09.09 bzoj4403: 序列统计(Lucas定理)

    传送门 感觉单调不降序列什么的不好做啊. 于是我们序列中下标为i的元素的值加上i,这样就构成了一个单调递增的序列. 问题就变成了: 求出构造长度分别为1 ~ n且每个元素的值在l+1 ~ r+n之间的 ...

  9. java常用设计模式一:单例模式

     1.饿汉式 package singleton.demo; /** * @author Administrator * @date 2019/01/07 */ public class Single ...

  10. java socket 之UDP编程

    一.概念 在TCP的所有操作中都必须建立可靠的连接,这样一来肯定会浪费大量的系统性能,为了减少这种开销,在网络中又提供了另外的一种传输协议——UDP,不可靠的连接(这种协议在各种聊天工具中被广泛使用) ...