-
Notifications
You must be signed in to change notification settings - Fork 12
/
operatorloops.h
110 lines (85 loc) · 2.74 KB
/
operatorloops.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
Developed by Sandeep Sharma and Garnet K.-L. Chan, 2012
Copyright (c) 2012, Garnet K.-L. Chan
This program is integrated in Molpro with the permission of
Sandeep Sharma and Garnet K.-L. Chan
*/
#ifndef SPIN_OPERATOR_LOOPS_HEADER_H
#define SPIN_OPERATOR_LOOPS_HEADER_H
#include <vector>
#include <iostream>
#include <communicate.h>
#ifdef _OPENMP
#include <omp.h>
#endif
#include <boost/shared_ptr.hpp>
#include "pario.h"
#include "StackBaseOperator.h"
/**
* Distributed loops to be used functors on OperatorArrays
*
*/
/**
* Loop over all local (i.e. stored on current processor) in array
*
*/
namespace SpinAdapted{
class StackSpinBlock;
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
//execute a function on all elements of an array
//single thread and multithread versions of the code
template<typename T2, class A> void for_all_singlethread_hmult(A& array, const T2& func)
{
int i;
{
for (i = 0; i < array.get_size(); ++i) {
for (int j=0; j<array.get_local_element(i).size(); j++)
func(array.get_local_element(i)[j]);
}
}
}
//execute a function on all elements of an array
//single thread and multithread versions of the code
template<typename T2, class A> void for_all_singlethread(A& array, const T2& func)
{
int i;
{
for (i = 0; i < array.get_size(); ++i) {
func(array.get_local_element(i));
}
}
}
template<typename T2, class A> void for_all_operators_singlethread(A& array, const T2& func)
{
int i;
for (i = 0; i < array.get_size(); ++i) {
int vecsize = array.get_local_element(i).size();
for (int j=0; j<vecsize; j++){
func(*(array.get_local_element(i)[j]));
}
}
}
template<class A> void singlethread_build(A& array, StackSpinBlock& b, std::vector< Csf >& s, vector< vector<Csf> >& ladders)
{
for (int i = 0; i < array.get_size(); ++i) {
//typedef typename A::OpType Op;
int vecsize = array.get_local_element(i).size();
for (int j=0; j<vecsize; j++) {
array.get_local_element(i)[j]->buildUsingCsf(b, ladders, s);
}
}
}
template<class A> void singlethread_build(A& array, StackSpinBlock& b)
{
for (int i = 0; i < array.get_size(); ++i) {
//typedef typename A::OpType Op;
//std::vector<boost::shared_ptr<Op> >& vec = array.get_local_element(i);
int vecsize = array.get_local_element(i).size();
for (int j=0; j<vecsize; j++) {
array.get_local_element(i)[j]->build(b);
//pout << *vec[j]<<endl;
}
}
}
}
#endif